Last active
January 30, 2016 07:58
-
-
Save alundiak/6653473 to your computer and use it in GitHub Desktop.
i18n.js Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // rest response in JSON format. | |
| { | |
| "statuses": [{ | |
| "name": "open", | |
| "count": 2 | |
| }, { | |
| "name": "pending", | |
| "count": 1 | |
| }, { | |
| "name": "approved", | |
| "count": 0 | |
| }, { | |
| "name": "processing", | |
| "count": 0 | |
| }, { | |
| "name": "placed", | |
| "count": 0 | |
| }] | |
| } | |
| // This object is being parsed by Backbone/Marionette | |
| // and passed to tepmplate as data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "open": "Open", | |
| "statuses": { | |
| "open":"Open", | |
| "pending":"Pending" | |
| } | |
| "name": "MyName" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/template"> | |
| <!-- This is not very well for me. | |
| Because UNDERI18N works only with json data for 1 level. No namespaces support. | |
| And it evaluate exact property of resource object, and I need evluation by value | |
| --> | |
| <h3>JSON data: <%= name %></h3> | |
| <!-- Will be "open", "pending" and other from JSON_REST data --> | |
| <h3>UNDERI: <%_ name %></h3> | |
| <!-- Will be "MyName" underi_resource.json data --> | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // object which represents strings for i18n to be use. | |
| // root is main element from where i18n gets all data. | |
| define({ | |
| "root" : { | |
| "open": "Open", | |
| "statuses": { | |
| "open":"Open", | |
| "pending":"Pending" | |
| } | |
| } | |
| //, "pl-pl" : true | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/template"> | |
| <% var labels = require('i18n!path/to_folder/nls/3_labels'); %> | |
| <!-- | |
| This is what I expected, but | |
| Need to include resource bundle object (labels) on every template files | |
| But Namespace supported :) | |
| --> | |
| <h3>Require.JS: i18n: <%= labels[name] %></h3> | |
| <h3>Require.JS: i18n: <%= labels.statuses[name] %></h3> | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment