@osaedasia/oresume
Version:
A user-friendly library for generating complete Single Page Applications (SPAs)
92 lines (91 loc) • 3.44 kB
TypeScript
import { Observable } from "./observer/Observable";
import { ISO639_1 } from "../domain/definitions/types/Country";
import { ILanguageService } from "../domain/definitions/interfaces/ILanguageService";
/**
* Configuration interface for language service initialization.
* @template LSupported The supported ISO 639-1 language codes.
*/
interface LanguageServiceConfig<LSupported extends ISO639_1> {
/**
* The default language code to use.
*/
defaultLanguage: LSupported;
/**
* Array of supported language codes.
*/
supportedLanguages: ReadonlyArray<LSupported>;
}
/**
* Service for managing application language settings and locale preferences.
* Implements singleton pattern for global language state management.
* @template LSupported The supported ISO 639-1 language codes.
* @implements ILanguageService
*/
export declare class LanguageService<LSupported extends ISO639_1> implements ILanguageService<LSupported> {
/**
* Singleton instance of the LanguageService.
*/
private static _instance;
/** @inheritDoc */
readonly supportedLanguages: LSupported[];
/** @inheritDoc */
readonly countryCode: Observable<LSupported>;
/**
* Storage key for persisting language preferences.
*/
private readonly _storeKey;
/**
* Default country code for the service.
*/
private readonly _defaultCountryCode;
/**
* Set of supported language codes.
*/
private readonly _supportedLanguages;
/**
* Creates a new LanguageService instance.
* @param {LanguageServiceConfig<LSupported>} config Service configuration parameters.
* @throws {EmptyLanguageConfigurationError} If no supported languages are provided.
*/
private constructor();
/** @inheritDoc */
get defaultLanguage(): LSupported;
/**
* Retrieves the singleton instance of the language service.
* @param {LanguageServiceConfig<LSupported>} config Initial configuration for new instances.
* @returns {LanguageService<LSupported>} The singleton instance.
*/
static getInstance<LSupported extends ISO639_1>(config: LanguageServiceConfig<LSupported>): LanguageService<LSupported>;
/**
* Adds a single language code to supported languages.
* @param {LSupported} code The language code to add.
*/
private _addSupportedLanguage;
/**
* Adds multiple language codes to supported languages.
* @param {ReadonlyArray<LSupported>} codes Array of language codes to add.
*/
private _addSupportedLanguages;
/**
* Creates and configures an Observable instance for managing language codes.
* @returns {Observable<LSupported>} Observable instance initialized with validated browser language.
*/
private _getCodeObservable;
/**
* Extracts the country code from the browser's language settings.
* @returns {ISO639_1} The detected ISO 639-1 language code from the browser.
*/
private _detectBrowserCountryCode;
/**
* Validates a country code against supported languages list.
* @param {ISO639_1} code The country code to validate.
* @returns {LSupported} The validated code or default country code if invalid.
*/
private _assertValidCountryCode;
/**
* Updates the HTML document's lang attribute.
* @param {ISO639_1} code The language code to set.
*/
private _updateHtmlLang;
}
export {};