i18n想加载一个未指定的翻译

时间:2015-12-24 09:21:25

标签: internationalization aurelia i18next

我目前正在开展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,我的视图和viewmodel设置如下:

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。但我从来没有在任何地方指明......

1 个答案:

答案 0 :(得分:2)

这就是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,即使它没有在config中指定。它可以是空的但是有效的json文件,内容为{}