ngx-translate-extract
ngx-translate-extract copied to clipboard
Translation keys passed to instant() are missed depending on TranslateService's visibility
Environment
- Angular 9.1.9
-
@biesbjerg/ngx-translate-extract
:7.0.0
Description
When TranslationService
is not called as a public
or private
attribute, arguments passed to instant
are not extracted as translation keys. (I did not test other methods such as get
). It is also ignored when TranslationService
is not directly injected by Angular.
Scenario 1 - visibility readonly
constructor(readonly translate: TranslateService) {}
ngOnInit() {
this.translate.instant("XYZ"); // XYZ is not extracted as a translation key
}
Scenario 2- service passed as an instance to another non-injectable context
@Injectable()
class InjectableService {
private otherService: NonInjectableService;
constructor(private translate: TranslateService) {
this.otherService = new NonInjectableService(translate);
}
ngOnInit() {
this.otherService.foo();
}
}
class NonInjectableService {
constructor(private translate: TranslateService) {}
foo() {
this.translate.instant("XYZ"); // XYZ is not extracted as a translation key
}
}
Workaround
We currently use marker
as a workaround but this makes us miss a lot a translations, especially because we use real english expressions/sentences as translation keys with gettext.
We are having the same issue in a class which inherits from it's parent which has the translateService injected. The keys that are inside the child class are not picked up by extracting the translations.
-
"@biesbjerg/ngx-translate-extract": "^7.0.2"
-
"@biesbjerg/ngx-translate-extract-marker": "^1.0.0"
export abstract class BaseComponent implements AfterContentChecked, OnDestroy {
constructor(
protected translate: TranslateService
) { }
}
export class ChildComponent extends BaseComponent implements OnInit {
constructor(
translate: TranslateService
) {
super(translate);
}
foo() {
this.translate.stream('some.key');
}
}
Is there any workaround to have the translation key extracted, except using the translate marker everywhere? Right now it's easy to forget a translate marker on this.translate.stream/get/instant.
Did anyone found a better workaround than having to use 'marker' everywhere?
There is a fork that fix most of the issue: https://github.com/vendure-ecommerce/ngx-translate-extract Nevertheless, the visibility issue is not fixed. Maybe @michaelbromley can give a hint ?
@dsnoeck Hi, when I created that fork, I decided not to bring over any existing issues, but you are free to create a new issue on that repo if you like.