-
Notifications
You must be signed in to change notification settings - Fork 194
[Discussion] Localization for Schemas #256
Comments
Good foresight. Immediate thoughts: IIRC, those strings are rendered by I would propose that we change the text in the enums from English to id tags, same as the id tags used for strings throughout the dapp, (e.g. the ids in this Chinese json doc). All languages (including English) are then handled/rendered the same, presumably using something like So the schema would then look something more like:
|
I like that idea @wanderingstan - thanks... The util might work something like this:
So, aside from maintaining the If you agree, I'll close this issue and create another one describing the creation of the util and the conversion of enum English strings to IDs |
Two follow up questions: Do we need a separate And are you proposing that we would loop over the schema json and do our own id-to-translation substitution before passing it into |
Well, we need a However, your comment about Using the
Which would render a
We could then write a util similar to the one I mentioned above that pairs Before passing the schema into
This would mean that we'd store the ID (not localized text) in IPFS, which we could then convert to a localized string when we render the listing card in the DApp. Whatchathinkaboutthat? |
Great find on the "Custom labels for enum fields"! Am I understanding correctly that with this, we definitely don't need any changes in
This is definitely what we want to be storing in the IPFS json, not a human-language string.
Ah, is the
I'm a little confused about "sending" to react-intl. When the util is processing the schema json in preparation for react-jsonschema-form, couldn't it use a function like Sorry this is a bit scattered. Correct me if I'm wrong. I'm imagining the (possible) steps as:
This will cause our English text to get extracted. Thus we will end up with translations in the the
The
|
Yes, you've got it exactly, with one small caveat... Instead of building a component that never renders, we can use the
So, there will actually need to be three utils, which I wasn't clear about before:
|
Ah ha! It's all clicking now! Didn't realize that Sorry for the derail, and thanks for the lesson in One thought: Seems this utility would be of use to lots of other people; anyone using EDIT: Relevant thread - rjsf-team/react-jsonschema-form#739 The |
That's a great idea 💯 I think our NPM package would be named something like It could have two methods to start with:
Also, we could let all of the relevant |
Nice! Rather than functions, could we just wrap the Form component with our own, eg FormIntl? Eg:
Then all the magic of translating the enunNames happens behind the scenes. They would just have to do their own |
That's a cool idea. I think the two functions I mentioned above would still be valuable though, because the work of extracting the messages from the schema is a bit complex, and so is translating the enum names "in-place" in the But yes, it would be nice to offer a way to do it via react component that wraps the |
oof... I was so focused on enums that I forgot about the need to translate the other form field types... For normal (non-enum) schema objects, like the ones used to generate form fields, I think the best way to localize them might be to replace the So instead of a text field for a location looking like this:
It would look like this:
We could then extract those messages with the utility functions described above so they can be translated and included in Thoughts on this @wanderingstan ? |
It seems a little odd to me that the You've read more on this than me: has really no one encountered this before? It seems a major oversight of the jsonschema people that they would just have people put raw English (or whatever) into the schema, not thinking of translations. I wonder if there is (or should be?) some convention to indicate "hey, this is an id of a string, not an actual human language string!". E.g.
to use the over-used @ sign! |
@wanderingstan Unfortunately, there doesn't seem to be a consensus among json-schema folks about how to localize strings in schemas. There's a whole other concept in
What I'm suggesting is that we store english strings in json-schema to serve as the defaultMessage for both enums and form field labels. I know that seems janky, but the those defaultMessage (english) strings have to be stored somewhere and if we don't store them in the schema, all developers have to know to edit two different files when they add something to a schema (the schema plus some kind of key/val map to link IDs with their defaultMessage) So I think it makes sense to put both ID and defaultMessage in the schema so all the data is in one place and obvious to all devs how to add/edit a schema. But open to suggestions. |
Hmm..we're wading into heavy territory here! If these schemas are to represent a standard, the purist in me says English really doesn't belong there—this is supposed to be just the schema for data. If someone in France decides to extend the schema, would they also be required to put the I don't care super strongly as I'm sure we'll iterate on this a lot more times, but my gut is to just put the "pure" IDs in the schema, and have the translation logic and mappings live outside. (Another thought: |
Ok, fair enough. I'll split out the mapping of So it would be structured something like: schemas Sound good? |
Yes, LGTM! |
Created #258 to track the work that was discussed here |
@joshfraser : would love a lookover of our localization strategy here as our listing schemas will be one of the biggest "interfaces" to Origin for the developer community. Essentially, I steered @jordajm toward completely exorcising English from our schemas, leaving only ID's whose translations are defined elsewhere. E.g. instead of having |
@wanderingstan you have more experience dealing with localization issues than I do. This seems reasonable and I trust you if you think this is the way to go. One question - Is there a reason we can't use "Airplane Rentals" as the key? A developer shouldn't have to think about localization stuff at all to get their custom "hello world" marketplace up and running. From my limited experience with localization, it seems pretty common to just use the English string as the lookup key instead of introducing a separate lookup key. |
@joshfraser - More research shows that even the JSON schema community is unsure on this! The last three comments on the localization thread (from Dec 2016!) are from JSON schema contributors who conclude that the standard is not clear: @jordajm 's implementation of english-less ID's is working right now, so I say we go with it for now. But I agree it might make sense to use english text as the keys in this case to enable the "hello world" marketplace to be as easy as possible. |
Uh oh!
There was an error while loading. Please reload this page.
The problem
We currently have a
category
object in each schema with anenum
array similar to this:The problem is that those enums are in English, and since they are in the schema instead of the React code, they don't fit easily into the
react-intl
patterns we're using throughout the rest of the app.This is a common problem and it has been a regular topic of discussion among
json-schema
contributors.The general consensus is that UI-specific elements like translated strings shouldn't be mixed into
json-schema
JSON documents, so we should probably come up with a solution for this in the React layer.Proposed Solution
I propose building a util file in
src/utils/
that will provide a translation of each enum that is available in a schema. This util can be used by any component to render a translated string representing any enum.It would work similarly to other places in the app where we use translated strings in plain JavaScript (as opposed to JSX) - For example, https://github.com/OriginProtocol/demo-dapp/blob/develop/src/components/listing-create.js#L34-L59
Those strings would then be translated along with all of the other strings and made available for consumption by components.
The text was updated successfully, but these errors were encountered: