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
Bug(transloco): Can't translate with scope/alias inside a data provider (ResolveFn) #686
Comments
@guillerot I think this is an issue with the But I do agree that the scenario that your provided should work I just think the solution should be related to the scope registration flow, what happens is:
But there is no alias provided since it's resolved at the component level using the ScopeResolver which registers the aliases from the scope provider |
@guillerot After digging into this, there are 2 things that need to be done:
|
@shaharkazaz I would say having a TranslocoService with self-registered scopes could be great (less hackish than scopeMapping managed by user) I didn't go deep into the transloco code.
|
@guillerot The main issue with that suggestion is that it's not the Not sure I understand all your cases, can you share code examples before I respond? just to make sure I understood them correctly 🙂 |
Sorry, I got a bit lost in my suggestions. A (dirty?) solution could be to force set of translation even if cached when the scope is mapped ...
private isMappedScope(scope: string): boolean {
const { scopeMapping = {} } = this.config;
return !!scopeMapping[scope];
}
load(path: string, options: LoadOptions = {}): Observable<Translation> {
const cached = this.cache.get(path);
if (cached) {
const isMappedScope = this._isLangScoped(path) && this.isMappedScope(getScopeFromLang(path));
if(isMappedScope) { // an other condition should be used to avoid setting this translation each time load is called
cached.subscribe((translation) => this.setTranslation(translation, path, { emitChange: false }));
}
return cached;
}
... |
Is there an existing issue for this?
Which Transloco package(s) are the source of the bug?
Transloco
Is this a regression?
Yes
Current behavior
Translating with a scope/alias inside a data provider (https://angular.io/api/router/ResolveFn) can break future translations with same alias
Example, using the data propriver below in
lazy-scope-alias.routes.ts
of transloco-playgroundWill cause
transloco-missing-handler.ts:22 Missing translation for 'myScopeAlias.title'
ℹ️ The issue no longer occurs if scope mapping is provided in transloco config ℹ️
Expected behavior
Translations can still be made after using an alias inside a data provider
Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.
https://codesandbox.io/s/ngneat-transloco-forked-r6fgjs?file=/src/app/lazy-scope-alias/lazy-scope-alias.routes.ts
Transloco Config
No response
Please provide the environment you discovered this bug in
Browser
No response
Additional context
No response
I would like to make a pull request for this bug
No
The text was updated successfully, but these errors were encountered: