Reputation: 1399
We are using angular 1.2.16 and i18next 0.2.6 for development. In our application localization works fine when JSON from same server.
Now we came across with the new requirement, to load resources string i.e. JSON files from another content server. let say load JSON from "http://mysite/locales/en-us/sample.json"
<head>
<meta charset="utf-8"/>
<title>i18next test</title>
<script src="i18next.js"></script>
<script src="angularjs/1.2.16/angular.min.js"></script>
<script src="ngI18next.js"></script>
<script>
angular.module('jm.i18next').config(function ($i18nextProvider) {
'use strict';
$i18nextProvider.options = {
lng: 'dev',
useCookie: false,
useLocalStorage: false,
fallbackLng: 'dev',
resGetPath: '../locales/__lng__/__ns__.json',
ns: {
namespaces: ['messages', 'options'],
defaultNs: 'messages'
}
};
});
angular.module('MyApp', ['jm.i18next']).controller('MyProviderCtrl', function ($rootScope, $scope, $i18next) {
$rootScope.$on('i18nextLanguageChange', function () {
$scope.hello = $i18next('messages:header.name');
});
});
</script>
</head>
<body ng-app="MyApp">
<div ng-controller="MyProviderCtrl">
<div>{{hello}}</div>
<div ng-i18next="options:moment-i18n"></div>
<div ng-i18next="messages:header.name"></div>
<div ng-i18next="header.name"></div>
</div>
</body>
I tried to change resGetPath: '../locales/__lng__/__ns__.json' to resGetPath: 'http://mysite/locales/en-us/sample.json' its loading JSON file from server however its not translating text on UI.
Any suggestions how to translate?
Upvotes: 1
Views: 1101
Reputation: 4498
Looks like you're using an older version of http://i18next.com. So i'm not sure that already allowed loading from other servers (CORS).
I would suggest upgrading to current release and enabling "crossDomain" access in the backend: https://github.com/i18next/i18next-xhr-backend
Upvotes: 1