Replies: 1 comment
-
In another attempt to try and understand how the signal api is working, i configured the project so that the asset directory after build will look like this:
So now, the translation of the app is located in
@Component({
selector: 'app-root',
imports: [],
templateUrl: 'app.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
text1 = translateSignal('hello');
text2 = translateSignal('greet', { name: 'Hans' });
text3 = translateSignal('hello', {}, { scope: 'lib-A' });
text4 = translateSignal('greet', { name: 'Hans' }, { scope: 'lib-A' });
}
<p>core: {{ text1() }}</p> <-- results in text1() = world
<p>core: {{ text2() }}</p> <-- results in text2() = hello Hans
<p>lib-A: {{ text3() }}</p> <-- results in text1() = world lib-A
<p>lib-A: {{ text4() }}</p> <-- results in text2() = hello Hans lib-A Now im really confused, why text1 and text2 load the translation from the scope |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, so im trying to figure out transloco's signal api and it mostly seems to make sense to me.
One thing is unclear to me though.
Im using an NX monorepo, have a frontend app and some frontend libraries.
The project structure looks something like this:
Content of
apps/frontend/src/assets/i18n/en.json
:Content of
libs/frontend/lib-A/src/assets/i18n/en.json
:Content of
transloco-loader.service.ts
:Content of
app.component.ts
:Content of
app.component.html
:As you can see from the app.component.ts, only the translation key 'hello' is used here, which lets suggest, that the returned translation is always the one from the
apps/frontend/src/assets/i18n/en.json
.It is getting odd, when using
provideTranslocoScope({ scope: 'lib-A' })
in the app.config.ts now, which looks like this:As you can see, i use provideTransloco as described in the documentation. Additionally, to provide the translations from lib-A in the
app.component.ts/html
i use provideTranslocoScope, which is working fine and the translations are successfully loaded.What is odd now is, that i would expect the translateSignal, to return the string
world
, because no scope was provided.But what it actually returns is
world lib-A
.So even though there is no
lib-A
scope provided withintranslateSignal('hello')
i get the value from the lib-A translation file.There seems to be no way of explicitly stating "do not use a scope here", so Im wondering if im using the translateSignal wrong or if this is an actual bug / unintended behavior of the translateSignal api.
When i do not provide a scope for the translateSignal function, i would expect it to grab the translation from the unscoped translation file and have it return
world
. Only if i specifically set the scope tolib-A
like thistranslateSignal('hello', {}, {scope: 'lib-A'})
i would expect to getworld lib-A
returned.I try to reproduce the issue in a Stackblitz example. But maybe someone else already experienced that issue?
Beta Was this translation helpful? Give feedback.
All reactions