-
-
Notifications
You must be signed in to change notification settings - Fork 108
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 #2
Comments
Inheriting from a none-base component has implications for testing, code sharing and readability. So does using Translation is an edge-case as far as most development and maintenance efforts are concerned (aside from wrapping all strings in What about something like initializing |
Thanks for the feedback! I agree wholeheartedly. Class inheritance is unequivocally bad and context is basically global variables. Unfortunately, I'm somewhat far down the path of using both due to the fact that we're using JSX directly to create the interface. That makes minimizing the wires that need to be hooked up to every field somewhat desirable. The one alternative would be trickling some central object all the way through (sorta like I initially did precisely |
I've been thinking about this, and I think maybe the right answer is somewhere between the two. I'm going to look at using some higher order components (à la redux |
In the case of a dictionary is it worse to pass around a global singleton via requires? It's almost like a constant? |
I would tend to think that yes, it's worse. It's almost a constant, but that would make it for example, actually impossible to show two editors in two different languages on the same page. I can't come up with a good use case for why you'd want to do that (apart from comparing/testing/debugging), but the actual inability indicates to me unnecessary use of global state. For this editor (and for the connection to its plot, in particular), I've been operating under the assumption that global state is 100% prohibited. |
Yes true. The tradeoffs in a library are different from an end-user application. Ok, thanks for hearing out my concerns! |
Likewise! I really appreciate the feedback. I'm reworking some pieces a bit to make it a bit more predictable/maintainable. Instead of this: class RangeInput extends BaseField { } it'll be: class RangeInput extends Component { }
export default connectEditorField(RangeInput) That might do some context magic to expose the equivalent of the workspace plot and provide things like the Or even: export default localize(connectEditorField(RangeInput)) (FWIW how do you think redux does it? 😛) |
Oh ya for sure and React Router. They are both a PITA to unit test. But whaddyagonnado |
Have had some talks with @bpostlethwaite and @alexcjohnson. Here are some takeaways: React
I18n
|
A few comments:
So maybe
Great idea. I'd vote for putting the dictionaries in |
Thanks for the feedback! |
I'd keep it flat |
Ohh, lib, not src. Of course. Lots of files in a flat directory. Agreed. |
this is complete |
Opening this for a discussion of i18n, both for this and for the public plotly.js repo.
There are a few different ways to accomplish this. In semi-pseudocode, the i18n function fundamentally looks like:
The input is the string itself, which has pros and cons. The dictionary looks like:
You'd use this like:
The downside is that "Trace" (nominative) and "Trace" (accusative) have different translations in some languages. If this were the case, you could be more explicit and make nontrivial use of an english dictionary to use keys instead of the strings themselves.
Or maybe
panels.style.trace
or whatever you prefer. It's a bit free-form.At any rate, you'd pass in a dictionary which would get deep-merged into whatever default dictionaries plotly.js has built in. The fallback is builtin dictionary values or just a pass-through i18n function.
For plotly, the dictionary would be passed through config as, e.g.
{"es": {...}}
and the desired language would be specified as, e.g"language": "es"
. As in:(
locale
instead oflanguage
?dictionaries
, plural? I at least like the idea of being able to pass multiple dictionaries in one parameter so that changing the language would be possible.)For plotly.js it could also be possible to use
Plotly.Register
. As in:For react components, the editor would probably receive a dictionary and expose it through context. All components would inherit from a base component that makes the dictionary available so that it's not global and so that the dictionary doesn't need to trickle down through props explicitly. Then instead of importing
_
, you'd inherit from the base component and havethis._(...)
automatically available./cc @bpostlethwaite @alexcjohnson @etpinard
The text was updated successfully, but these errors were encountered: