Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change path for i18n with RequireJS r.js build

I'm using RequireJS for my javascript project, and r.js to build one single javascript file for production. This single file (main.js) is then uploaded to a CDN. This all works very fine, but now I'm trying to add i18n support.

The problem is that the location of the i18n file is relative to the main javascript file. So within a module, I would have:

define(['i18n!nls/text'], function(Translation) { });

This all works very fine when I'm developing, but for production the problem is that the translation file is not relative to the main.js file as this is placed in a CDN. I don't want to store the translation file in the CDN, so how do I change the reference to that file in the build process?

like image 790
Bjorn Avatar asked Feb 11 '14 11:02

Bjorn


1 Answers

I found a solution to my problem. In the RequireJS config I've added:

requirejs.config({
    paths: {
        nls: "/js/nls"
    }
});

Because the path starts with a slash, RequireJS knows it's not relative. Now the problem I got was that the build would fail, as RequireJS would be looking for default language files in /js/nls. Therefore, I added a symlink from the root of my webserver to the nls directory on the machine.

like image 82
Bjorn Avatar answered Sep 25 '22 17:09

Bjorn