ng2-translate

Inject a translated string as an input in an angular 5 component

十年热恋 提交于 2020-03-05 05:07:41
问题 I have an angular component template I want to inject title as an @Input() into, to be displayed as: <div class="title" > {{ title }} </div> How do I inject the translated title into the parent component using ng2-translate's pipe, like so: <title-component [title]="{{ 'KEY' | translate }}" ></title-component> I want to pass the translated string dynamically to the child component, but I'd prefer to avoid injecting the translate service into the component's constructor and keep everything in

Inject a translated string as an input in an angular 5 component

流过昼夜 提交于 2020-03-05 05:07:12
问题 I have an angular component template I want to inject title as an @Input() into, to be displayed as: <div class="title" > {{ title }} </div> How do I inject the translated title into the parent component using ng2-translate's pipe, like so: <title-component [title]="{{ 'KEY' | translate }}" ></title-component> I want to pass the translated string dynamically to the child component, but I'd prefer to avoid injecting the translate service into the component's constructor and keep everything in

VS2015: “Cannot find type definition” and “File not found” errors

a 夏天 提交于 2020-01-05 08:36:14
问题 I have an Angular2 app which worked perfectly fine until two days ago. When I tried to build the solution in Visual Studio 2015, I got 10 errors: Build: Cannot find type definition file for 'hammerjs'. Build: Cannot find type definition file for 'jasmine'. Build: File (...)/wwwroot/lib/ng2-translate/index.ts' not found. And 6 more about various files in ng2-translate not found. Surprisingly, when I build my app by dotnet run command, it works well. I updated everything by npm-check-updates -u

How to update .json file without rebuilding in angular cli?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 10:06:08
问题 I'm using angular cli to build a website which contains multiple languages. I use ng2-translate for the translations. I import a languages.json file defined in angular-cli.json: "assets": [ "assets", "fonts", "languages.json" ], In my controller, I retrieve the data using require: this.languages = require('../../../../languages.json'); Loading the json file works. After deploying, I tried to change (add or remove) some languages in the languages.json, but the changes does not get shown in the

How to trap errors from chained rxjs observables when using combineLatest?

最后都变了- 提交于 2019-12-20 03:40:08
问题 Following on from this post, I have the following Observable.combineLatest( this.translate.get("key1"), this.translate.get(""), this.translate.get("key3"), this.translate.get("key4") ) .subscribe(([result1, result2, result3, result4]) => { console.log(result1); console.log(result2); console.log(result3); console.log(result4); }, error => { console.log(`${error}`); }); At line 2 I get an error, but this does not seem to go into the error handler above. Unfortunately the examples and doco I

ng2-translate customLoader & multiple files per language

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 12:42:41
问题 In an Ionic2 app I'm using ng2-translate the strings in my app. Now I need to split the translation file into several files per language, for example "de.json" and "de_gs1ais.json". As ng2-translate is limited to one file per language I've tried to implement a custom loader: class CustomLoader implements TranslateLoader { private http: Http; public getTranslation(lang: String): Observable<any> { return this.http.get("assets/i18n" + "/" + lang + ".json").map((res) => res.json()); } } This

How to chain calls to ng2-Translate, and rxjs observables in general?

感情迁移 提交于 2019-12-11 03:24:47
问题 I have just started using the ng2 translate in my Ionic 2 (Angular 2) project. I Have found that when I need to get a few strings all at once, the code becomes nested and a lot harder to read. I am sort of wondering why something like this (that just emits a single value) need to use an observable, but perhaps there is a good reason. Anyway... So for example, say I had 4 strings to read at various points in a method let result1: string; let result2: string; let result3: string; let result4:

The pipe 'translate' could not be found , angular2 component testing

被刻印的时光 ゝ 提交于 2019-12-03 23:53:03
问题 I am working on component testing with angular2. in my html template i use the translate pipe. This is the code of the test : import { ComponentFixture, TestBed ,getTestBed} from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; import { RightComponent } from './right.component'; import {TranslateService} from 'ng2-translate/ng2-translate'; import {Injector} from "@angular/core"; let comp: RightComponent; let fixture:

The pipe 'translate' could not be found , angular2 component testing

◇◆丶佛笑我妖孽 提交于 2019-12-01 02:51:10
I am working on component testing with angular2. in my html template i use the translate pipe. This is the code of the test : import { ComponentFixture, TestBed ,getTestBed} from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; import { RightComponent } from './right.component'; import {TranslateService} from 'ng2-translate/ng2-translate'; import {Injector} from "@angular/core"; let comp: RightComponent; let fixture: ComponentFixture<RightComponent>; let el: DebugElement; let translate: TranslateService; let injector:

Angular2 and webpack - i18n plugin vs ng2-translate

。_饼干妹妹 提交于 2019-11-29 22:41:15
I want to build a web-application with angular2 and bundle this with webpack. What is the best way for providing multiple languages: i18n-plugin: https://github.com/webpack/i18n-webpack-plugin or ng2-translate: https://github.com/ocombe/ng2-translate I got it working with webpack using the cookbook. The xliff file has to be converted to ts like so: export const TRANSLATION_SV = `<?xml version="1.0" encoding="UTF-8" ?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template"> <body> <trans-unit id=