Skip to content

Commit

Permalink
feat(l10n): refactor the localization code (#296)
Browse files Browse the repository at this point in the history
* 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 #247
Related #234
Fixes #123, Fixes #26
  • Loading branch information
bfabio authored Jan 16, 2024
1 parent ce747d7 commit 17404a9
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 1,097 deletions.
105 changes: 91 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@
"dotenv": "^16.3.1",
"draft-js": "^0.11.7",
"i18next": "^23.2.2",
"i18next-browser-languagedetector": "^7.2.0",
"immutable": "^4.3.0",
"js-yaml": "3.14.0",
"locale-codes": "^1.3.1",
"lodash": "^4.17.21",
"prop-type": "^0.0.1",
"rc-collapse": "^3.7.0",
Expand Down
10 changes: 5 additions & 5 deletions src/app/components/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fragment, useCallback, useEffect, useState } from "react";
import PropTypes from "prop-types";
import Head from "./Head";
import { LanguageSwitcher } from "./LanguageSwitcher";
import { PubliccodeYmlLanguages } from "./PubliccodeYmlLanguages";
import { useAppDispatch, useAppSelector } from "../store";
import EditorForm from "./EditorForm";
import InfoBox from "./InfoBox";
Expand All @@ -27,7 +27,7 @@ import {
toFlatPropertyMap,
transformSimpleStringArrays,
} from "../utils/transform";
import { setLanguages, resetLanguages } from "../store/language";
import { setPubliccodeYmlLanguages, resetPubliccodeYmlLanguages } from "../store/publiccodeYmlLanguages";
import useDebounce from "../hooks/useDebounce";
import { DevTool } from '@hookform/devtools';

Expand Down Expand Up @@ -166,7 +166,7 @@ export const Editor = (props) => {
notify(t("editor.errors.yamlloading"), { state: "error" });
return;
}
dispatch(setLanguages(extractLanguages(data)));
dispatch(setPubliccodeYmlLanguages(extractLanguages(data)));
return data;
};

Expand Down Expand Up @@ -204,7 +204,7 @@ export const Editor = (props) => {
setYaml(null);
clearErrors();
setFlatErrors(null);
dispatch(resetLanguages());
dispatch(resetPubliccodeYmlLanguages());
};

const handleValidationErrors = useCallback((validator) => {
Expand Down Expand Up @@ -276,7 +276,7 @@ export const Editor = (props) => {

<div className="content">
<Head lastGen={lastGen} />
<LanguageSwitcher />
<PubliccodeYmlLanguages />
<div className="content__main" id="content__main">
{blocks && allFields && (
<EditorForm
Expand Down
4 changes: 1 addition & 3 deletions src/app/components/EditorForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const EditorForm = (props) => {
<div>
<FormProvider {...formMethods}>
<form onSubmit={submit}>
{languages && languages.length > 0 ? (
{languages && (
<Collapse
onChange={props.onAccordion}
{...params}
Expand All @@ -139,8 +139,6 @@ const EditorForm = (props) => {
t
)}
/>
) : (
<div>{t("editor.nolanguage")}</div>
)}
</form>
</FormProvider>
Expand Down
63 changes: 0 additions & 63 deletions src/app/components/LanguageSwitcher.tsx

This file was deleted.

Loading

0 comments on commit 17404a9

Please sign in to comment.