• <tfoot id='Qt8tK'></tfoot>
  • <small id='Qt8tK'></small><noframes id='Qt8tK'>

  • <legend id='Qt8tK'><style id='Qt8tK'><dir id='Qt8tK'><q id='Qt8tK'></q></dir></style></legend>

          <bdo id='Qt8tK'></bdo><ul id='Qt8tK'></ul>
        <i id='Qt8tK'><tr id='Qt8tK'><dt id='Qt8tK'><q id='Qt8tK'><span id='Qt8tK'><b id='Qt8tK'><form id='Qt8tK'><ins id='Qt8tK'></ins><ul id='Qt8tK'></ul><sub id='Qt8tK'></sub></form><legend id='Qt8tK'></legend><bdo id='Qt8tK'><pre id='Qt8tK'><center id='Qt8tK'></center></pre></bdo></b><th id='Qt8tK'></th></span></q></dt></tr></i><div id='Qt8tK'><tfoot id='Qt8tK'></tfoot><dl id='Qt8tK'><fieldset id='Qt8tK'></fieldset></dl></div>

        本地化 javascript 消息和验证文本

        时间:2023-08-26
      1. <i id='Kw1jc'><tr id='Kw1jc'><dt id='Kw1jc'><q id='Kw1jc'><span id='Kw1jc'><b id='Kw1jc'><form id='Kw1jc'><ins id='Kw1jc'></ins><ul id='Kw1jc'></ul><sub id='Kw1jc'></sub></form><legend id='Kw1jc'></legend><bdo id='Kw1jc'><pre id='Kw1jc'><center id='Kw1jc'></center></pre></bdo></b><th id='Kw1jc'></th></span></q></dt></tr></i><div id='Kw1jc'><tfoot id='Kw1jc'></tfoot><dl id='Kw1jc'><fieldset id='Kw1jc'></fieldset></dl></div>
              <tbody id='Kw1jc'></tbody>

          1. <small id='Kw1jc'></small><noframes id='Kw1jc'>

                <legend id='Kw1jc'><style id='Kw1jc'><dir id='Kw1jc'><q id='Kw1jc'></q></dir></style></legend>

                <tfoot id='Kw1jc'></tfoot>
                • <bdo id='Kw1jc'></bdo><ul id='Kw1jc'></ul>
                  本文介绍了本地化 javascript 消息和验证文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在开发一个多语言的网络项目.例如,该项目的一部分涉及一些自定义的谷歌地图,该地图利用客户端接口使用 jquery/.net 将点添加到地图并将它们保存到数据库中.

                  I'm working on a web project that is multilingual. For example, one portion of the project involves some custom google mapping that utilizes a client-side interace using jquery/.net to add points to a map and save them to the database.

                  会有一些验证和其他信息性消息(例如请在地图上至少添加一个点")必须本地化.

                  There will be some validation and other informational messaging (ex. 'Please add at least one point to the map') that will have to be localized.

                  我现在能想到的唯一选择是:

                  The only options I can think of right now are:

                  1. 在 javascript 中使用代码渲染块从资源文件中提取本地化消息

                  1. Use a code render block in the javascript to pull in the localized message from a resource file

                  使用带有 meta:resourcekey 的隐藏字段,以使用当前文化自动从资源文件中获取正确的本地化消息,并在必要时在 jquery 中获取 .val().

                  Use hidden fields with meta:resourcekey to automatically grab the proper localized message from the resource file using the current culture, and get the .val() in jquery when necessary.

                  每次需要消息时,调用网络服务以按键/语言获取正确的消息.

                  Make a webservice call to get the correct message by key/language each time a message is required.

                  有什么想法、经验吗?

                  我更喜欢使用 .net 资源文件来与应用程序的其余部分保持一致.

                  I'd prefer to use the .net resource files to keep things consistent with the rest of the application.

                  推荐答案

                  好的,我构建了一个通用的 Web 服务来允许我获取资源并将它们返回到字典中(可能是转换为字典的更好方法)...

                  Ok, I built a generic web service to allow me to grab resources and return them in a dictionary (probably a better way to convert to the dictionary)...

                  <WebMethod()> _    
                  <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XmlSerializeString:=True)> _
                      Public Function GetResources(ByVal resourceFileName As String, ByVal culture As String) As Dictionary(Of String, String)
                  
                          Dim reader As New System.Resources.ResXResourceReader(String.Format(Server.MapPath("/App_GlobalResources/{0}.{1}.resx"), resourceFileName, culture))
                          If reader IsNot Nothing Then
                              Dim d As New Dictionary(Of String, String)
                              Dim enumerator As System.Collections.IDictionaryEnumerator = reader.GetEnumerator()
                              While enumerator.MoveNext
                                  d.Add(enumerator.Key, enumerator.Value)
                              End While
                              Return d
                          End If
                  
                          Return Nothing
                  
                      End Function
                  

                  然后,我可以获取这个 json 结果并将其分配给一个局部变量:

                  Then, I can grab this json result and assign it to a local variable:

                  // load resources
                  $.ajax({
                      type: "POST",
                      url: "mapping.asmx/GetResources",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      data: '{"resourceFileName":"common","culture":"en-CA"}',
                      cache: true,
                      async: false, 
                      success: function(data) {
                          localizations = data.d;                
                      }
                  });
                  

                  然后,您可以像这样从局部变量中获取您的值:

                  Then, you can grab your value from the local variable like so:

                  localizations.Key1

                  localizations.Key1

                  这里唯一的问题是,如果要将本地化分配给全局变量,则必须运行它 async=false,否则在需要时将无法获得翻译.我正在尝试使用获取",以便可以缓存响应,但它对我不起作用.看到这个问题:

                  The only catch here is that if you want to assign the localizations to a global variable you have to run it async=false, otherwise you won't have the translations available when you need them. I'm trying to use 'get' so I can cache the response, but it's not working for me. See this question:

                  不能通过 GET ajax Web 请求返回 Dictionary(Of String, String),适用于 POST

                  这篇关于本地化 javascript 消息和验证文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 web.sitemap 中实现本地化 下一篇:StreamReader 抱怨文件不存在,但确实存在

                  相关文章

                  最新文章

                  <legend id='D3QdT'><style id='D3QdT'><dir id='D3QdT'><q id='D3QdT'></q></dir></style></legend>
                    <bdo id='D3QdT'></bdo><ul id='D3QdT'></ul>
                  <tfoot id='D3QdT'></tfoot>

                  <small id='D3QdT'></small><noframes id='D3QdT'>

                      <i id='D3QdT'><tr id='D3QdT'><dt id='D3QdT'><q id='D3QdT'><span id='D3QdT'><b id='D3QdT'><form id='D3QdT'><ins id='D3QdT'></ins><ul id='D3QdT'></ul><sub id='D3QdT'></sub></form><legend id='D3QdT'></legend><bdo id='D3QdT'><pre id='D3QdT'><center id='D3QdT'></center></pre></bdo></b><th id='D3QdT'></th></span></q></dt></tr></i><div id='D3QdT'><tfoot id='D3QdT'></tfoot><dl id='D3QdT'><fieldset id='D3QdT'></fieldset></dl></div>