Skip to content

Commit

Permalink
refactor(i18n): use one locale file per language
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabio committed Jan 16, 2024
1 parent 17404a9 commit f5350f7
Show file tree
Hide file tree
Showing 7 changed files with 667 additions and 687 deletions.
4 changes: 2 additions & 2 deletions src/app/components/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const InfoBox = ({inputTitle, description}: Props): JSX.Element => {
const dispatch = useAppDispatch();
const { t } = useTranslation();

const translationReadyLabel = t(`pc:${inputTitle}.label`);
const translationReadyLabel = t(`publiccodeyml.${inputTitle}.label`);
// some components use Info to display some constraint
// e.g. max/minLength info
const translationReadyDescription = inputTitle
? t(`pc:${inputTitle.replace(/\[[0-9]+\]/,'')}.description`)
? t(`publiccodeyml.${inputTitle.replace(/\[[0-9]+\]/,'')}.description`)
: description;

const partial = ellipsis(translationReadyDescription);
Expand Down
2 changes: 1 addition & 1 deletion src/app/form/renderField.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const renderField = (
let showLabel = schema.showLabel == false ? false : true;
// label are same for every element of arrays
const translationReadyLabel = t(
`pc:${schema.rawTitle || newFieldName.replace(/\[[0-9]+\]/,'') || schema.title}.label`
`publiccodeyml.${schema.rawTitle || newFieldName.replace(/\[[0-9]+\]/,'') || schema.title}.label`
);

const lbl = translationReadyLabel || schema.title || fieldName;
Expand Down
16 changes: 4 additions & 12 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ import locales from "locale-codes";
import LanguageDetector from 'i18next-browser-languagedetector';

import { FALLBACK_LANGUAGE } from "../app/contents/constants";
import translation from "./translations.json";
import pc from "./publiccode.json";
import en from "./locales/en.json";
import it from "./locales/it.json";

i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
ns: ["translation", "pc"],
defaultNS: "translation",
resources: {
en: {
pc: pc.en.pc,
translation: translation.en.translation,
},
it: {
pc: pc.it.pc,
translation: translation.it.translation,
},
en: { translation: en },
it: { translation: it },
},
supportedLngs: ["en", "it"],
nonExplicitSupportedLngs: true, // make pass eg. "en-US" if "en" is in supportedLngs
Expand Down
330 changes: 330 additions & 0 deletions src/i18n/locales/en.json

Large diffs are not rendered by default.

330 changes: 330 additions & 0 deletions src/i18n/locales/it.json

Large diffs are not rendered by default.

574 changes: 0 additions & 574 deletions src/i18n/publiccode.json

This file was deleted.

98 changes: 0 additions & 98 deletions src/i18n/translations.json

This file was deleted.

0 comments on commit f5350f7

Please sign in to comment.