我有以下咖啡脚本代码,它读取文件系统并提取目录名称:
fs.readdir "./locales", (err,locales) ->
EXCLUDE = [ 'dev', 'README.md', 'config.json' ]
results = __.reject locales, (value, index, list) ->
return EXCLUDE.indexOf(value) != -1
languages = {}
locales = __.each results, (value, index, list) ->
code = value
locale = value.split("-")[0]
console.log locale
console.log code
language = cldr.extractLanguageDisplayNames(locale)[locale]
console.log language
languages.locale = language
#languages.push[{locale: language}]
console.log languages
控制台日志输出:
cs
cs-CZ
čeština
en
en-UK
English
fr
fr-FR
français
pt
pt-PT
português
sk
sk-SK
slovenčina
制作 json 文件的正确方法是什么:
{
"cs": {
"locale": "cs",
"code": "cs-CZ"
},
"en": {
"locale": "en",
"code": "en-UK"
},
"fr": {
"locale": "fr",
"code": "fr-FR"
},
"pt": {
"locale": "pt",
"code": "pt-PT"
},
"sk": {
"locale": "sk",
"code": "sk-SK"
}
}
我想languages
返回上述对象并在全局命名空间中可用,以便我可以在我的应用程序中使用它。