new I18N(lang, datanullable, appTagnullable, local)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
lang |
string | Two-character ISO639 language code of the destination language, or a language_region locale code (e.g. "en_US"), or a custom value for special languages (eg 'lolcat', or 'user-defined') | |
data |
string |
<nullable> |
Contents of translation csv file for `lang`, OR a url to load a translation csv file. OR an app-tag (obtained from the i18njs portal; begins with a #) to load from the i18njs portal (if you have an account). Loading is done synchronously (it will block), using jQuery. |
appTag |
string |
<nullable> |
Tag to report translation misses to the i18njs portal (if you have an account). If an appTag is provided for the data parameter (see above), then there is no need to repeat it here. appTags must begin with a # |
local |
boolean | Use the local server for this I18N rather than i18n.soda.sh. Defaults to using i18n.soda.sh if absent. |
Members
(static) KEEPME
numbers, emails, html tags -- keep them untranslated
Methods
(static) getBrowserLanguage()
Try to guess the user's language from the browser.
Returns:
language code (which could be incorrect), or null
(static) tr()
Convenient static access to a global I18N
_loadFile(data)
Do a synchronous load of a csv file
Parameters:
Name | Type | Description |
---|---|---|
data |
string | The url |
_uncanon2_convert(v)
Parameters:
Name | Type | Description |
---|---|---|
v |
string |
Returns:
formatted version of v, e.g. numbers are run through numberFormat()
active(onnullable)
Automatically called when an I18N object is made (so the most recently made is the active one).
You can also call it explicitly to swap between objects.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
on |
boolean |
<nullable> |
Set this to be active (or not). |
Returns:
true if this is active
add(original, translation, typenullable)
Add a translation to the dictionary.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
original |
string | ||
translation |
string | ||
type |
object |
<nullable> |
Plural or gender for categorise() based advanced multiple-choice translations. |
canon(varCatcher, varOrdernullable)
Convert into a canonical form for internal lookup.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
varCatcher |
array | , which will collect the raw versions of "variables", for uncanon to put back. TODO OR the output from a previous canon(original), used to establish place-marker ordering in canon(translation). | |
varOrder |
boolean |
<nullable> |
If true, varCatcher is interpreted as the output from a previous canon(). |
Returns:
The "canonical" form -- with variable markers, standardised whitespace, etc.
canTranslate(english)
Find out if there's a translation available for this string
Parameters:
Name | Type | Description |
---|---|---|
english |
categorise(v) → {object}
Is this plural or singular? Male or female?
Parameters:
Name | Type | Description |
---|---|---|
v |
string | Variable value (probably a word or a number) to analyse; |
Returns:
- Type
- object
onfail(english, lang, key)
Called when we can't translate a phrase.
The default version is for a SoDash backend -- replace it with your own logging call!
Note: This will skip repeats, too-long texts (max:1000 characters), and it stops logging after 1000 fails.
Parameters:
Name | Type | Description |
---|---|---|
english |
string | The original text. |
lang |
string | The language we're translating to. |
key |
string | The internal lookup key, as produced by canon(). Useful if debugging corner cases. |
tr(english)
Parameters:
Name | Type | Description |
---|---|---|
english |
string | Original text (often English) |
uncanon(canon, vars)
Inverse of canon. Sort of.
Parameters:
Name | Type | Description |
---|---|---|
canon |
The output from canon | |
vars |
The varCatcher array from canon. |