Simple Dojo i18n implementation

I recently started learning dojo for personal use and experience. So far, I have been engaged in training materials on various dojo materials (on their website and on the Internet), and I have β€œstruggled” with implementing a specific infrastructure for a more complex application (or good practice). I found one interesting project ( https://github.com/csnover/dojo-boilerplate ) and an article ( http://www.sitepen.com/blog/2011/05/04/what-is-the-best-way -to-start-a-dojo-project / ). At the same time, I think my first problem is solved. Correct me if I am wrong.

It seems to me that the i18n tutorial lacks a specific implementation. For example, I would like to add i18n to the dialog box from the project template.

define([ 'dojo/_base/declare', 'dijit/Dialog' ], function (declare, Dialog) { return declare(Dialog, { title: 'Hello World', content: 'Loaded successfully!' }); }); 

Here is my project hierarchy:

enter image description here

As you can see, I create my own nls folder for my application and save my "lines" for different (lang-locale). Now, how do I indicate the contents of the locale on the header or content for my dialog code above. I recently made i18n on ruby ​​on rails (with the concept of MVC), and depending on my view, I had to create a localization file (.yml) for this particular kind. I know that RoR and dojo are not really the same thing, but a widget (can be compared with my presentation), and therefore each widget should have its own localization ... I came through 2 tutorials, first and second . Maybe I'm reading this all wrong.

I now have something like this, but it does not work. What am I missing?

 dojo.requireLocalization("app", "dialog"); define([ 'dojo/_base/declare', 'dijit/i18n' 'dijit/Dialog' ], function (declare, Dialog) { i18n: dojo.i18n.getLocalization("app", "dialog"), return declare(Dialog, { title: i18n.title, content: i18n.content }); }); 

Thanks.

EDIT:

 define([ 'dojo/_base/declare', 'dojo/i18n!app/nls/labels', 'dijit/Dialog' ], function (declare, labels, Dialog) { return declare(Dialog, { title: labels.title, content: labels.content }); }); 

I have no error now, but my label.title is empty ...?

EDIT (1): I forgot to add the root to the default nls folder.

+4
source share
1 answer

Here is an example of how I created some localization dialogs.

Directory structure

 myApp\ dialog\ myDialog.js nls\ dialog.js fr-ca\ dialog.js 

myDialog.js

 define("myApp/dialog/myDialog", [ "dojo", "dijit/Dialog", "dojo/i18n", "dojo/i18n!./nls/dialog" // this is a relative path to the // dialog.js from myDialog.js ], function(dojo, Dialog) { var i18n = dojo.i18n.getLocalization( "myApp.dialog", // this is the directory path to the nls folder "dialog" // this is the file ); return declare(Dialog, { title: i18n.title, content: i18n.content }); }); 
+4
source

Source: https://habr.com/ru/post/1416651/


All Articles