mozilla/friendlycode — pull request #163 by toolness (2012-12-07 00:23:30+00:00)
Title: Internationalize Friendlycode

Here I have implemented a simple, quick solution to bootstrap localization for Friendlycode.

Goals of the bootstrapping:

* Allow contributors to start localizing ASAP without blocking on us to "perfect" localization.
* Potentially allow contributors to provide better copy for certain components, such as e.g. the overly-technical HTML/CSS help that was scraped off MDN, by contributing to the `en` localization.
* Start with an extremely simple localization infrastructure: just key-value pairs, no initial support for pluralization, gender, or RTL languages. Evolve as needed, preferably without too much churn (e.g., constantly forcing contributors to re-localize the same content).
* Allow contributors to provide feedback on the localization of an app so we can solve any problems sooner rather than later.
* Use a simple but flexible data format for the localization that can easily be converted to whatever interchange format we end up using, be it `.po` files or `.properties` files or something else entirely.
* When possible, use other abstractions that allow us to decouple each component of the localization pipeline from one another, allowing us to replace parts with more powerful alternatives as needed.

Ultimately the initial solution involved the following pieces:

* Use the [tiny](https://raw.github.com/requirejs/i18n/latest/i18n.js) requirejs [i18n plugin](http://requirejs.org/docs/api.html#i18n) and its i18n bundle convention to access localization data in the product's source code.
* Create "stub" root i18n bundles in the product's source code that provide default data for the localization, "scraping" content from existing code/data files as necessary. This allows both for friendlycode to continue to minimally operate from flat files (without requiring a special server or build step) and also for a simple [build-i18n.js](https://github.com/toolness/friendlycode/blob/i18n/build-i18n.js) script to scrape and generate initial source data for localization tools to consume.
* Create a [html-to-i18n-bundle.js](https://github.com/toolness/friendlycode/blob/i18n/js/slowparse-errors/html-to-i18n-bundle.js) module that converts slowparse's HTML error templates into the JSON format expected by requirejs-style i18n bundles. This effectively "scrapes" the templates, providing initial source data for localization tools to consume.
* Create and document a tiny [inline-l10n.js](http://l10n-thimble.toolness.org/docs/inline-l10n.html) module that preprocesses HTML templates in friendlycode and outputs HTML templates with localized content. It can also "scrape" the templates and provide initial source data for localization tools to consume.
* Create and document a simple localization editor, [ghetto-l10n](https://github.com/toolness/ghetto-l10n), which takes the output of `build-i18n.js` and allows contributors to easily localize content and quickly see the results of their work.