所以我在我的項目中使用了Angular Translate v2.0.0,並創建了三個語言文件:「en.json」,「en-US.json」和「en-EU.json 「通過StaticFilesLoader加載。我想要發生的是當密鑰不存在於其中一個「en- *」文件中以在「en.json」文件中查找它時。這可能嗎?它在我通過$ translateProvider.translations()定義我的翻譯時起作用,但我需要加載靜態文件。Angular Translate - 具有StaticFilesLoader的FallbackLanguage
這裏是我的代碼:
/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」不存在。