Skip to content

Add en.json generator #803

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

Closed
wants to merge 12 commits into from
Closed

Conversation

yukienomiya
Copy link
Member

@yukienomiya yukienomiya commented Jun 21, 2020

Changes:

  1. Add the getenJSON.js script that extracts the data from the data.json file and automatically generates another JSON file (en.json) containing all the English strings that have to be translated.
  2. Add the en.json file.
    This file could serve both as a template for new translations and as an always up-to-date model to compare the translations with, in order to know when and where they need to be updated.
    • The structure of the en.json is slightly different from the one currently in use (see below), so the other files would have to be modified as well.
    • The en.json file is about x4 times larger than the Spanish version. This is because it contains all the p5.js classes and their related fields/methods.
  3. Add the enJSONStaticStrings.json file that contains static text from the Reference section. These entries are then added at the beginning of the en.json file.
  4. Update the index.hbs file: add the script section that swaps text from class pages of the Reference (it currently only performs the swaps in method/fields pages).

Structure of the en.json file:

image

Structure changes:

  • Description elements: from strings to arrays of strings.
    In the original documentation, the description text is split into paragraphs. This is especially important in long descriptions -Classes' for instance- because it helps with the text's legibility.
    In the translated JSONs the descriptions were saved as single strings and therefore displayed on the website as single paragraphs.
    To fix this, I saved the descriptions as arrays of strings, where each array element represents a paragraph.
  • Parameter elements saved by their name.
    The parameter elements are currently saved in arrays of strings, where each element has a "paramType: paramDescription" structure. They are then inserted in the translated webpage in the order in which they were saved. This is problematic because every little edit on the webpage could mess this order up (here for example, the descriptions of the "colorstring" param and the "a" param are switched).
    To fix this, I saved the "params" elements as object, where each element has a "paramName": "paramType: paramDescription" structure.

The getenJSON script generates the en.json file from the data.json file and the enJSONStaticStrings.json file.
English version of the Reference JSON files.
File containing the static strings of the Reference section that have to be inserted at the beginning of the en.json file.
Change the swapping of the text that has to translated, in order to match the new structure of the Reference JSON file.
Add script section that performs the text swaps in "class" pages of the Reference.
@limzykenneth
Copy link
Member

Can the two JSON files be combined into one? Just to make the process of copying it to create a new language more straightforward.

@yukienomiya
Copy link
Member Author

@limzykenneth I think I explained the enJSONStaticStrings.json file poorly.

I split the en.json into three main sections:

  1. static strings: static text from the Reference section of the website (i.e., the placeholder in the Search bar or the "Parameters" string in methods pages)
  2. module names: for the group and subgroup titles in the Reference's main page
  3. documentation

While the module names and the documentation are extracted from the data.json, the static strings can't be, so I stored them in the enJSONStaticStrings.json to have a place to fetch them when the getenJSON script builds the en.json.
(I guess it would make more sense to save them in the YAML file, but I don't know if that's okay..?)

So, in short, the enJSONStaticStrings.json is only needed for building the en.json, which is the only file that will have to be copied when starting a new translation.

@limzykenneth
Copy link
Member

I see, in that case can the data in enJSONStaticStrings.json be included directly in the code of getenJSON.js?

If I understand correctly the workflow is generate en.json by taking data from data.json and static entries and combine them into en.json; to create a new translation it still is copying en.json and start from there; to update a translation, one would check the latest generated en.json and update the respective language's JSON file. If that is the case and there being not too many entries in enJSONStaticStrings.json nor would it change often, not having it as a seperate file could reduce confusion about what role it plays in the translation process.

@yukienomiya
Copy link
Member Author

I originally included the strings in the getenJSON.js script, but changed it after discussing it with Evelyn. We both agreed it would be cleaner this way. I didn't consider the fact that it could be confusing, to be honest. @outofambit what do you think?

@limzykenneth
Copy link
Member

I guess one of the main reason I find it potentially confusing is because of the name enJSONStaticStrings.json which almost implies there should be esJSONStaticStrings.json, zh-HansJSONStaticStrings.json etc.

@yukienomiya
Copy link
Member Author

I see, maybe just staticStrings.json then? I'm not great at coming up with file names 🙈

@limzykenneth
Copy link
Member

staticStrings.json would be better in this case.

@lmccart
Copy link
Member

lmccart commented Aug 3, 2020

@yukienomiya this is looking great! It seems like there are a few details in your description and the conversation here that are not yet captured in the i18n_contribution.md file yet. I wonder if the "How the website works" section could be updated a bit to include this? Or if this feels too in-depth for this particular section, maybe just a "Notes" section at the end of this page could be useful?

@yukienomiya
Copy link
Member Author

I'm closing this PR because I'm splitting it into two new ones, in order to separate the JSON structure change from the getenJSON script.
@lmccart, thank you 😃 I'll make sure to update the i18n_contribution.md file in the new ones!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants