-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Sending translocoService into the missing handler #555
Comments
@AbdealiJK, I now understand why you are using the syntax with the double curly braces jsverse/transloco-keys-manager#130 🙂 |
Hi @shaharkazaz thanks a lot for going through all the 3 issues i raised and understanding them :) The way I generally prefer to use translations is to do:
This is a very simple approach where developers who normally know English can just write the English they expect to be shown. Pros:
Overall. I have found in all my projects using this approach has made a developer's life much much easier. My workflow today is:
The nested keys approach has always given us issues like if I have the same string in 2 places we have duplicated values. Like 'UserEdit.Name' and 'UserLogin.Name' both having the value 'User name'. These are not as easy to track because they will be in different parts of my en.json and developers won't always know they have to make a 'UserCommon.Name'. Bottom line: The approach I described reduces the maintenance work needed to keep translations in projects. I haven't seen any major cons for this approach. |
@AbdealiJK Here is a working example, use the injector since you know that the Transloco service is injected already. |
That's fair - I can dynamically inject it. |
I had the same original issue and used the workaround with dynamic inject. Thanks @AbdealiLoKo and @shaharkazaz for this idea. However, while I was digging in the transloco code, I noticed that the translation object could easily be passed to the missing handler, the same way it is passed to the transpiler here: Having access to translations object, I could just pick the translation using fallback key or fallback second time to an empty string. Note: In my case, we use custom transpiler and UPPER_CASE keys but the fallback keys do not require transpilation nor additional params (maybe yet). |
Is there an existing issue for this?
Which Transloco package(s) will this feature affect?
Transloco
Is your feature request related to a problem? Please describe
I am trying to write a missing key handler which uses my key as the value.
The default behavior currently does not transpile() my variables though.
So, I tried writing a custom missing handler needs to use the
translations
andtranspiler
.This is what I tried:
This gives me a circular DI issue because the missing handler is being used in the TranslocoService.
Describe the solution you'd like
In
ngx-translate
I could do:Similarly, It would be nice to get the
translateService
as a argument into the handle function so we can use it easily.This way I could do
getTranslation()
from the provided translateServiceDescribe alternatives you've considered
Additional context
No response
I would like to make a pull request for this feature
Yes 🚀
The text was updated successfully, but these errors were encountered: