Comments (12)
I guess it would be better to use "set" yes.
You could also name your languages based on the type of access: "en-a", "en-b" and "en-c" and have 3 different json files for each, but I'm not sure that's better.
You could write your own loader for that as well and use "provide" in bootstrap to provide ng2-translate with your specific static loader, that might work but I haven't test it :)
from core.
Thanks for the library and the feedback
from core.
I'm fine with separate json files per module, actually prefer that.
I ended up just using Http
to load separate language files for each module's route, and adding definitions using TranslateService.set
, so I could hook the loading of the language into a @CanActivate
annotation, to prevent the UI loading and then updating.
A custom loader wouldn't have helped me without also changing what happens inside the TranslateService.getTranslation
to append key:values to the existing definitions for a particular language, or adding a method like getAndAppendTranslations
. I would also need to add a way to check which modules' language files were already loaded so they wouldn't re-fetch every time that route was loaded.
It might be nice to encapsulate all that in this library, but I didn't fork/add it here because I'm not sure how common a use-case that would be?
from core.
To know the loaded langs you can use getLangs()
: Returns an array of currently available langs.
I'm not sure we want to include all of that in the lib right now. Maybe if there really is other people who request it.
I'm glad that you managed to do it, I'm closing this then.
from core.
Sounds good for closing/waiting to evaluate interest. There's a key difference in what I was trying to do, versus what this library seems tooled to handle already though, as illustrated in your comment about getLangs()
This library seems tooled to switch languages for a particular UI at runtime... which seems like kind of a strange use-case to me. I have no interest in changing language at runtime (maybe not even per deployment), but I do want to support code-splitting. (multiple entry-points for a given language.)
I suspect that as web-pack code-splitting becomes more and more 'normal' use-case, this will come back up.
Thanks again for your time 👍
from core.
Yep, that's a good point.
I don't want to fall into complicated code for this lib because the official i18n lib will come soon and I might deprecate this lib by then (unless their implementation is really too complicated or doesn't fit my needs).
from core.
makes sense to me
from core.
@ollwenjones If you have a repo somewhere with an example of what you did to split up language json files for async routes, I would love to have a look at it.
from core.
@nchutchind oh man... that was so long ago and in a private bitbucket repo. I had the PR out and was basically told "let's wait until the official Angular 2 i18n is ready, so we only have to do this once."
I can see if that branch is still alive and maybe make a snippet...
from core.
@nchutchind here is the gist:
https://gist.github.com/ollwenjones/024c16e290637fd23205144f47bd300c
Warning that that branch was abandoned like beta.3, so there's some workarounds in there you don't need.
from core.
@ollwenjones Thank you for that. I was actually in the middle of writing a paragraph describing what I thought would be necessary and asking if I was close. With your gist I can see that I was in the right neighborhood, but it will help me nail it down.
Thank you.
from core.
my pleasure. good luck!
from core.
Related Issues (20)
- Print parsing errors to console
- InnerText gets repeated/duplicated when translate directive being used
- Translations mixed in app between two languages.
- How to handle import TranslateModule.forChild in module when moving to standalone components HOT 2
- reuse last loaded loder in standalone component which doesn't load by routes
- setTranslation is confusing the translation
- bump angular 17 HOT 3
- Translation keys are ignored when dot format and nested format are mixed
- How to handle import TranslateModule.forChild in module when creating a standalone component in an NgModule Application HOT 8
- How to use ngx-translate in Angular 17, Knowing that AppModule is not implemented? HOT 2
- Support for Angular v17 HOT 28
- ngx-translate creates billions of tiny files HOT 1
- Using ngx-translate in a standalone component HOT 3
- 'EventEmitter' and 'DefaultLangChangeEvent' is declared but its value is never read.
- Angular 17 SSR. Standalone implementation - NullInjectorError: No provider for _TranslatePipe! HOT 1
- I am trying to add Arabic language. I have configured package correctly but some labels are translated some are not
- Latency when loading the website, because Translation Key appears when user opens our website HOT 1
- Add opption to pass callback in translate pipe
- ncaught SyntaxError: Cannot use import statement outside a module (at scripts.js:16887:1) main.ts:13 Error: Unexpected value 'TranslateModule' imported by the module 'AppModule'. Please add an @NgModule annotation. at verifySemanticsOfNgModuleDef (core.mjs:28868:5) at core.mjs:28878:5 at Array.forEach (<anonymous>) at verifySemanticsOfNgModuleDef (core.mjs:28876:43) at AppModule.get (core.mjs:28833:23) at getInjectorDef (core.mjs:333:1) at walkProviderTree (core.mjs:5550:1) at core.mjs:5500:6 at core.mjs:4701:1 at Array.forEach (<anonymous>)
- Wrong TranslateHttpLoader after upgrade app to Angular 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.