@hug/ngx-g11n
Version:
Angular helpers for internationalizing and localizing your application
104 lines (95 loc) • 2.97 kB
TypeScript
import { Provider, InjectionToken } from '@angular/core';
type DefaultModuleImport = Promise<{
[key: string]: unknown;
default?: unknown;
}>;
declare enum G11nDebug {
SHOW_KEYS = 0,
DUMMY_TRANSLATIONS = 1,
NO_DEBUG = 2
}
interface G11nOptions {
/**
* The default language to use when no language is detected or provided.
* @example 'en', 'fr-CH'
* @default 'fr-CH'
*/
defaultLanguage?: string;
/**
* The default currency code used for formatting values.
* Must be a valid ISO 4217 currency code.
* @example 'USD', 'EUR', 'CHF'
* @default 'CHF'
*/
defaultCurrency?: string;
/**
* Whether to automatically detect and use the browser's language (via navigator.language).
* @default true
*/
useNavigatorLanguage?: boolean;
/**
* Whether to load Angular locale extra data (e.g. pluralization rules, date formats).
* @default false
*/
loadLocaleExtra?: boolean;
/**
* Enables or disables the translation system.
* If false, only locale-based formatting will be applied.
* @default true
*/
useTranslations?: boolean;
/**
* Root path where translation files are located.
* @default '/translations' (or '/assets/translations' for legacy apps)
*/
rootTranslationsPath?: string;
/**
* List of translation scopes to load from the root translations folder.
* Each scope typically represents a feature/module-specific translation folder.
* @example ['common', 'auth', 'dashboard']
* @default []
*/
translationScopes?: string[];
/**
* Name of the query parameter used to override the active language.
* @example '?lang=en'
* @default 'lang'
*/
queryParamName?: string;
/**
* Storage mechanism used to persist user preferences.
* Typically localStorage or sessionStorage.
* @default localStorage
*/
storage?: Storage;
/**
* Debug configuration for logging and development diagnostics.
* @default G11nDebug.NO_DEBUG
*/
debug?: G11nDebug;
}
interface G11nFeature<T = Provider> {
providers: T[];
}
interface G11nLocale {
base: () => DefaultModuleImport;
extra?: () => DefaultModuleImport;
datefns?: () => DefaultModuleImport;
translationFilename?: string;
}
/**
* @internal
*/
declare const DEFAULT_OPTIONS: G11nOptions;
declare const currentLanguage: () => string;
declare const setLanguage: (value: string) => void;
/**
* Initializes G11N providers.
* @internal
* @returns An array of Angular providers for G11N initialization.
*/
declare const init: () => Provider[];
declare const LOCALES: InjectionToken<Record<string, G11nLocale>>;
declare const G11N_OPTIONS: InjectionToken<G11nOptions>;
export { DEFAULT_OPTIONS, G11N_OPTIONS, G11nDebug, LOCALES, currentLanguage, init, setLanguage };
export type { DefaultModuleImport, G11nFeature, G11nLocale, G11nOptions };