读取 ASP.NET MVC 项目的当前文化并在 javascript 中更改语言确认
我有一个 JavaScript 确认。我的文本是英文的,但如果我要更改我的 ASP.NET MVC 项目的语言/文化,确认仍然是英文。
我可以手动控制它,只需编写两个 javascript 方法(针对两种语言),但我认为它并不那么干净。如果我有超过 3 种语言,那就更脏了。
您能给我一些如何解决我的问题的提示吗?
对我来说最好的方法是确认一些元标记或其他东西,我可以在哪里从资源文件中给出我的文本。
I have a javascript confirm. My text is in english, but if I will change language/culture of my asp.net mvc project confirm is of cource still english.
I can controll it manually and just write two javascript methods (for both Languages) but it is no so clean I think. And if I will have more than 3 languages its will be more dirty.
Could you give me some Tip how can i solve my problem?
Best for me is to have confirm with some metatag or something where can i give my text from resource files out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以仅使用字符串制作单独的js文件,例如:
并且比使用设置的语言信息动态生成js文件:
您还可以通过不同的方式获取此信息(例如AJAX),但上面的解决方案有一个优点,即您的代码是已加载并设置了
currentLanguage
。然后在你的代码中输入:
你可能想将所有内容包装到 1 个全局变量中,这样会更简洁。
另请记住不要覆盖方法
MultilanguageStrings.get
。You can do seperate js file with strings only, e.g.:
And than make dynamically generated js file with information which language is set:
You can also get this information by different way (e.g. AJAX) but solution above has this advantage, that your code is already loaded and
currentLanguage
is set.Then in your code put:
You may want to wrap everything into 1 global variable, that would be more neat.
Also remember not to overwrite method
MultilanguageStrings.get
.