我目前正在使用 .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模板网!
读取 XML 时忽略空格Ignore whitespace while reading XML(读取 XML 时忽略空格)
使用 HTMLAgilityPack 仅提取页面文本extracting just page text using HTMLAgilityPack(使用 HTMLAgilityPack 仅提取页面文本)
C# 从 XML 中提取数据C# extracting data from XML(C# 从 XML 中提取数据)
读取 XML(从字符串)并获取一些字段 - 读取 XML 时出Read a XML (from a string) and get some fields - Problems reading XML(读取 XML(从字符串)并获取一些字段 - 读取 XML 时出现问题)
在 .net 中读取大型 XML 文档Reading large XML documents in .net(在 .net 中读取大型 XML 文档)
如何使用 .NET API 在 Google Drive 中创建文件夹?How to create folder in Google Drive using .NET API?(如何使用 .NET API 在 Google Drive 中创建文件夹?)