ngx-translate

Update translations in loader of ngx-translate

拥有回忆 提交于 2020-04-11 09:39:06
问题 I am creating a custom Angular ngx-translate Loader which either gets translations from cache or from an API. The point where I am stuck is Case 2 (see code below): Desired procedure: gets translations from cache (sync) returns cached translations (via observer) gets translations from api (async) compares cache and api (finds difference) sends updated version of translations <-- How? This is what I got: getTranslation(lang: string): Observable<any> { return new Observable(observer => { // get

Angular 6 - can't resolve all parameters for AppComponent

前提是你 提交于 2020-01-31 04:44:29
问题 I am trying to build an application with Angular 6 and I am still setting everything up. But it seems there is something wrong with the dependency injection in my app. It cannot resolve any constructor parameter. They all result in Uncaught Error: Can't resolve all parameters for AppComponent: (?). . Even a custom service results in the same error. Versions (omitted the dependencies that can't have any influence on this) "dependencies": { "@angular/common": "6.0.5", "@angular/compiler": "6.0

Angular 7 i18n translation inside service, component and without template

北城以北 提交于 2020-01-13 17:14:12
问题 I am trying to migrate from ngx-translate to Angular i18n approach and wanted to make sure a few points before migration. Is it possible to translate inside the service and component without any template? In ngx-translate it was possible using translate pipe. Is there any approach which angular has introduced for V7 or planning to introduce in v8 for translating inside component and service level? Is this currently only possible using workaround and there is no angular way to do it? If yes,

Angular 7 i18n translation inside service, component and without template

纵然是瞬间 提交于 2020-01-13 17:13:13
问题 I am trying to migrate from ngx-translate to Angular i18n approach and wanted to make sure a few points before migration. Is it possible to translate inside the service and component without any template? In ngx-translate it was possible using translate pipe. Is there any approach which angular has introduced for V7 or planning to introduce in v8 for translating inside component and service level? Is this currently only possible using workaround and there is no angular way to do it? If yes,

Translations based on specific keys in custom JSON files and business cases with ngx-translate (Angular 7)

被刻印的时光 ゝ 提交于 2020-01-06 07:14:18
问题 I have a working implementation of the ngx-translate library for Angular, based on several .json files (for example, stored in assets/i18n/en.json ). I want to achieve the following: There is always a default JSON (for example de.json ) and additionally always specific JSON files (for example de_specific.json ) that only contain specific translations using the same keys as the respective default JSON. If there is e.g. a translation in the default de.json with "Home": "Startseite" , then the

ngx/translate - translate only part of a string

橙三吉。 提交于 2020-01-02 08:19:12
问题 I need to translate strings coming from a server using ngx/translate. It works fine when i need to translate a string but in some case i need to translate only part of the string. For example: 'hello Shay' or 'hello John' And i need to translate only 'hello' and leave the name as is. I tried: this.i18n.instant('hello {Shay}') and in the en.json file: "hello {var}": "Hello {var}" but with no success. Any Ideas how it can be done? 回答1: You are looking for parametrized translations. You do not

Ionic3 / Ngx-translate - TranslateHttpLoader with external URL

谁说胖子不能爱 提交于 2019-12-30 07:02:43
问题 I'm loading the translation files from the server using TranslateHttpLoader in my app.module.ts like this: export function createTranslateLoader(http: Http) { return new TranslateHttpLoader(http, AppConfig.API_URL+'/static/i18n/', '.json'); } @NgModule({ ... imports: [ TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: (createTranslateLoader), deps: [Http] } }), ], ... }) Everything works fine, but i'm wondering if there is a way to catch event when the loader fails to

How to populate the array for a dropdown where values are externalized already [Angular]

爷,独闯天下 提交于 2019-12-25 01:13:28
问题 I think I haven't understood externalizing concepts very well. I have a simple Dropdown whose options are stored in the corresponding typescript file. HTML <select> <option *ngFor="let source of modeOptions" [value]="source"> {{ source }} </option> </select> typescript modeOptions= ['Calendar year', 'Current quarter', 'Rolling year']; But now I've decided to externalize all the values. en-Us.json { "Modes": { "CalendarYear": "Calendar year", "YearToDate": "Year-to-date", "Rolling12Months":

i18n in datePipe Angular

一世执手 提交于 2019-12-23 04:19:10
问题 I have an application that it's running in two language ( i can change an choose the language i want bu using i18n) English / French. At the moment i can get the date only in english even if i select the French Language. <div class="information"> {{ information.date | information:'EEEE'}} {{information.date | date:'d'}} {{ information.date | date:'MMMM'}} {{ information.date | date:'yyyy'}} </div> At the moment i get it like this Monday 17 August 2018, i want to get the french one too Lundi

put new line in string to translate

北慕城南 提交于 2019-12-22 06:48:22
问题 I'm using ngx-translate. How can I put a line break in a string to translate ? In my template I have : {{'STRING_TO_TRANSLATE' | translate}} In my en.json: { "STRING_TO_TRANSLATE": "text on first line. <br> or \n don't work. Text on second line" } 回答1: It works! But instead of {{'STRING_TO_TRANSLATE' | translate}} You should do <div [innerHTML]="'STRING_TO_TRANSLATE' | translate"></div> <br/>s should work just fine, but in other cases you may need some additional 'safe html pipe', i.e: import