-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathi18n.node.txt
43 lines (36 loc) · 2.74 KB
/
i18n.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
┏━━━━━━━━━━┓
┃ I18N ┃
┗━━━━━━━━━━┛
VERSION ==> #0.5.0
CATALOG ==> # - is at DIR/PrefixLocaleExt
# - current Locale
# - OPT_OBJ.directory DIR (def: "./node_modules/i18n/locales", which is not good)
# - OPT_OBJ.prefix Prefix (def: "")
# - OPT_OBJ.extension Ext (def: ".json")
# - locales specified in OPT_OBJ.locales LOCALE_ARR are used
# - files are being written by __[n]() when there is no translation, providing
# OPT_OBJ.updateFiles is true (def)
# - can be retrieved with I18N.getCatalog([LOCALE]):
# - JSON { KEY: TRANSLATION }:
# - KEY includes raw "%CHAR" or "{{VAR}}"
# - TRANSLATION can be STR or { one|other: TRANSLATION_STR }
CURRENT LOCALE ==> # - can be global|request-wise
# - set by (least to most preference) (only works if CATALOG[LOCALE] is loaded):
# - Accept-Language [C] COUNTRY-REGION[;q=NUM]...:
# - sets LOCALE = COUNTRY with higher NUM
# - also sets REQ.languages = COUNTRY_ARR (in preference order)
# - if OPT_OBJ.cookie NAME_STR, REQ.cookies.NAME
# - I18N.overrideLocaleFromQuery(REQ): REQ.query.locale LOCALE_STR (if exists)
# - I18N|REQ.setLocale(LOCALE_STR)
# - get by I18N|REQ.getLocale():
# - if none, use OPT_OBJ.defaultLocale STR (def: "en")
I18N.configure(OPT_OBJ) #Must be called to init (before I18N.init)
I18N.init #Express MIDWR init function (e.g. initialize REQ.*)
I18N|REQ.__(STR[, VAL]) #According to I18N|REQ.getLocale()
#VAL can be:
# - STR2..., so STR can use "%CHAR" (sprintf chars), e.g. "%s" or "%d"
# - OBJ, so STR can use {{VAR}} (uses Mustache)
I18N|REQ.__n(STR, STR2, #Use either STR or STR2 according to whether NUM is plural (not 0|1).
NUM[, VAL]) #Can use "%CHAR" to put NUM. Can use "%%CHAR" to use VAL instead.
RES.locals.__|__n|getLocale|
setLocale|getCatalog #Automatically filled for templates