LnkWcb Framework

LnkWcb  2.5.0

LnkWcb Framework > LnkWcb > LnkWcb.intl
Search:
 
Filters

Class LnkWcb.intl

Internationalization utilities

Methods

addTranslator

protected static void addTranslator ( ident , lang , translator )
Register a translator function.
Parameters:
ident <String> an identifier for the translator
lang <String> the BCP-47 language tag of the translator
translator <Function> the translator

applyTranslators

private void applyTranslators ( )
Execute translators for the current global language.

fmt

static void fmt ( str , attrs )
Expands a format string with parameters values.

For example, if {foobar} appears in the format string, then it is replaced by the value of attrs.foobar. Whenever {foobar} appears twice, only the first occurrence is expanded.

The method accepts as many attrs parameters as you like. They will apply in order, so that you can enforce priorities in the expansion process. This is very useful when enforcing cascaded substitutions. For example, fmt("oh-{foo}", { foo: "{bar}" }, { bar: "yeah!" }) will produce "oh-yeah!".

Parameters:
str <String> the format string
attrs <Object<String>> an optional object of attributes to substitute

getLang

protected static String getLang ( )
Get the current global language setting.
Returns: String
the current global language

getRsc

protected static void getRsc ( ident , lang )
Obtain a resource.
Parameters:
ident <String> an identifier for the resource
lang <String> the optional BCP-47 language tag of the resource, defaulting to the global language set

lookupBestLang

private static void lookupBestLang ( preferredLanguages , availableLanguages )
Look for the best matching BCP-47 language.

For example, with preferred languages being "fr-FR,en,de-DE" the lokup will try in order: fr-FR, fr, en, de-DE, and finally de. An empty string is returned if the match fails, i.e. if none of these values appear in available languages.

The set of preferred languages might be a string of comma separated values, or an array. Languages appearing first are preferred over those appearing last. * wildcard value is ignored.

When availableLanguages is not specified, the set of all ever languages is used. These are any languages that have some resources registered for any identifier.

Parameters:
preferredLanguages <Array|String> a set of preferred languages
availableLanguages <Array> an optional set of available languages

setLang

static void setLang ( lang )
Set the global language setting to a new value.
Parameters:
lang <String> the new global language

setRsc

protected static void setRsc ( ident , lang , rsc )
Register a resource.
Parameters:
ident <String> an identifier for the resource
lang <String> the BCP-47 language tag of the resource content
rsc <Object> the resource to register

Events

onLangChanged

protected onLangChanged ( lang )
Fires when a the global language is changed, after any translators have been applied.
Parameters:
lang <String> the new global language setting


Copyright © 2010 Linkeo.com All rights reserved.