Giter VIP home page Giter VIP logo

Comments (9)

Bertg avatar Bertg commented on August 10, 2024 1

Hey @lloydwatkin This is exactly what we have settled on in our internal translator.
We did not use this lib, and went for a different approach, but that is exactly what our method signatures now look like.

Internally when the translate function is called, it fetches each of the "shared" translations and merges those objects. This is then passed to the translator.

from react-translate.

bloodyowl avatar bloodyowl commented on August 10, 2024

this is possible, although this can be a breaking change in the current state of it (you can put . in your keys already), if I introduce this, it would likely be with translate()(Component) (with no argument). would this be solving your use-case?

from react-translate.

alexbardas avatar alexbardas commented on August 10, 2024

It can also be implemented as a non breaking change, but you may not want to do it like this if you consider it would be too confusing.

Consider you have the key form.cancel. If there is no match in the initial Component dictionary and the key has at least one ., then check if key.split('.')[0] is in the dict and its value is an object instead of a string.

from react-translate.

bloodyowl avatar bloodyowl commented on August 10, 2024

this approach would be too implicit and confusing IMO.

from react-translate.

Bertg avatar Bertg commented on August 10, 2024

We are working on some namespace system as well. However we don't think namespacing is a component issue; but a translator issue.

We are doing this for the translate method:

translate("Header", "Ui")(Header)

Where Ui is a fallback namespace for the keys to be looked into. We are also using a "global" fallback. So a translations like this: t('Menu') would be sought for in Header.Menu, Ui.Menu and global.Menu. A final fallback is to return the Key itself.

Maybe this can be implemented?

from react-translate.

lloydwatkin avatar lloydwatkin commented on August 10, 2024

I'd be looking to do something like this, I'd refer to them as 'shared' translations, my example would be:

translate([ 'Header', 'MenuItems' ])(Header)
/* ..and... */
translate([ 'Footer', 'MenuItems' ])(Footer)

from react-translate.

lloydwatkin avatar lloydwatkin commented on August 10, 2024

Would this work for you @bloodyowl, there wouldn't be a BC break since one is a string and the other an array?

from react-translate.

beau6183 avatar beau6183 commented on August 10, 2024

#12

That PR accomplishes the original ask as:

t('form')['cancel']

However, it does not support pluralization or string expansion in that usage.

from react-translate.

lloydwatkin avatar lloydwatkin commented on August 10, 2024

Getting to the point where I require this functionality so have implemented here #13, does not break existing implementations and supports all required features.

from react-translate.

Related Issues (14)

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.