Skip to content

Commit 17404a9

Browse files
authored
feat(l10n): refactor the localization code (italia#296)
* App localization is now based on the detected language from the browser at runtime * Spell the whole language name in the UI * Change the UI for multiple languages in the publiccode.yml file, removing the tabs * Use a library for the list of languages, so we don't have to maintain our own Obsoletes italia#247 Related italia#234 Fixes italia#123, Fixes italia#26
1 parent ce747d7 commit 17404a9

File tree

17 files changed

+267
-1097
lines changed

17 files changed

+267
-1097
lines changed

package-lock.json

Lines changed: 91 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@
8989
"dotenv": "^16.3.1",
9090
"draft-js": "^0.11.7",
9191
"i18next": "^23.2.2",
92+
"i18next-browser-languagedetector": "^7.2.0",
9293
"immutable": "^4.3.0",
9394
"js-yaml": "3.14.0",
95+
"locale-codes": "^1.3.1",
9496
"lodash": "^4.17.21",
9597
"prop-type": "^0.0.1",
9698
"rc-collapse": "^3.7.0",

src/app/components/Editor.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Fragment, useCallback, useEffect, useState } from "react";
22
import PropTypes from "prop-types";
33
import Head from "./Head";
4-
import { LanguageSwitcher } from "./LanguageSwitcher";
4+
import { PubliccodeYmlLanguages } from "./PubliccodeYmlLanguages";
55
import { useAppDispatch, useAppSelector } from "../store";
66
import EditorForm from "./EditorForm";
77
import InfoBox from "./InfoBox";
@@ -27,7 +27,7 @@ import {
2727
toFlatPropertyMap,
2828
transformSimpleStringArrays,
2929
} from "../utils/transform";
30-
import { setLanguages, resetLanguages } from "../store/language";
30+
import { setPubliccodeYmlLanguages, resetPubliccodeYmlLanguages } from "../store/publiccodeYmlLanguages";
3131
import useDebounce from "../hooks/useDebounce";
3232
import { DevTool } from '@hookform/devtools';
3333

@@ -166,7 +166,7 @@ export const Editor = (props) => {
166166
notify(t("editor.errors.yamlloading"), { state: "error" });
167167
return;
168168
}
169-
dispatch(setLanguages(extractLanguages(data)));
169+
dispatch(setPubliccodeYmlLanguages(extractLanguages(data)));
170170
return data;
171171
};
172172

@@ -204,7 +204,7 @@ export const Editor = (props) => {
204204
setYaml(null);
205205
clearErrors();
206206
setFlatErrors(null);
207-
dispatch(resetLanguages());
207+
dispatch(resetPubliccodeYmlLanguages());
208208
};
209209

210210
const handleValidationErrors = useCallback((validator) => {
@@ -276,7 +276,7 @@ export const Editor = (props) => {
276276

277277
<div className="content">
278278
<Head lastGen={lastGen} />
279-
<LanguageSwitcher />
279+
<PubliccodeYmlLanguages />
280280
<div className="content__main" id="content__main">
281281
{blocks && allFields && (
282282
<EditorForm

src/app/components/EditorForm.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const EditorForm = (props) => {
127127
<div>
128128
<FormProvider {...formMethods}>
129129
<form onSubmit={submit}>
130-
{languages && languages.length > 0 ? (
130+
{languages && (
131131
<Collapse
132132
onChange={props.onAccordion}
133133
{...params}
@@ -139,8 +139,6 @@ const EditorForm = (props) => {
139139
t
140140
)}
141141
/>
142-
) : (
143-
<div>{t("editor.nolanguage")}</div>
144142
)}
145143
</form>
146144
</FormProvider>

src/app/components/LanguageSwitcher.tsx

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)