Search code examples
javascriptinternationalizationrequirejsamdr.js

Is there a way to add all languages to optimized RequireJS project?


I have support for two languages in my project (english and spanish). The thing is, that when I optimize the code with r.js, the output file has the root language (english) embed, but not the other variants (spanish).

How can I force the optimizer to embed all the languages on the output file?

Example:

// /app/app.js
define(["i18n!nls/something"], function(somethingLanguage) { /* stuff */ });

// /app/nls/something.js
define({
    "root": {
        "hi": "Hi!"
    },
    "es": true
});

// /app/nls/es/something.js
define({
    "hi": "¡Hola!"
});

// /app/result-file.js
define("nls/something", { "hi": "Hi!" });define(["i18n!nls/something"], function(somethingLanguage) { /* stuff */ });

As you can see, the "nls/es/something" is missing from the "result-file". It should look like this:

// /app/result-file.js
define("nls/something", { "hi": "Hi!" });define("nls/es/something", { "hi": "¡Hola!" });define(["i18n!nls/something"], function(somethingLanguage) { /* stuff */ });

I hope you can help me, guys.

Thanks!


Solution

  • Fixed this issue with an extra configuration in r.js:

    config: {
        "i18n": {
            locale: "es"
        }
    }
    

    Hope it helps others with the same issue.