-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
i18n: Support changing language inside the app #24549
Comments
The i18n team is already working on it: #16477 |
@HarelM Just out of curiosity - how are you going to create language specific templates in the build step, without creating different versions of your application? Are you talking about dynamic translation? Ngx-translate already has this. For a production application, I'm not sure how you can avoid building separate apps for each language |
@spock123 it's not possible yet, which is why this is a feature request, i.e. a request to provide a feature that doesn't exist yet. And, as I said, the NG team is working on it. So it will be possible to generate a single bundle supporting several languages. |
@jnizet Thanks.. |
There are two different things here:
|
My current solution that I'm using is to place all the text in a service and use it throughout the app: |
@HarelM can I ask why you chose to implement what https://github.com/ngx-translate/core already dos? Just curious (sorry if off topic guys). |
Well, basically when I started my project I used AngularJS and I didn't fancy the fact that I need to define magic IDs for every string that I use (personal preference), instead I use the string itself as the ID (this is how gettext works and one of the reasons I choose it). |
I am having the same issue: One app running on one instance with two domains, AU and NZ. I am looking at this example (https://embed.plnkr.co/lWV4VhzpWYnCXeDBpzsn/) to fetch the locale source file dynamically. |
I used the example mentioned in my previous post, but it didn't completely work because at the moment the I have a different variation of the solution and I would LOVE feedback on how to do it better. Context: we have one app running on one instance, with two domain names pointing to it. In the
Then in my
The bit I am unsure of is the
Then finally the translation provider:
So what I am not a 100% sure of is using that So I ended up extracting the locale before bootstrapping the module. It feels a little bit finicky, so PLEASE suggest how to better this example. edit |
It seems ok for now, if you don't mind using JIT. We should have better tools to detect the locale and lazy load translations at bootstrap for ivy since we will do translations at runtime. |
@ocombe Unfortunately it doesn't work when I build with --prod. Without --prod, the bundle files include the XML, but with the Otherwise I am forced to create to build instances with separate languages :( |
Okay, I figured out running Good enough for now until there is a proper solution in A6. |
what about |
@ocombe Just tried that. With When I run In essence I have 4 options to go with:
|
closing as duplicate (#16477) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
From the documentation:
Expected behavior
I would like to be able to dynamically change the language using i18n tool chain.
What is the motivation / use case for changing the behavior?
A user would like to change the language of the app without a full refresh to preserve current application state, much like other SPA actions.
Can be seen here (right side language button):
https://israelhiking.osm.org.il/
The above site that I created is using gettext which is an awesome tool but is not the angular team's choice and I prefer to use maintained tools and not deprecated ones.
Gettext can use a json file that was compiled from translations pot file and served as a static file to facilitate language changes.
IMHO, building a separate app for different languages is not the right approach, especially considering how SPA works.
Also #11405 is a key aspect here that can be solved with this approach.
I believe the current solution is not mature enough and I think it's worth considering other requirements.
Environment
The text was updated successfully, but these errors were encountered: