AngularJS​ 的国际化和本地化模块:angular-translate

jopen 11年前

AngularJS​ 的国际化和本地化模块:angular-translate

angular-translate 是一个 AngularJS 的模块,用于简化 i18n 和 l10n 应用的便携,实现了延迟加载和多元化。

var app = angular.module('at', ['pascalprecht.translate']);    app.config(function ($translateProvider) {    $translateProvider.translations('en', {      TITLE: 'Hello',      FOO: 'This is a paragraph.',      BUTTON_LANG_EN: 'english',      BUTTON_LANG_DE: 'german'    });    $translateProvider.translations('de', {      TITLE: 'Hallo',      FOO: 'Dies ist ein Paragraph.',      BUTTON_LANG_EN: 'englisch',      BUTTON_LANG_DE: 'deutsch'    });    $translateProvider.preferredLanguage('en');  });    app.controller('Ctrl', function ($scope, $translate) {    $scope.changeLanguage = function (key) {      $translate.use(key);    };  });

Features

It provides components like filters and directives, asynchronous loading of i18n data, full pluralization support through MessageFormat and much more!

Flexibility

angular-translate is very flexible. You can build your own loaders, storages or error handlers and extend angular-translate to your needs!

项目主页:http://www.open-open.com/lib/view/home/1392601198069