Поэтому я использую Angular Translate v2.0.0 в своих проектах, и у меня есть три языковых файла: "en.json", "en- US.json" и "en- EU.json", которые загружаются через StaticFilesLoader, Я хочу, чтобы это произошло, когда ключ не существует внутри одного из файлов en- *, чтобы найти его внутри файла "en.json". Это возможно? Он работает, когда я определяю свои переводы через $ translateProvider.translations(), но мне нужно загрузить статические файлы.
Вот мой код:
/i18n/en.json
{ "sidebar": { "HEADING": "I AM HEADING" }}
/i18n/en-US.json
{ "formats": { "date": "MM/DD/YYYY" }}
/i18n/en-EU.json
{ "formats": { "date": "DD/MM/YYYY" }}
Тогда, внутри моей конфигурации у меня есть:
// Register a loader for the static files
// So, the module will search missing translation tables under the specified urls.
// Those urls are [prefix][langKey][suffix].
$translateProvider.useStaticFilesLoader({
prefix: 'i18n/',
suffix: '.json'
});
// Tell the module what language to use by default
$translateProvider.preferredLanguage('en-US');
// Set the fallback language to use if the string cannot be found in the default locale
$translateProvider.fallbackLanguage('en');
// Tell the module to store the language in the cookies
$translateProvider.useCookieStorage();
// For security, we set the sanitize strategy to make sure our strings are sanitized correctly
$translateProvider.useSanitizeValueStrategy('sanitize');
// For debugging missing translations, uncomment to use
$translateProvider.useMissingTranslationHandlerLog();
Но при загрузке приложения только рендеринг "formats.date" и он говорит, что "sidebar.HEADING" не существует.
Оказывается, что невозможно сделать то, что я хочу делать без CustomLoader или что-то в этом роде. Я только начал использовать https://github.com/RobbinHabermehl/gulp-angular-translate и добавил его к части моего шага сборки. Это все равно, потому что язык будет загружен сразу, а не асинхронный.