Skip to content

Instantly share code, notes, and snippets.

@alundiak
Last active January 30, 2016 07:58
Show Gist options
  • Select an option

  • Save alundiak/6653473 to your computer and use it in GitHub Desktop.

Select an option

Save alundiak/6653473 to your computer and use it in GitHub Desktop.
i18n.js Example
// 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.
{
"open": "Open",
"statuses": {
"open":"Open",
"pending":"Pending"
}
"name": "MyName"
}
<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>
// 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
});
<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