import RAL from './ral' ; export enum MessageFormat { file = 'file' , bundle = 'bundle' , both = 'both' } export enum BundleFormat { standalone = 'standalone' , languagePack = 'languagePack' } export interface Options { locale ? : string ; cacheLanguageResolution ? : boolean ; messageFormat ? : MessageFormat ; bundleFormat ? : BundleFormat ; } export interface LocalizeInfo { key : string ; comment : string [ ] ; } namespace LocalizeInfo { export function is ( value ) { let candidate = value as LocalizeInfo ; return candidate && isDefined ( candidate . key ) && isDefined ( candidate . comment ) ; } } export interface LocalizeFunc { ( info , message , ... args ) : string ; ( key , message , ... args ) : string ; } export interface LoadFunc { ( file ? ) : LocalizeFunc ; } export type SingleFileJsonFormat = string [ ] | { messages : string [ ] ; keys : string [ ] ; } ; export interface NlsBundle { [ key ] : string [ ] ; } export type KeyInfo = string | LocalizeInfo ; export interface MetaDataEntry { messages : string [ ] ; keys : KeyInfo [ ] ; } export interface MetadataHeader { id : string ; type : string ; hash : string ; outDir : string ; } export interface MetaDataFile { [ key ] : MetaDataEntry ; } export interface TranslationConfig { [ extension ] : string ; } export interface I18nBundle { version : string ; contents : { [ module ] : { [ messageKey ] : string ; } ; } ; } export interface LanguageBundle { header : MetadataHeader ; nlsBundle : NlsBundle ; } export function isDefined ( value ) { return typeof value !== 'undefined' ; } export let isPseudo = false ; export function setPseudo ( pseudo ) { isPseudo = pseudo ; } export function format ( message , args ) { let result ; if ( isPseudo ) { message = '\uFF3B' + message . replace ( /[aouei]/g , '$&$&' ) + '\uFF3D' ; } if ( args . length === 0 ) { result = message ; } else { result = message . replace ( /\{(\d+)\}/g , ( match , rest ) => { let index = rest [ 0 ] ; let arg = args [ index ] ; let replacement = match ; if ( typeof arg === 'string' ) { replacement = arg ; } else if ( typeof arg === 'number' || typeof arg === 'boolean' || arg === void 0 || arg === null ) { replacement = String ( arg ) ; } return replacement ; } ) ; } return result ; } export function localize ( _key , message , ... args ) { return format ( message , args ) ; } export function loadMessageBundle ( file ? ) { return RAL ( ) . loadMessageBundle ( file ) ; } export function config ( opts ? ) { return RAL ( ) . config ( opts ) ; }