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

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

        我可以从我的 Chrome 扩展程序中获取可用的语言环境翻译列表吗?

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

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

                • 本文介绍了我可以从我的 Chrome 扩展程序中获取可用的语言环境翻译列表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法从我的 Google Chrome 扩展程序中检索所有可用翻译的列表?

                  Is there a way to retrieve from within my Google Chrome extension the list of all available translations?

                  例如,我的应用可能包含以下文件夹:

                  For instance, my app may contain the following folders:

                  _localesenmessages.json
                  _localesfrmessages.json
                  _localesesmessages.json
                  

                  有没有办法从扩展本身中知道它是 enfres?

                  Is there a way to know that it's en, fr, and es from within the extension itself?

                  第二个问题,有没有办法将特定的 messages.json 文件解析为 JSON 数据?我的意思是比 chrome.i18n.getMessage() 提供的功能多一点.

                  And a second question, is there any way to parse a specific messages.json file as the JSON data? I mean a little bit more capabilities than what's provided by chrome.i18n.getMessage().

                  推荐答案

                  两个问题都是肯定的,这要归功于能够读取扩展程序自己的文件夹:

                  Yes to both questions, thanks to the ability to read the extension's own folder:

                  chrome.runtime.getPackageDirectoryEntry(函数回调)

                  返回包目录的 DirectoryEntry.

                  例如,您可以以这种方式列出语言环境(没有弹性,添加您自己的错误检查):

                  For example, you can list locales in this way (not resilient, add your own error checks):

                  function getLocales(callback) {
                    chrome.runtime.getPackageDirectoryEntry(function(root) {
                      root.getDirectory("_locales", {create: false}, function(localesdir) {
                        var reader = localesdir.createReader();
                        // Assumes that there are fewer than 100 locales; otherwise see DirectoryReader docs
                        reader.readEntries(function(results) {
                          callback(results.map(function(de){return de.name;}).sort());
                        });
                      });
                    });
                  }
                  
                  getLocales(function(data){console.log(data);});
                  

                  同样,您可以使用它来获取 messages.json 文件的 FileEntry 并解析它.
                  或者您可以按照 Marco's answer 中所述使用 XHR,一旦您知道文件夹名称.

                  Likewise, you can use this to obtain a FileEntry for the messages.json file and parse it.
                  or you can use XHR as described in Marco's answer once you know the folder name.

                  这篇关于我可以从我的 Chrome 扩展程序中获取可用的语言环境翻译列表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 jquery-i18n-properties 和 JavaScript 动态更改语言? 下一篇:您如何处理带有标记的文本翻译?

                  相关文章

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

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

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