angularjs-l10n

Simple module for localization your angular applications

Added by: Sam Deering

GitHub

Repository

one001/angularjs-l10n

Stats

Stars: 0

Watchers: 0

Forks: 0

Module Description

L10n module for Angular.js

==============

Simple and fast module for localization your angular applications.

Installation

bower install angularjs-l10n

Usage

angular.module('myApp', ['l10n']);

You can use either external files with translations or just add translations from your main.js

For external files you have to create directory with files inside. Each file for each localization. For example en.json.

Configure

angular.module('myApp', ['l10n']).config(['l10nProvider', function(l10n) {
  l10n.setLocale('en'); // first of all you must set locale. You can take it from anywhere, for instance navigator.language
  
  l10n.setExtension('js'); // not required. By default 'json'
  
  l10n.pathToFile('translations/'); // if you set pathToFile, your JSON file with translations from that directory will be loaded
  
  // you can just add any translations like this
  l10n.add('en', {
    'Hello World!': 'Hello World',
  });
});

After configuration you can use l10n as a service:

Just add l10n as dependency in your controller or directive or whatever:

angular.module('myApp', ['l10n']).controller('myController', ['$scope', 'l10n', function($scope, l10n) {
  console.log(l10n.trans('Hello World!'));
}]);

Or as a filter. In your templates write:

  <span>{{ 'Hello World!' | trans }}</span>

Module stats last updated: 2015-04-28 11:06:58

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!