Git Product home page Git Product logo

Comments (12)

ocombe avatar ocombe commented on May 21, 2024

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.

ollwenjones avatar ollwenjones commented on May 21, 2024

Thanks for the library and the feedback

from core.

ollwenjones avatar ollwenjones commented on May 21, 2024

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.

ocombe avatar ocombe commented on May 21, 2024

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.

ollwenjones avatar ollwenjones commented on May 21, 2024

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.

ocombe avatar ocombe commented on May 21, 2024

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.

ollwenjones avatar ollwenjones commented on May 21, 2024

makes sense to me

from core.

nchutchind avatar nchutchind commented on May 21, 2024

@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.

ollwenjones avatar ollwenjones commented on May 21, 2024

@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.

ollwenjones avatar ollwenjones commented on May 21, 2024

@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.

nchutchind avatar nchutchind commented on May 21, 2024

@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.

ollwenjones avatar ollwenjones commented on May 21, 2024

my pleasure. good luck!

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.