【发布时间】:2018-07-09 19:50:04
【问题描述】:
我的项目中有以下结构:
locale
|_ nl
| |_ country.ts
|_ en
| |_ country.ts
|_ de
|_ country.ts
每个country.ts 都包含一个用于翻译的查找对象:
export default {
'AFG': 'Afghanistan',
'ALA': 'Åland',
'ALB': 'Albanië',
'DZA': 'Algerije',
目前我正在使用 NL 文件,例如:
import CountryNL from 'locale/nl/country';
let locale = CountryNL['ALB'];
但是,要使用其他语言环境,我需要动态导入模块。正如Importing modules using ES6 syntax and dynamic path 中所述,这是不可能的。
动态获取正确语言文件的最佳方法是什么?
【问题讨论】:
标签: node.js typescript