采用了棱角分明翻译StaticFilesL​​oader国际化采用了、棱角、分明、oader

由网友(安逸以默)分享简介:我在下面的本教程在NG-通讯应用国际化我的应用程序中使用角翻译。该应用程序正常工作时,我有我的app.js文件中的翻译,但我遇到麻烦StaticFilesL​​oader工作。这是我与app.js注释掉工作code文件 - angular.module('对myApp',[ngCookies',ngRoute',...

我在下面的本教程在NG-通讯应用国际化我的应用程序中使用角翻译。该应用程序正常工作时,我有我的app.js文件中的翻译,但我遇到麻烦StaticFilesL​​oader工作。这是我与app.js注释掉工作code文件 -

  angular.module('对myApp',[ngCookies',ngRoute',ngResource',帕斯卡尔precht.translate',myApp.services',myApp.directives',myApp.controllers',]);angular.module('myApp.services',['ngResource']);angular.module('myApp.directives',[]);angular.module('myApp.controllers',[]);angular.module('对myApp')的.config(['$ httpProvider','$ translateProvider',函数($ httpProvider,$ translateProvider){$ httpProvider.defaults.useXDomain = TRUE;$ httpProvider.defaults.withCredentials = TRUE;删除$ httpProvider.defaults.headers.common ['X-要求-随着'];的console.log($ httpProvider.defaults);/*$translateProvider.translations('en',{    标题:这是我的主页,    HOME:'家',    设置:设置,    注销:注销,    编辑:编辑,    删除:删除,    密码:密码,    CONFIRM_PASSWORD:确认密码,    BUTTON_TEXT_EN:英语,    BUTTON_TEXT_DE:德意志  })  .translations('德',{    标题:模具IST DER首页',    HOME:Zuhause',    设置:Einstellungen',    注销:Ausloggen',    编辑:'Bearbeiten',    DELETE:Löschen',    PASSWORD:Passwort',    CONFIRM_PASSWORD:PasswortBestätigen',    BUTTON_TEXT_EN:englisch',    BUTTON_TEXT_DE:德语  }); * /  $ translateProvider preferredLanguage('恩')。  $ translateProvider.useStaticFilesL​​oader({          preFIX:/语言/',          后缀:以.json        });}]); 

我添加了两个文件复制到我的应用程序,en.json和de.json和一个名为/语言文件夹中。当我尝试运行应用程序,我得到一个错误说:

 未捕获的错误:[$喷油器:unpr]未知提供商:$ translateStaticFilesL​​oaderProvider<  -  $ translateStaticFilesL​​oader 

我如何声明这是一个依赖?我认为这是帕斯卡尔precht.translate的一部分。

解决方案

这包含在文件中也:

angular.module("pascal$p$pcht.translate").factory("$translateStaticFilesLoader",["$q","$http",function(a,b){return功能(C){如果(!c请||!angular.isString(约preFIX)||!angular.isString(c.suffix))抛出新的错误(无法加载的静态文件,没有preFIX或指定的后缀!); VAR D = a.defer();回报b({url:[c.$p$pfix,c.key,c.suffix].join(""),method:"GET",params:""}).success(function(a){d.resolve(a)}).error(function(){d.reject(c.key)}),d.promise}}]);

其重命名为角转换-架静态files.min.js,包括它。

它位于此处的https://github.com/angular-translate/bower-angular-translate-loader-static-files

I'm following this tutorial at ng-newsletter to apply i18n to my app using Angular-Translate. The app works fine when I include the translations within my app.js file, but I'm having trouble getting the StaticFilesLoader to work. This is my app.js file with the working code commented out-

angular.module('myApp',
[
'ngCookies',
'ngRoute',
'ngResource',
'pascalprecht.translate',
'myApp.services',
'myApp.directives',
'myApp.controllers',
]);


angular.module('myApp.services', ['ngResource']);
angular.module('myApp.directives', []);
angular.module('myApp.controllers', []);


angular.module('myApp')
.config(['$httpProvider', '$translateProvider', function($httpProvider, $translateProvider) {
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
console.log($httpProvider.defaults);

/*$translateProvider.translations('en', {
    HEADLINE: 'This is my home page',
    HOME: 'Home',
    SETTINGS: 'Settings',
    LOGOUT: 'Log Out',
    EDIT: 'Edit' ,
    DELETE: 'Delete' ,
    PASSWORD: 'Password' ,
    CONFIRM_PASSWORD: 'Confirm Password' ,
    BUTTON_TEXT_EN: 'english',
    BUTTON_TEXT_DE: 'german'

  })
  .translations('de', {
    HEADLINE: 'Dies ist der Homepage',
    HOME: 'Zuhause',
    SETTINGS: 'Einstellungen',
    LOGOUT: 'Ausloggen',
    EDIT: 'Bearbeiten' ,
    DELETE: 'Löschen' ,
    PASSWORD: 'Passwort' ,
    CONFIRM_PASSWORD: 'Passwort Bestätigen' ,
    BUTTON_TEXT_EN: 'englisch',
    BUTTON_TEXT_DE: 'deutsch'
  }); */

  $translateProvider.preferredLanguage('en');

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

}]);

I've added two files to my app, en.json and de.json and a folder called /languages. When I try to run the application, I get an error saying:

Uncaught Error: [$injector:unpr] Unknown provider: $translateStaticFilesLoaderProvider <- $translateStaticFilesLoader

How do I declare this as a dependency? I thought it was part of pascalprecht.translate.

解决方案

Include this in your file also:

angular.module("pascalprecht.translate").factory("$translateStaticFilesLoader",["$q","$http",function(a,b){return function(c){if(!c||!angular.isString(c.prefix)||!angular.isString(c.suffix))throw new Error("Couldn't load static files, no prefix or suffix specified!");var d=a.defer();return b({url:[c.prefix,c.key,c.suffix].join(""),method:"GET",params:""}).success(function(a){d.resolve(a)}).error(function(){d.reject(c.key)}),d.promise}}]);

Rename it to angular-translate-loader-static-files.min.js and include it.

It's located here: https://github.com/angular-translate/bower-angular-translate-loader-static-files

阅读全文

相关推荐

最新文章