Internationalization
This patchset internationalizes Sapphire. To do so, all strings are marked off for translation as:
JavaScript: A call to window._ with the template. For mix-ins, use {syntax} and then pass in an object as the second argument, mapping the key "syntax" to the desired value. This is ChromeOS convention.
Mustache: Wrap the string in {{#_}}string{{/_}}
, mapping to the above lambda.
Static HTML: Set the data-i18n
property to the attribute that needs to be internationalized, or to an empty string (as a boolean) to internationalize the textContent. This only applies to index.html
and will only be translated on page load. It should NOT be used in templates.
Each marked string corresponds to an entry in po/sapphire.pot; this process is manual at the moment.
Each language has a corresponding po/langcode.po file. See gettext documentation for reference on how this works.
po
files are updated from the pot
and converted to JavaScript via the included Makefile, adding a dev dependency on the package po2json
, available in Debian and npm.
A tiny implementation of 1/1000 of gettext is provided in i18n.js to implement the aforementioned _ syntax.
A reference Spanish translation is included to test the patch and as a base for other languages.
Closes #8 (closed)
I recommend reading the cumulative diff, rather than the commit log :)