Comments (9)
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.
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.
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.
this approach would be too implicit and confusing IMO.
from react-translate.
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.
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.
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.
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.
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)
- Full usage example? HOT 2
- Issue with Gatsbyjs when building (server side) HOT 4
- Helper to access translations outside components
- PropTypes is undefined HOT 1
- Locale identification and usage HOT 5
- Forwarding refs HOT 1
- Add ability to use ReactElements as variables in translations HOT 3
- Updating translations on the fly HOT 5
- Typo on NPM.com for under yarn add instructions
- Re-using translations HOT 3
- There are peerDependency issues! HOT 1
- react-translate with latest react release
- Can't make this work HOT 1
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 react-translate.