角转换静态加载文件帕斯卡尔precht [英] angular translate static-loader-file PascalPrecht

查看:128
本文介绍了角转换静态加载文件帕斯卡尔precht的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm使用角转换(帕斯卡precht模块)。

I´m using Angular-translate (PascalPrecht module).

我successed使其按照与实施例工作:<一href=\"http://www.ng-newsletter.com/posts/angular-translate.html\">http://www.ng-newsletter.com/posts/angular-translate.html

I successed to make it work according to the example in: http://www.ng-newsletter.com/posts/angular-translate.html

不过,我想有使用架静态文件不同的JSON文件中的所有我的翻译,但是这不是为我工作。我不确定I'm做就在这里。

However, I would like to have all my translations in different json files using loader-static-files, but this is not working for me. I´m not sure I´m doing right here.

在我的角度模块I刚刚更换了code工作(现在的注释)与架静态调用:

In my angular module I just replaced the code working (now commented) with the loader-static call:

angular.module('myApp.i18n', ['pascalprecht.translate'])
    .config(['$translateProvider', function ($translateProvider) {
        /*$translateProvider.translations('en', {
            HOME: 'Home',
            COMPANIES: 'Companies',
            WHAT_TO_DO: 'What to do',
            ABOUT: 'About us',
            CONTACT: 'Contact'
        })
        .translations('es', {
            HOME: 'Inicio',
            COMPANIES: 'Empresas',
            WHAT_TO_DO: 'Qué hacer',
            ABOUT: 'Nosotros',
            CONTACT: 'Contacto'
        });*/
        $translateProvider.preferredLanguage('es');

        $translateProvider.useStaticFilesLoader({
          prefix: '/languages/',
          suffix: '.json'
        });
}]);

我已经加入到我的应用程序文件夹中的文件:

I have added to my app folder the files:

/app/languages​​/en_US.json
 /app/languages​​/es.json

/app/languages/en_US.json /app/languages/es.json

当我打开我家的网站,我看到下一个错误控制台:

When I load my home site, I see next error in console:

http://localhost:1234/languages/es.json 404 (Not Found)

如果我删除第一'/'在我的preFIX,像这样的:

If I remove the first '/' in my prefix, like this:

$translateProvider.useStaticFilesLoader({
              prefix: 'languages/',
              suffix: '.json'
            });

然后,我得到下一个错误控制台:

Then, I get next error in console:

意外标记^ h

对不起,我想我不undertand这应该是如何工作的。

Sorry, I think I don´t undertand how this should work.

推荐答案

请确保您的服务器发送以.json 为JSON而不是纯文本。
此外,确保了以.json文件的名称取决于相应的语言键。

Make sure that your server sends the .json as json and not as plain text. Also, make sure that the names for the .json files depend on the corresponding language key.

你可以在这里阅读:的http://角翻译。 github.io/docs/#/guide/12_asynchronous-loading~~V (使用staticFilesL​​oader)

As you can read here: http://angular-translate.github.io/docs/#/guide/12_asynchronous-loading ("Using staticFilesLoader")

在code对我来说很好,所以一旦你您的服务器不发送JSON作为JSON固定的问题,事情应该工作。

The code looks good to me, so once you've fixed the issue that your server isn't sending json as json, things should work.

这篇关于角转换静态加载文件帕斯卡尔precht的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆