I’d like to use i18n in my project. But I met with a problem in the process. The question was that the structure of directory I designed is not fit to the requirement of i18n. This question resulted the resource files cannot be loaded normally. To be better understanding, I will include more details in the following description.
The structure of directory in my project can be abstracted as below:
app/
-- config.js
-- widgets/
-- WidgetName/
-- nls/
-- strings.js
-- Widget.js
-- index.html
I set up the baseUrl as the root directory of application. Then, call the resource file in the Widget.js and depends this Widget in the index.html. The code is as below:
config.js:
require.config({
baseUrl: '/app/widgets'
});
Widget.js:
define(["i18n!./nls/strings.js"], function (nls) {
...
});
index.html:
require(["widgets/WidgetName/Widget"], function (Widget) {
...
});
However, when I ran the code, the request path of i18n was “app/WidgetName/nls/strings.js” other than “app/widgets/WidgetName/nls/strings.js” which I expected. It implied i18n used the directory in the index.html other than the baseUrl I set up.
Therefore, my questions are as following:
- How to solve this problem if I don’t want to modify the directory structure?
- How to set up the baseUrl as the default path of i18n?
I’d like to use i18n in my project. But I met with a problem in the process. The question was that the structure of directory I designed is not fit to the requirement of i18n. This question resulted the resource files cannot be loaded normally. To be better understanding, I will include more details in the following description.
The structure of directory in my project can be abstracted as below:
I set up the baseUrl as the root directory of application. Then, call the resource file in the Widget.js and depends this Widget in the index.html. The code is as below:
config.js:
Widget.js:
index.html:
However, when I ran the code, the request path of i18n was “app/WidgetName/nls/strings.js” other than “app/widgets/WidgetName/nls/strings.js” which I expected. It implied i18n used the directory in the index.html other than the baseUrl I set up.
Therefore, my questions are as following: