Skip to content Skip to sidebar Skip to footer

AngularJS Implementing A Localization For Templates

i want to implement a localization for views (should include the body, too). I've done this before by loading a JSON File and than iterate trough the keys. The keys are class names

Solution 1:

You can use the Localization Service by Coding SmackDown TV

1) Load the service, and include your i18n file. For instance, take this

// /i18/en/dictionary_en.js
[
    {
        "key":"_More_",
        "value":"More",
        "description":"More button"
    }
]

// In the localize service
$http({ method:"GET", url:url, cache:false }).success(localize.successCallback).error(function () {
    // the request failed set the url to the default resource file
    var url = '/i18n/en/dictionary_en.js';
    localize.language = 'en';
    // request the default resource file
    $http({ method:"GET", url:url, cache:false }).success(localize.successCallback);
});

2) In your views use the i18 filter or through ng-bind

<button data-i18n="_More_">

Post a Comment for "AngularJS Implementing A Localization For Templates"