admin管理员组文章数量:1320864
I'm new to both programming and angular. I need to use angular-translate with its' useUrlLoader, since my translations are stored in database. $translateProvider.useUrlLoader('foo/bar.json');
$translateProvider.preferredLanguage('en');
While using staticFilesLoader seems enough simple for me, since I need just two separate json files with translation data, i can't get what useUrlLoader expects. As far as I understand, it expects json which includes multiply language translations (both English and German for example). Can't find example of such file anywhere.
I'm new to both programming and angular. I need to use angular-translate with its' useUrlLoader, since my translations are stored in database. $translateProvider.useUrlLoader('foo/bar.json');
$translateProvider.preferredLanguage('en');
While using staticFilesLoader seems enough simple for me, since I need just two separate json files with translation data, i can't get what useUrlLoader expects. As far as I understand, it expects json which includes multiply language translations (both English and German for example). Can't find example of such file anywhere.
Share Improve this question edited Apr 14, 2015 at 18:45 Олег Петровський asked Apr 14, 2015 at 18:37 Олег ПетровськийОлег Петровський 831 silver badge7 bronze badges1 Answer
Reset to default 8The StaticFilesLoader expects that you store all translations for different languages in separate files on the server. It makes requests like this:
/your/server/i18n/locale-en.json
/your/server/i18n/locale-de.json
/your/server/i18n/locale-fr.json
where /your/server/i18n/locale-
and .json
are prefix and suffix (respectively) which you've passed during configuration.
The UrlLoader expects that you have one "clever" endpoint instead of a bunch of files. It makes requests like this:
/your/server/i18n/locale-endpoint?lang=en
/your/server/i18n/locale-endpoint?lang=de
/your/server/i18n/locale-endpoint?lang=fr
where /your/server/i18n/locale-endpoint
and lang
are url and queryParameter (respectively) which you've passed during configuration. The url is required, but queryParameter may be omitted (defaults to "lang").
You can setup the UrlLoader either like this:
$translateProvider.useUrlLoader('/path/to/your/endpoint', {
queryParameter : 'localeKey'
});
or like this:
$translateProvider.useLoader('$translateUrlLoader', {
url : '/path/to/your/endpoint',
queryParameter : 'localeKey'
});
Both loaders expect to load translation as JSON object. It could look like this:
{
"translationId" : "Translation for this ID",
"anotherTranslationId": "Another translation for another id"
}
You can find more information about different loaders in the official guide.
A source code of the UrlLoader can be found in the angular-translate repository.
Hope, this helps.
本文标签: javascriptPascalPrecht angulartranslate useUrlLoaderStack Overflow
版权声明:本文标题:javascript - PascalPrecht angular-translate useUrlLoader - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742015682a2413721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论