mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Created i18n utility function
This commit is contained in:
parent
da762fbc4f
commit
76110423c0
2 changed files with 23 additions and 1 deletions
|
@ -44,4 +44,26 @@ module.exports.hslToHex = (hsl) ->
|
|||
toHex = (n) ->
|
||||
h = Math.floor(n).toString(16)
|
||||
h = '0'+h if h.length is 1
|
||||
h
|
||||
h
|
||||
|
||||
i18n = (say, target, language=me.lang(), fallback='en') ->
|
||||
generalResult = null
|
||||
fallbackResult = null
|
||||
fallforwardResult = null # If a general language isn't available, the first specific one will do
|
||||
matches = (/\w+/gi).exec(language)
|
||||
generalName = matches[0] if matches
|
||||
|
||||
for locale in say?.i18n
|
||||
if target of say[locale]
|
||||
result = say[locale][target]
|
||||
else continue
|
||||
return result if locale == language
|
||||
generalResult = result if locale == generalName
|
||||
fallbackResult = result if locale == fallback
|
||||
fallforwardResult = result if locale.indexOf language != -1 and not fallforwardResult?
|
||||
|
||||
return generalResult if generalResult?
|
||||
return fallbackResult if fallbackResult?
|
||||
return fallforwardResult if fallforwardResult?
|
||||
return say.text if 'text' of say
|
||||
null
|
0
test/app/lib/utils.spec.coffee
Normal file
0
test/app/lib/utils.spec.coffee
Normal file
Loading…
Reference in a new issue