Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx-translate not parsing subclasses #30

Open
johannks opened this issue Jun 10, 2018 · 8 comments
Open

ngx-translate not parsing subclasses #30

johannks opened this issue Jun 10, 2018 · 8 comments

Comments

@johannks
Copy link

Hello

It seems like ngx-translate doesn't support inheritance.

It doesn't parse a subclass which extends a parent class (with a protected i18n: I18n) unless the subclass has a constructor, re-declares and imports all injectables, and calls super(...).

It's a workaround, but would it be possible to not have to do this?

@FloNeu
Copy link

FloNeu commented Sep 17, 2018

Having similar issue... im importing the the pollyfill in an shared service - but only the classes which directly import the pollyfill get parsed... what's the problem here? Is there a workaround?

@johannks
Copy link
Author

My workaround was to create a constructor in the child, which re-declared and re-imported all injectables. It then only calls super(...) to invoke the parent's constructor.

@timminss
Copy link

Having similar issue... im importing the the pollyfill in an shared service - but only the classes which directly import the pollyfill get parsed... what's the problem here? Is there a workaround?

I'm having the exact same issue. Did you ever come across a solution FloNeu?

@FloNeu
Copy link

FloNeu commented Jun 26, 2019 via email

@timminss
Copy link

Thanks for your reply FloNeu! Would you mind going into a little more detail about your solution if you've got the time?

Is some-component.key.ts a service (only used by 'some-component') which has many hard coded items, and returns the correct one based on a function input?

@FloNeu
Copy link

FloNeu commented Jun 29, 2019

@timminss Hello, sorry - i did forget to come back to this... for example, this is the translation.key.ts file of my login-component ( i exchanged the default '_' methode with 'translation_key' what can be done when calling the parser with -m translation_key parameter ):

@Injectable( { providedIn: 'root' } )
export class FgLoginTranslationKeys {
    public readonly HEADLINE_TAB_LOGIN = translation_key( 'login_headline_tab_login' );
    public readonly HEADLINE_SUB_TAB_LOGIN = translation_key( 'login_headline_sub_tab_login' );
constructor() {}}

then in my component file constructor i import it like this.

class component {
constructor(
 $keys: FgLoginTranslationKeys
) {}}

and then use the key in my template:

<h1>{{ translate( $keys.HEADLINE_TAB_LOGIN ) | async }}</h1>

not that here the translate-methode is a base-component methode i inherit to all my components
which wrapps the ngx-translation-service methode stream ( wich returns new translation when the language is changed ), like:

public translate( key: string ): Observable<any> {
    return this.$component.$translate.stream( key );
  }

and finally the npm-script i use to extract the translation master.json:

"i18n:get-master": "ngx-translate-extract -i ./src -o ./src/assets/i18n/master.json -m translation_key",

Hope that's useful - all the best, Florian

@mickeyjohn
Copy link

mickeyjohn commented Nov 25, 2020

Migrated to Angular 9. Tried migrated i18n to use $localize but It still did not fully work thus I have to revert back. Painful.

Confirmed that the extractor actually does not work on sub classes. Is there any way to force it work?

Please anyone shed me some light !?
Much appreciated in advance.

@mickeyjohn
Copy link

Had to use the workaround as @johannks mentioned before that is injecting i18n:I18n on every component's constructor.

giovannicolacitti pushed a commit to HyperIoT-Labs/HyperIoT-UI that referenced this issue Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants