HaxeFoundation/haxe — pull request #3199 by Atry (2014-07-22 14:05:06+00:00)
Title: Proposal of haxe.locale.Translator

`haxe.locale.Translator` contains some utilities to help people publish their applications or libraries in multi-languages.

Usage:

1. Create translation in json format, e.g. https://github.com/Atry/haxe/blob/605ba8e470aacef27d3602d67f2927592b1c005a/tests/unit/translation.zh_CN.UTF-8.json
2. Add `--macro haxe.locale.Translator.addTranslationFile("zh_CN.UTF-8", "unit/translation.zh_CN.UTF-8.json")` to your application's `build.hxml` or your library's `extra.hxml`
3. Surround `haxe.locale.Translator.translate` to your string literal or string interpolation.
4. Switch the translation for different locales:
* Use `-D locale=zh_CN.UTF-8` to to switch locales at compile-time
* Or, Use `-D run_time_translation` and change `haxe.locale.Translator.runTimeLocale` to switch locales at run-time.

I want to merge the proposed class `haxe.locale.Translator` into Haxe standard library because:
1. It is too tiny to become a standalone project.
2. Other classes in Haxe standard library may use `haxe.locale.Translator` to create localized error messages when throwing exceptions.

Like https://github.com/rockswang/haxe-i18n, `haxe.locale.Translator` is implemented in macro.

But unlike https://github.com/rockswang/haxe-i18n, `haxe.locale.Translator` supports macro platform.

Even the error messages from `haxe.locale.Translator` are translated by `haxe.locale.Translator` itself (https://github.com/Atry/haxe/blob/605ba8e470aacef27d3602d67f2927592b1c005a/std/haxe/locale/Translator.hx#L110).