【问题标题】:i18n wants to load an unspecified translationi18n 想要加载一个未指定的翻译
【发布时间】:2016-03-30 18:05:06
【问题描述】:

我目前正在开发一个 Aurelia 项目(像 Angular2 这样的网络框架)。 我按照他们的github account 上的指南进行操作,但遇到了问题。

首先,浏览器返回给我这个错误:
GET http://localhost:9000/src/locale/nl/translation.json?_=1450946571510 404 (Not Found)

其次,我在我的应用程序中使用了两种语言:荷兰语 (nl-BE) 和法语 (fr-BE)。

我的文件夹结构如下所示:

src (inside root)
.. locale 
..... fr-BE 
........ translation.json 
..... nl-BE
........ translation.json

这是我的完整 main.js 文件的样子:

import 'bootstrap';
import {I18N} from 'aurelia-i18n';

export function configure(aurelia) {

    aurelia.use
        .standardConfiguration()
        .developmentLogging()
        .globalResources('converters/dateFormat')
        .plugin('components/index')
        .plugin('plugins/index')
        .plugin('aurelia-i18n', (instance) => {
            instance.setup({
                resGetPath: 'src/locale/__lng__/__ns__.json',
                lng: 'nl-BE',
                attributes: ['t', 'i18n'],
                getAsync: true,
                sendMissing: false,
                fallbackLng: 'fr-BE',
                debug: false
            });
        });
    aurelia.start().then(a => a.setRoot());
}

我正在尝试设置一个 hello world,我的视图和视图模型设置如下:

import {inject} from 'aurelia-framework';
import {I18N} from 'aurelia-i18n';

@inject(I18N)
export class EntryDetails {
    constructor(i18n){
        this.i18n = i18n;
        this.i18n.setLocale('nl-BE').then(() => console.log('test'));
    }
}

我的看法:

<template>
    <span t="hello"></span> <span t="world"></span>
</template>

问题不在于它不起作用。问题是我收到一个错误,指出我的文件夹 nl 在我的 locale 文件夹中丢失。但我从来没有在任何地方指定过..

【问题讨论】:

    标签: internationalization aurelia i18next


    【解决方案1】:

    这就是 i18next 解析翻译文件的方式。

    The lookup order for keys is always:
    
    nl-BE language + country 
    nl language only
    fallback thats defined in options.fallbackLng (en) (string or array of fallback language)
    
    loaded resources:
    
    locale/en/translation.json
    locale/nl/translation.json
    locale/nl-BE/translation.json
    

    http://i18next.com/translate/#resolve

    所以你需要有 nl/translation.json,即使它没有在配置中指定。它可以是空但有效的 json 文件,内容为 {}

    【讨论】:

    • 我想到了这个,但作为一个解决方案似乎很“愚蠢”,还是只有我一个人?但它肯定会解决问题是的。
    • 如果您没有其他 nl-... 和 fr-... 语言环境,将 nl 和 fr 语言环境作为主要语言环境而不使用特定国家/地区的语言环境(例如 nl-)会更简单BE或fr-BE
    • 你有一个有效的观点。我会编辑你的消息并在那里;)
    猜你喜欢
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 2013-07-29
    • 2020-02-20
    • 2012-11-12
    相关资源
    最近更新 更多