Skip to content
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

[Framework] Put i18n logic in place #110

Merged
merged 1 commit into from
Oct 21, 2017
Merged

Conversation

tidoust
Copy link
Member

@tidoust tidoust commented Oct 20, 2017

Overhaul of the JS code to handle localized versions of roadmap documents.

As discussed in #68, the code assumes that the following naming convention is used for all localized files: [name].[lang].[ext]

English versions of the files are assumed to be named: [name].[ext]

To determine the language of the HTML page to render, the code checks the lang attribute on the <html> tag. If it not set, it tries to extract the language from the page name (window.location.pathname), using the above convention. If not set, English (en) is assumed.

The page tries to load localized versions of all files. If not found, it falls back to the English versions. The code issues warnings on the console when it cannot find localized versions of a given file (in some cases, we may not need localized versions, so warnings may not be warranted. However they are useful during development to understand what still needs to be translated).

Files that may (and often should!) be localized are:

  1. toc.json: the labels, descriptions and URLs should be localized
  2. *.html: the actual contents of the roadmap obviously need to be localized. Note the need to update the lang attribute of the <html> tag, otherwise the code will consider that the page is in English.
  3. js/template-table-*.html: the HTML templates used for generated tables. (These templates used to be hardcoded in generate.js)
  4. js/translations.[lang].json: the translations of features, group names, spec titles, and labels that are needed to render the roadmaps. The file is a semi-flat mapping table between the English string and the translated string. First level properties are: "features" for feature names that appear in data files, "groupNames" for translations of group names, "specTitles" for translations of spec titles, "labels" for all other translations.

For instance, the beginning of a js/translations.fr.json document could be:

{
  "labels": {
    "shipped": "C'est en prod!",
    "experimental": "On déboggue",
    "indevelopment": "On y travaille",
    "consideration": "On y réfléchit",
    "N/A": "Non renseigné",
    "in": "dans"
  },
  "features": {
    "audio element": "La balise audio",
    "picture element": "La balise picture"
  },
  "groupNames": {
    "CSS Working Group": "Le groupe de travail CSS"
  },
  "specTitles": {
    "Magnetometer": "Magnétomètre"
  }
}

The overhaul also adds support for merging features in generated tables when they use the same "data-feature", even if they appear in different parts of the documents (#73).

A couple of notes for later:

  • I found it to be a good thing to keep [name].[ext] files for English to be able to continue to use GitHub Pages easily. However, if published as-is, note that this prevents content negotiation (index.html cannot both mean "the localized version for the user" and "the English version"), so we may want to revisit that later on.
  • We'll probably need to extend the translation logic to support some templating mechanism à la "The group %1 developed %2" because different languages may need to introduce terms before/after the "%1" or "%2". I kept things simple for now (but the problem already occurs for the "in" label)

Overhaul of the JS code to handle localized versions of roadmap documents.

As discussed in w3c#68, the code assumes that the following naming convention is
used for all localized files:

 [name].[lang].[ext]

English versions of the files are assumed to be named:

 [name].[ext]

To determine the language of the HTML page to render, the code checks the `lang`
attribute on the `<html>` tag. If it not set, it tries to extract the language
from the page name (`window.location.pathname`), using the above convention. If
if not set, English (`en`) is assumed.

The page tries to load localized versions of all files. If not found, it falls
back to the English versions. The code issues warnings on the console when it
cannot find localized versions of a given file (in some cases, we may not need
localized versions, so warnings may not be warranted. However they are useful
during development to understand what still needs to be translated).

Files that may (and often should!) be localized are:
1. `toc.json`: the labels, descriptions and URLs should be localized
2. `*.html`: the actual contents of the roadmap obviously need to be localized.
Note the need to update the `lang` attribute of the `<html>` tag, otherwise the
code will consider that the page is in English.
3. `js/template-table-*.html`: the HTML templates used for generated tables.
(These templates used to be hardcoded in `generate.js`)
4. `js/translations.[lang].json`: the translations of features, group names,
spec titles, and labels that are needed to render the roadmaps. The file is a
semi-flat mapping table between the English string and the translated string.
First level properties are: "features" for feature names that appear in data
files, "groupNames" for translations of group names, "specTitles" for
translations of spec titles, "labels" for all other translations.

For instance, the beginning of a `js/translations.fr.json` document could be:

```
{
  "labels": {
    "shipped": "C'est en prod!",
    "experimental": "On déboggue",
    "indevelopment": "On y travaille",
    "consideration": "On y réfléchit",
    "N/A": "Non renseigné",
    "in": "dans"
  },
  "features": {
    "audio element": "La balise audio",
    "picture element": "La balise picture"
  },
  "groupNames": {
    "CSS Working Group": "Le groupe de travail CSS"
  },
  "specTitles": {
    "Magnetometer": "Magnétomètre"
  }
}
```

The overhaul also adds support for merging features in generated tables when
they use the same "data-feature", even if they appear in different parts of the
documents (w3c#73).
@tidoust tidoust requested a review from xfq October 20, 2017 20:08
@tidoust tidoust mentioned this pull request Oct 20, 2017
5 tasks
@tidoust
Copy link
Member Author

tidoust commented Oct 20, 2017

Another note for later: there's a little bit of code duplicated between generate-index.js and generate.js. In an ideal world, we would put that code in a separate JS file and use it from the other scripts.

Copy link
Member

@xfq xfq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xfq
Copy link
Member

xfq commented Oct 21, 2017

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants