使用 NLS/本地化进行 Dojo 定制构建

发布于 2024-08-09 12:20:37 字数 2156 浏览 5 评论 0原文

我在 Dojo 中实现跨域自定义构建时遇到问题。 情况如下:我有一个相当大的应用程序,有大量的本地化包,所以基本上目录结构是这样的
核心\(我的模块)
nls\
fr\
zh\
....
构建我的模块时,结果是一个大的 core.js/core.xd.js 文件,当然,它不包含本地化。在本地化 nls 目录(en/fr/etc)中,我发现构建后每个包都已构建/缩小,并且每种语言都有一个更大的文件 core_fr.js/core_en.fs,其中仅包含 Dojo/Dijit 相关字符串。

所以我的构建脚本是

            layers: [
            {
    resourceName: "core",
            name: "../core/trusted.js",
            dependencies: [
                      "dojo.i18n",
                      //data
                      "dojox.data.JsonRestStore",
                      "dojox.data.XmlStore",
                      "dojox.rpc.Service",
                      "dojox.form.FileInput",
                       ...
                      "core.controller.Fusebox"                        
],
                  prefixes: [
                ["dijit","../dijit"],
            ["dojox","../dojox"],
                    ["core", "../core"]
                  ]

在 core.controller.Fusebox 类中,我尝试

dojo["requireLocalization"]("core", "FuseboxContent");

在此处加载 1 nls 它会死掉,但是

availableFlatLocales is undefined
[Break on this error] var locales = availableFlatLocales.split(",");\r\n

html 文件中的我的配置是:

// version build
  var djConfig = {
    baseUrl: 'https://..../',
    modulePaths: { 'core': 'core'},
    useXDomain: true,
    xdWaitSeconds: 10,
    parseOnLoad: true,
    afterOnLoad: true,
//  debugAtAllCosts: true,
    isDebug: true,
    locale: "fr"
  };

,然后

<script type="text/javascript" src="http://xd.woopic.com/dojoroot/1.3.2-xd/dojo/dojo.xd.js.uncompressed.js"></script> 
<script type="text/javascript" src="https://..../core/trusted.js.uncompressed.js"></script>  

当然 我使用未压缩的进行调试。 问题是,在运行时,Dojo 尝试加载我的包但找不到它们,我想将它们嵌入到我的图层文件中,因此不需要额外的加载。 这能实现吗?当我们这样做时,是否有任何具有跨域本地化的工作站点/示例? 更新:我继续分析,问题似乎在于我正在动态加载 nls,因此构建解析器找不到 requireLocalization() 调用。因此项目nls文件只包含dojo/dijit相关的内容。但是,我在虚拟文件中添加了一些捆绑包加载,并且 core/nls 的内容仍然被构建器忽略。

感谢您提供任何信息,我的搜索已经结束,网上关于这个主题的信息不多。

I have a problem implementing a cross domain custom build in Dojo.
The situation is as follows: i have a pretty large application, with a good number of localisation bundles, so basicly the directory structures is like
core\ (my module)
nls\
fr\
en\
....
When building my module the result is a big core.js/core.xd.js file, which, bien sur, does not contain the localisations. In the localisation nls directories (en/fr/etc) i find after the build each bundle builded/minified, and a bigger file for each language, core_fr.js/core_en.fs, which contains only Dojo/Dijit related strings.

so my build script is

            layers: [
            {
    resourceName: "core",
            name: "../core/trusted.js",
            dependencies: [
                      "dojo.i18n",
                      //data
                      "dojox.data.JsonRestStore",
                      "dojox.data.XmlStore",
                      "dojox.rpc.Service",
                      "dojox.form.FileInput",
                       ...
                      "core.controller.Fusebox"                        
],
                  prefixes: [
                ["dijit","../dijit"],
            ["dojox","../dojox"],
                    ["core", "../core"]
                  ]

In the core.controller.Fusebox class i try to load 1 nls

dojo["requireLocalization"]("core", "FuseboxContent");

here it will die, however with

availableFlatLocales is undefined
[Break on this error] var locales = availableFlatLocales.split(",");\r\n

My config in the html file is :

// version build
  var djConfig = {
    baseUrl: 'https://..../',
    modulePaths: { 'core': 'core'},
    useXDomain: true,
    xdWaitSeconds: 10,
    parseOnLoad: true,
    afterOnLoad: true,
//  debugAtAllCosts: true,
    isDebug: true,
    locale: "fr"
  };

and then

<script type="text/javascript" src="http://xd.woopic.com/dojoroot/1.3.2-xd/dojo/dojo.xd.js.uncompressed.js"></script> 
<script type="text/javascript" src="https://..../core/trusted.js.uncompressed.js"></script>  

I used the uncompressed for debug, of course.
The problem is that, on runtime, Dojo tries to load my bundles and can not find them, and i would like to embed them in my layer file, so no extra loads will be required.
Can this be achieved? And while we're at it, are there any working sites/examples with cross domain localisations?
UPDATE: i continued my analysis and the problem seems to lay in the fact that i am dynamicaly loading nls, so the build parser can not find the requireLocalization() calls. Therefore the project nls file contains only dojo/dijit related content. However, i added a few bundle loads in a dummy file, and the content of core/nls is still ignored by the builder.

Thanks for any info, i am pretty much at the end of my searches, there isn't much on the net on this subject.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看海 2024-08-16 12:20:37

几天前我也遇到了类似的问题。首先,您可以通过将可用区域设置设置为 requireLocalization 调用的第四个参数来解决该错误。

例如

dojo.requireLocalization("core", "FuseboxContent", null, "en,fr");

,尽管您不必这样做。

您是否尝试过如下包含本地化?

dojo.requireLocalization("core", "FuseboxContent"); // and not dojo["require..."]

I had a similar issue a few days ago. First of all, you can get around the error by setting the available locales as the 4th parameter of the requireLocalization call.

e.g.

dojo.requireLocalization("core", "FuseboxContent", null, "en,fr");

though you should not have to do that.

Did you try including the localization as follows?

dojo.requireLocalization("core", "FuseboxContent"); // and not dojo["require..."]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文