Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wonder93/i18n-gas
libintl-like (gettext) internationalization script for Google Apps Script
https://github.com/wonder93/i18n-gas
Last synced: 26 days ago
JSON representation
libintl-like (gettext) internationalization script for Google Apps Script
- Host: GitHub
- URL: https://github.com/wonder93/i18n-gas
- Owner: WOnder93
- Created: 2013-04-07T21:39:54.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-04-08T13:58:13.000Z (almost 12 years ago)
- Last Synced: 2023-05-28T08:05:12.576Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 125 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
I18N for Google Apps Script
========I18N is a simple libintl-like internationalization script for Google Apps Script.
It supports gettext and ngetttext functions and partially supports multiple domains (but seriously, who uses them anyway...).## Using the script
1. Copy the contents of **I18N.js** into a new file in your project.
2. In your code, use `I18N.[d][n]gettext` functions (or the `_` alias for `I18N.gettext`) to mark strings as translatable (you *must* use double quotes):```javascript
_("This will be translated.");
I18N.gettext("Also this...");
Utilities.formatString(I18N.ngettext("I have %s apple", "I have %s apples", n), n);
```3. Copy your code files into a local directory and generate a message template:
```bash
$ xgettext --from-code=utf-8 -C -k_ -o messages.pot source1.gs source2.gs ui.html ...
```4. Use the template to create .po files for the languages you want to support.
5. Use **msgfmt.py** to generate a Google Apps Script file containing the translated messages from one or more .po files:```bash
$ python msgfmt.py -o messages.gs *.po
```6. Add the generated script file (messages.gs by default) to your project.
You can get/set current locale with `I18N.getLocale`/`I18N.setLocale` functions. It is stored as a user property with key `"LANGUAGE"`, but you can change the code to whatever you need.