jsbeans

jsbeans  1.0.0

jsbeans > jsbeans > jsbeans.i18n
Search:
 
Filters

static Class jsbeans.i18n

Utility Object to get and (document.)write messages in any language.

Properties

BASE - static JSON

Default JSON containing messages.

LANG - static String

Default language.

Methods

get

static String get ( msgId , [replacers] )
Gets the message in the language set by setLanguage by its {@param} msdId.
More precisely looks for a static property jsbeans.i18n.<msgId>.<jsbeans.i18n.LANG> (e.g. jsbeans.i18n.title.en = "My title"). If not found returns the string "??<msgId>??" (e.g. ??title??) to give developer something to see and fix.
Messages can accept numbered placeholders (e.g. "My name is {0} and my email is {1}") or in JSON format (e.g. "My name is {name} and my email is {email}") that will be replaced with optional arguments.
Parameters:
msgId <String> the message id
[replacers] <Array | JSON | arguments} ordered values for placeholders; may be key/value pairs in case of JSON format. May be an Array (jsbeans.i18n.get('label', ['Mr', 'Jones'])) or the function arguments (jsbeans.i18n.get('label', 'Mr', 'Jones')) or JSON (jsbeans.i18n.get('label', { title: 'Mr', lastName: 'Jones'> ))
Returns: String
the formatted messages in provided language or ??<msgId>?? otherwise

has

static boolean has ( msgId )
Checks if a message with given {@param} msgId has been provided
Parameters:
msgId <String> the id of the message to be checked
Returns: boolean
true if jsbeans.i18n.BASE[msgId] has been found

put

static void put ( selector , msgId , [replacers] )
Replaces content of DOM element identified by {@param} selector with message identified by {@param} msgId.
Internally it uses jsbeans.i18n.get to get message.
Parameters:
selector <String> the id of an HTML element
msgId <String> the id of the message
[replacers] <Array | JSON | arguments> See jsbeans.i18n.get.
Returns: void

putAll

static void putAll ( json )
A shortcut for multiple jsbeans.i18n.put (without replacers).
Parameters:
json <JSON> a json in the format
nameOfSelector1: msgIdForSelector1,
nameOfSelector2: msgIdForSelector2,
...
Returns: void

setBase

static void setBase ( obj )
get uses jsbeans.i18n as base object for messages.
For example jsbeans.i18n.get("mama"); will look for the property jsbeans.i18n.mama.
Use {@method} setBase to change message container.
Note: jsbeans.i18n.setLanguage still looks for jsbeans.i18n._languages to check language availability.
Parameters:
obj <JSON> A JSON containing all messages. Default jsbeans.i18n.
Returns: void

setLanguage

static void setLanguage ( lang )
Sets/changes the default locale to the given one.
Parameters:
lang <String> the language used to get all next messages
Returns: void

setLocale

static void setLocale ( lang )
Alias for setLanguage
Parameters:
lang <String> the language used to get all next messages
Returns: void

write

static document.write write ( msgId , [replacers] )
As jsbeans.i18n.get but writes on document using document.write
Parameters:
msgId <String>
[replacers] <Array | JSON | arguments> See jsbeans.i18n.get.
Returns: document.write


Copyright © 2016 Francesco Mele. All rights reserved.