0

我想在我的 nativescript 应用程序中使用 ngx-translate 实现多语言。我做所有这样的代码(https://nativescript.nl/tips/how-to-create-a-multilingual-nativescript-app-with-angular-4/)。运行 'tns run ios' 时,会出现问题:

这是我的演示代码:

app.module.ts

import { NgModule, NgModuleFactoryLoader, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NSModuleFactoryLoader } from "nativescript-angular/router";
import { NativeScriptFormsModule } from "nativescript-angular/forms";

import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";

import { NativeScriptHttpModule } from "nativescript-angular/http";
import { HttpClient, HttpClientModule } from "@angular/common/http";

import { TranslateModule, TranslateLoader } from "@ngx-translate/core";
import { TranslateHttpLoader } from "@ngx-translate/http-loader";
// import { Http } from "@angular/http";


// for AoT compilation
export function translateLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, "/i18n/", ".json");
};

@NgModule({
    bootstrap: [
        AppComponent
    ],
    imports: [
        NativeScriptModule,
        NativeScriptFormsModule,
        AppRoutingModule,
        NativeScriptHttpModule,
        HttpClientModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                deps: [HttpClient],
                useFactory: (translateLoaderFactory)
            }
        })


    ],
    declarations: [
        AppComponent
    ],
    providers: [
        { provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader },
        HttpClient,
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
export class AppModule { }

app.component.ts

import { Component } from "@angular/core";

// import * as Platform from "platform";
import { TranslateService } from '@ngx-translate/core';

@Component({
    selector: "ns-app",
    templateUrl: "app.component.html"
})
export class AppComponent { 

    constructor(private translate: TranslateService) {

        translate.addLangs(["en", "zh"]);
        translate.setDefaultLang("en");
        // translate.use(Platform.device.language);
    }
}

home.component.html

<GridLayout class="page page-content">
    <Label  [text]="'HOME.TITLE' | translate"></Label>
</GridLayout>

包.json

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.MutilLanguageDemo",
    "tns-ios": {
      "version": "3.3.0"
    }
  },
  "scripts": {
    "lint": "tslint \"app/**/*.ts\""
  },
  "dependencies": {
    "@angular/animations": "4.4.6",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "4.4.6",
    "@angular/platform-browser": "4.4.6",
    "@angular/router": "4.4.6",
    "@ngx-translate/core": "7.2.0",
    "@ngx-translate/http-loader": "^2.0.0",
    "nativescript-angular": "4.4.1",
    "nativescript-theme-core": "1.0.4",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.5.2",
    "tns-core-modules": "3.3.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "codelyzer": "3.2.2",
    "nativescript-dev-sass": "1.3.2",
    "nativescript-dev-typescript": "0.5.1",
    "node-sass": "4.5.3",
    "tslint": "5.8.0",
    "typescript": "2.4.2"
  }
}

错误代码

CONSOLE LOG file:///app/tns_modules/@angular/core/./bundles/core.umd.js:2957:20: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1052:24: ERROR Error: Uncaught (in promise): Error: Template parse errors:
CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1052:24: ERROR Error: Uncaught (in promise): [object Object]

全部,任何建议都非常感谢。谢谢!

4

1 回答 1

0

对不起,错误代码

CONSOLE LOG file:///app/tns_modules/@angular/core/./bundles/core.umd.js:2957:20: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1052:24: ERROR Error: Uncaught (in promise): Error: Template parse errors:
CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1052:24: ERROR Error: Uncaught (in promise): [object Object]

于 2017-12-05T16:13:46.170 回答