lingua

lingua

Angular i18n library wrapping Jed which allows for gettext-style support in html and javascript. Supporting singular, plural and interpolation/sprintf. Full stack tooling, like xgettext for text extraction, packaged for use with Grunt at grunt-lingua

Dependencies

Included in /vendor * Jed * Microajax

Usage

Usage in html/partial/view

Usage in service/controller

Initialize the module js // Angular init stuff angular.module('modulename').run(['$rootScope',...,'linguaService',function($rootScope,...,linguaService) { $rootScope._ = linguaService._; $rootScope._n = linguaService._n; ... }]);

And wrap it up on your page <!doctype html> <html lang="en" xmlns:ng="http://angularjs.org"> <!-- manual bootstrap so no ng-app --> ... <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script> ... <script src="js/lingua.js"></script> <script src="js/vendor/jed.js"></script> <script src="js/vendor/microajax.js"></script> <script> angular.element(document).ready(function() { Lingua.init(document, function() { angular.bootstrap(document, ['modulename']); }); }); </script> </body> </html>

Tooling

Requirements:

  1. python + pybabel + jinja2
  2. nodejs + >npm install -g po2json

Simple babel.cfg file:

[javascript:*.js] encoding = utf-8

[jinja2: *.html] encoding = utf-8

Workflow:

Generate .pot file:

Translations

tool like poedit to create a catalog and make translations (outputs .po/.mo files)

Generate .json

All of the above wrapped up for grunt at grunt-lingua

comments powered by Disqus
This page was last updated almost 4 years ago.