internationalization - Angular7 internationalization vs translate module
问题描述
I've got huge doubts on how to internationalize my angular7 webapp. What I want is to understand from browser locale the user language and to display the webapp in that language. Then if the user wants to change it, he can choose the language in the combobox. Now...I've spent two days reading all the official and unofficial documentation but I can't understand which is the best way to achieve this goal. Reading the official documentation I can use the new default i18n system but I can't understand how to change the language at runtime.
Should I use translate module?
Thanks
解决方案
如果我理解,您可以使用 ngx-translate ,它将按文档中的预期工作:
this.translate.setDefaultLang('en');
虽然您可以在运行时更改语言,例如:
useLang(){
const lang = localStorage.getItem('language');
if (lang === null) {
this.translate.use('en');
console.log('Language is null! Using english');
} else {
this.translate.use(lang);
console.log(lang);
}
}
我使用 ngx-translate 在我的应用程序中没有任何问题
推荐阅读
- language-agnostic - 查找所有“配对集”,使得所有元素都有一个配对,并且没有配对包含公共元素
- c++ - 如何删除二维数组中输出的行?
- sql - 我不明白什么是聚合函数以及它如何应用于我的查询
- javascript - Javascript / Angular保留过滤数组的旧索引/使用过滤列表拖放
- android - Play 商店部署多个环境
- beautifulsoup - bs4无法得到具体结果
- git - Gitlab CI 从项目 A 推送到项目 B
- regex - 字符串必须是字母数字并包含某个子字符串
- excel - 是否可以在 Excel 中的代码中更新 Power Query 数据源数据库连接?
- reactjs - 如何使用 react-native-testing-library 使用选择组件测试表单