angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

Angular 2 support

Open truongsinh opened this issue 8 years ago • 18 comments

Do you plan to support angular 2 natively?

truongsinh avatar Feb 18 '16 06:02 truongsinh

Angular 2 is a completely different framework so there's little code we'll be able to take along.

There are also plans by the Angular team to integrate a po-file based translation system, so it might be supported out of the box.

I'm currently waiting to see what will happen.

rubenv avatar Feb 18 '16 06:02 rubenv

There are also plans by the Angular team to integrate a po-file based translation system

Wow I never know that, can you give me the reference? So far I believe they only work with ICU format

truongsinh avatar Feb 18 '16 06:02 truongsinh

@truongsinh https://github.com/angular/i18n is the repository you're looking for Edit: it's in the angular/angular main repository now I believe

intellix avatar Feb 18 '16 20:02 intellix

Any update on your Angular2 plans?

john-k-rice avatar Jul 26 '16 19:07 john-k-rice

Now Angular 2.0 final is out since yesterday we're starting to see some of the specifications settle down.

Below is a link to a basic Angular 2 i18n example (though still written for Angular RC6 - a month ago or so) https://github.com/StephenFluin/i18n-sample

To scrape translations from your templates you should use the ng-xi18n cli tool that's bundled with the Angular compiler tool (ngc). Note that although Angular 2 is final lots of it's side projects (like Angular CLI) are still in Beta and under development.

Also note that right now gettext .po files are not supported yet (only XLIFF and XMB if I'm not mistaken)

wizardofjoz avatar Sep 16 '16 12:09 wizardofjoz

@wizardofjoz Thanks for the pointers, I'm sure many of the angular-gettext users are very interested in where to go from here.

I noticed that the most simple form of Angular 2 i18n is this: <h2 i18n>Attribute sample</h2>, which will feel very familiar to angular-gettext users.

This is the same sweet spot I was looking for with angular-gettext. The exact implementation in Angular 2 is (obviously) very different but what matters the most, the developer experience, is the same sweet simplicity.

I for one would thus recommend anyone to look into the built-in i18n support in Angular 2. I won't be updating angular-gettext to an Angular 2 version: that's simply not needed.

It's certainly not the case, but I'd love to believe that angular-gettext showed the Angular 2 developers what was possible for i18n and helped guide the concepts. Thanks to everyone who helped out!

rubenv avatar Sep 16 '16 15:09 rubenv

@rubenv The Angular i18n team did know about angular-gettext and had a look. Proof of which can be found on the team's draft document "Angular and the internationalization: The New World" https://docs.google.com/document/d/1mwyOFsAD-bPoXTk3Hthq0CAcGXCUw-BtTJMR4nGTY-0/edit#heading=h.ixg45w3363q (some people pointed to Angular-gettext in the remarks)

wizardofjoz avatar Sep 16 '16 15:09 wizardofjoz

I have all my strings written in a single service (no text is written in the html only variables). Is there a gettext service I can use with angular 2 until the following issue is fixed (which is externally basic IMHO for toasting messages from components): https://github.com/angular/angular/issues/11405 My code can be seen here: https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.Web/wwwroot/services/ResourcesService.ts

HarelM avatar Apr 29 '17 09:04 HarelM

News? I don't see the approach inc;uded in Angular.io

quedicesebas avatar Jun 21 '17 21:06 quedicesebas

I found it https://angular.io/guide/i18n but it can't be used with Ionic! :( instead ngx-translate, but is to bad, not like get-text

quedicesebas avatar Jun 21 '17 22:06 quedicesebas

@sebrojas14 i18n is as good as gettext, except the fact there are a few issues if you are working with sass instead of css which I'm trying to fix right now. But the most annoying thing of i18n is thar are no good editors like POEdit for xlf files.

dgroh avatar Jun 22 '17 17:06 dgroh

I ended up writing a simple injectable angular gettext catalog service for my site in order to facilitate for some of the functionality of get text. The following is the service: https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.Web/sources/application/services/GetTextCatalogService.ts It's pretty simple but does what I need since all of the text is currently in one location in my app, here: https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.Web/sources/application/services/ResourcesService.ts Hope this can help anyone who's interested.

HarelM avatar Jun 22 '17 18:06 HarelM

@sebrojas14 What are the issues do you have with Ionic? I have purchased below project.He did it using i18n and Ionic 3.But still, I didn't explore it yet.Hope no problem with Ionic and i18n.

Ionic 3 + Angular 4 + i18n Full App

Sampath-Lokuge avatar Jun 26 '17 10:06 Sampath-Lokuge

But the most annoying thing of i18n is thar are no good editors like POEdit for xlf files.

Poedit developer here. I plan to add XLIFF (and angular-gettext…) support, if you would find it useful, please feel free to thumbs-up this issue: https://github.com/vslavik/poedit/issues/408

EDIT: Poedit 2.2 has XLIFF support and Angular files were a specific focus.

vslavik avatar Jun 28 '17 17:06 vslavik

I found below library which seems to be good fit for ng2 translation solution because it uses a gettext format, supports an interpolation param and extractor tool. https://github.com/ngx-translate/core

mamsori avatar Oct 02 '17 20:10 mamsori

@mamsori that its the one recommended by Ionic, but definitly is not like gettext, with that library you have to use keys

quedicesebas avatar Oct 06 '17 06:10 quedicesebas

@sebrojas14 any luck here? I'm was trying to use ngx-translate and just realized that we have to use keys there..:/ found any alternative?

confraria avatar Jun 01 '18 10:06 confraria

As mentioned earlier, I have implemented a simple gettext catalog here - the previous link is dead, it serves most of my needs. https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.Web/sources/application/services/gettext-catalog.service.ts

import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";

@Injectable()
export class GetTextCatalogService {

    private strings: {};
    private baseLanguage: string;

    constructor(private readonly httpClient: HttpClient) {
        this.strings = {};
    }

    public setCurrentLanguage(lang: string): void {
        this.baseLanguage = lang;
    }

    public getCurrentLanguage(): string {
        return this.baseLanguage;
    }

    public getString(word: string, scope?: any, context?: string): string {
        return this.strings[word] as string || word || "";
    }

    public async loadRemote(url: string): Promise<any> {
        let response = await this.httpClient.get(url).toPromise();
        this.strings = response[this.getCurrentLanguage()];
    }
}

HarelM avatar Jun 02 '18 19:06 HarelM