@bespunky/angular-zen
Version:
The Angular tools you always wished were there.
148 lines (147 loc) • 5.88 kB
TypeScript
import { Observable } from 'rxjs';
import { Destroyable } from '@bespunky/angular-zen/core';
import { LanguageIntegrationConfig } from '../config/language-integration-config';
import * as i0 from "@angular/core";
/**
* Uses the language integration configuration provided by an app to provide language services for a library.
* @see `LanguageIntegrationModule.forRoot()`.
*
* @export
* @class LanguageIntegrationService
* @extends {Destroyable}
*/
export declare class LanguageIntegrationService extends Destroyable {
readonly config?: LanguageIntegrationConfig | undefined;
private $ready;
private defaultLang?;
private supportedLangs?;
private currentLang?;
/**
* Creates an instance of LanguageIntegrationService.
*
* @param {LanguageIntegrationConfig} [config] The language integration configuration provided using `LanguageIntegrationModule.forRoot()`.
*/
constructor(config?: LanguageIntegrationConfig | undefined);
private initReadyObservable;
private initMultiLanguageSupport;
private loadDefaultLanguage;
private loadSupportedLanguages;
/**
* A subscribable event emitting every time the integrated app changes a language.
* The new language name is emitted with each change.
*
* This will be `undefined` if the language integration module hasn't been imported by the app.
*
* @readonly
* @type {Observable<string> | undefined}
*/
get changed(): Observable<string> | undefined;
/**
* The default language used by the integrated app.
*
* This will be `undefined` in the following cases:
* 1. The language integration module hasn't been imported by the app.
* 2. The default language hasn't resolved yet.
*
* @readonly
* @type {string | undefined}
*/
get default(): string | undefined;
/**
* The languages supported by the integrated app.
*
* This will be `undefined` in the following cases:
* 1. The language integration module hasn't been imported by the app.
* 2. Supported languages haven't resolved yet.
*
* @readonly
* @type {string[] | undefined}
*/
get supported(): string[] | undefined;
/**
* The current language used by the integrated app.
*
* This will be `undefined` in the following cases:
* 1. The language integration module hasn't been imported by the app.
* 2. The `changed` event hasn't emitted yet.
*
* @readonly
* @type {string | undefined}
*/
get current(): string | undefined;
/**
* Indicated whether the language integration module has been imported into the app.
* If this is `false`, this service will serve no purpose.
*
* @readonly
* @type {boolean}
*/
get enabled(): boolean;
/**
* A resolvable async object which emits once when the intgrated language services are ready for operation.
*
* This will complete immediately if the the language integration module hasn't been imported, or a `ready` observable hasn't
* been provided when importing the module.
*
* @readonly
* @type {Observable<void>}
*/
get ready(): Observable<void>;
/**
* Retrieves the list of alternative languages to the specified language supported by the integrated app.
*
* @param {string} lang The language for which to get the alternative languages.
* @returns {string[]} An array of alternative languages supported by the integrated app.
* @throws If the language integration module hasn't been imported into the app.
*/
alternateLanguagesFor(lang: string): string[];
/**
* Translates a value (typically a translation id) into the current language used by the integrated app.
*
* @param {string} value The value to translate (typically a translation id).
* @param {Record<string, unknown>} [params] (Optional) Any params needed for translating the value.
* @returns {string} The translation of the specified value and params in the current language used by the integrated app.
* @throws If the language integration module hasn't been imported into the app.
*/
translate(value: string, params?: Record<string, unknown>): string;
/**
* Dives deep into an object or an array and replaces the indicated properties in-place with their translation.
*
* The `paths` argument is an array of paths representing deep properties which should be translated.
* For example:
*
* ```typescript
* // If we have a user object, we can translate its city and role properties
* {
* id: 15,
* addresses: [
* { city: 'Tel Aviv', ... },
* { city: 'Rishon LeTzion' }
* ],
* system: {
* role: 'Admin'
* }
* }
*
* // Our paths would be:
* `addresses[0].city`
* `addresses[1].city`
* `system.role`
* ```
*
* @param {Record<string, unknown>} data The object which holds the translatable properties. Can be a deeply nested object.
* @param {string[]} paths The paths of the translatable properties to translate and replace.
* @throws If the language integration module hasn't been imported into the app.
*/
translateProperties(data: Record<string, unknown>, paths: string[]): void;
/**
* Ensures that the language integration module has been imported and a configuration object has been provided.
*
* @throws {Error} The language integration module hasn't been imported by the app.
*/
ensureEnabled(): this is {
config: LanguageIntegrationConfig;
};
static ɵfac: i0.ɵɵFactoryDeclaration<LanguageIntegrationService, [{ optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<LanguageIntegrationService>;
}