Skip to content

Commit

Permalink
Merge pull request #1303 from nextstrain/json-lang
Browse files Browse the repository at this point in the history
Allow JSONs to define language
  • Loading branch information
jameshadfield authored Mar 10, 2021
2 parents 7933f73 + b8124ec commit fe167e3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/advanced-functionality/view-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For instance, if you set `display_defaults.color_by` to `country`, but load the
| `branch_label` | Which set of branch labels are to be displayed | "aa", "lineage" |
| `panels` | List of panels which (if available) are to be displayed | ["tree", "map"] |
| `transmission_lines`| Should transmission lines (if available) be rendered on the map? | Boolean |

| `language` | Language to display Auspice in | "ja" |

Note that `meta.display_defaults.panels` (optional) differs from `meta.panels` (required), where the latter lists the possible panels that auspice may display for the dataset.
See the [JSON schema](https://github.com/nextstrain/augur/blob/master/augur/data/schema-export-v2.json) for more details.
Expand Down
1 change: 1 addition & 0 deletions src/actions/recomputeReduxState.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ const createMetadataStateFromJSON = (json) => {
branch_label: "selectedBranchLabel",
map_triplicate: "mapTriplicate",
layout: "layout",
language: "language",
sidebar: "sidebar",
panels: "panels",
transmission_lines: "showTransmissionLines"
Expand Down
8 changes: 6 additions & 2 deletions src/components/controls/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class Language extends React.Component {
async ensureLanguageResources(lang) {
for (const ns of ["language", "sidebar", "translation"]) {
if (!i18n.hasResourceBundle(lang, ns)) {
const res = await import(/* webpackMode: "lazy-once" */ `../../locales/${lang}/${ns}.json`); // eslint-disable-line
i18n.addResourceBundle(lang, ns, res.default);
try {
const res = await import(/* webpackMode: "lazy-once" */ `../../locales/${lang}/${ns}.json`); // eslint-disable-line
i18n.addResourceBundle(lang, ns, res.default);
} catch (err) {
console.error(`Language ${lang} not found!`);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/reducers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const general = (state = {
return Object.assign({}, state, {
language: action.data
});
case types.CLEAN_START:
const defaultLanguage = action.metadata.displayDefaults["language"] || defaults.language;
return Object.assign({}, state, {
defaults: Object.assign({}, state.defaults, {language: defaultLanguage}),
language: query.lang ? query.lang : defaultLanguage
});
default:
return state;
}
Expand Down

0 comments on commit fe167e3

Please sign in to comment.