问题描述
我目前正在使用 .resx 文件来管理 .NET 的服务器端资源.
I'm currently using .resx files to manage my server side resources for .NET.
我正在处理的应用程序还允许开发人员将 JavaScript 插入到各种事件处理程序中以进行客户端验证等.对我来说本地化 JavaScript 消息和字符串的最佳方法是什么?
the application that I am dealing with also allows developers to plugin JavaScript into various event handlers for client side validation, etc.. What is the best way for me to localize my JavaScript messages and strings?
理想情况下,我想将字符串存储在 .resx 文件中,以便与其他本地化资源保持一致.
Ideally, I would like to store the strings in the .resx files to keep them with the rest of the localized resources.
我愿意接受建议.
推荐答案
基本的 JavaScript 对象是一个关联数组,因此可以很容易地用于存储键/值对.因此,使用 JSON,您可以为每个要本地化的字符串创建一个对象,如下所示:
A basic JavaScript object is an associative array, so it can easily be used to store key/value pairs. So using JSON, you could create an object for each string to be localized like this:
var localizedStrings={
confirmMessage:{
'en/US':'Are you sure?',
'fr/FR':'Est-ce que vous êtes certain?',
...
},
...
}
然后你可以像这样得到每个字符串的语言环境版本:
Then you could get the locale version of each string like this:
var locale='en/US';
var confirm=localizedStrings['confirmMessage'][locale];
这篇关于在 Javascript 中本地化字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)