This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
forked from softwarerero/meteor-accounts-t9n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
t9n.coffee
57 lines (47 loc) · 1.34 KB
/
t9n.coffee
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
if Meteor.isClient
if Package.ui
Handlebars = Package.ui.Handlebars
Handlebars.registerHelper 't9n', (x) ->
T9n.get(x)
class T9n
@maps: {}
@defaultLanguage: 'en'
@language: ''
@dep: new Deps.Dependency()
@depLanguage: new Deps.Dependency()
@missingPrefix = ">"
@missingPostfix = "<"
@map: (language, map) ->
if(!@maps[language])
@maps[language] = {}
@registerMap(language, '', false, map)
@dep.changed()
@get: (label, markIfMissing = true) ->
@dep.depend()
@depLanguage.depend()
if typeof label != 'string'
return ''
@maps[@language]?[label] ||
@maps[@defaultLanguage]?[label] ||
if markIfMissing then @missingPrefix + label + @missingPostfix else label
@registerMap = (language, prefix, dot, map) ->
if typeof map == 'string'
@maps[language][prefix] = map
else if typeof map == 'object'
if dot
prefix = prefix + '.'
for key, value of map
@registerMap(language, prefix + key, true, value)
@getLanguage: () ->
@depLanguage.depend()
return @language
@getLanguages: () ->
@dep.depend()
return Object.keys(@maps).sort()
@setLanguage: (language) ->
if(!@maps[language] || @language == language)
return;
@language = language
@depLanguage.changed()
@T9n = T9n
@t9n = (x) -> T9n.get(x)