From eddb335abe4a5d6ab3d29b6d752e5f06110f66d3 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Mon, 25 Nov 2024 19:10:16 +0300 Subject: [PATCH] Update Nuxt i18n (#5176) --- .codespell/ignore_lines.txt | 6 +- .github/workflows/generate_pot.yml | 2 +- frontend/.gitignore | 10 + .../locales/scripts => i18n/data}/en.json5 | 0 .../scripts => i18n}/locale-fallback.json | 8 + frontend/i18n/locales/README.md | 5 + .../{src => i18n}/locales/scripts/README.md | 0 .../{src => i18n}/locales/scripts/axios.js | 2 +- .../locales/scripts/bulk-download.js | 2 +- .../locales/scripts/create-wp-locale-list.js | 2 +- .../scripts/get-translations-status.js | 0 .../locales/scripts/get-translations.js | 6 +- .../locales/scripts/get-validated-locales.js | 8 +- .../locales/scripts/jed1x-json-to-json.js | 0 .../locales/scripts/json-helpers.js | 0 .../locales/scripts/json-pot-helpers.js | 0 .../locales/scripts/json-to-pot.js | 0 .../locales/scripts/ngx-json-to-json.js | 0 .../locales/scripts/parse-vue-files.js | 9 +- .../locales/scripts/read-i18n.js | 5 +- .../{src => i18n}/locales/scripts/types.d.ts | 0 .../{src => i18n}/locales/scripts/utils.js | 2 +- frontend/i18n/vue-i18n.ts | 173 +++++ frontend/nuxt.config.ts | 4 +- frontend/package.json | 16 +- frontend/src/app.vue | 8 +- .../components/VErrorSection/VErrorImage.vue | 4 +- frontend/src/components/VLicense/VLicense.vue | 6 +- .../components/VMediaInfo/VCopyLicense.vue | 4 +- .../components/VMediaInfo/VMediaDetails.vue | 4 +- .../components/VMediaInfo/VMediaLicense.vue | 6 +- .../VMediaInfo/meta/VMetadata.stories.ts | 6 +- .../src/composables/use-collection-meta.ts | 11 +- frontend/src/composables/use-collection.ts | 6 +- frontend/src/error.vue | 8 +- frontend/src/locales/README.md | 6 - frontend/src/pages/image/[id]/report.vue | 4 +- frontend/src/utils/attribution-html.ts | 19 +- frontend/src/utils/license.ts | 13 +- frontend/src/utils/metadata.ts | 25 +- frontend/src/vue-i18n.ts | 39 - frontend/test/README.md | 2 +- frontend/test/playwright/e2e/filters.spec.ts | 2 +- frontend/test/playwright/playwright.config.ts | 2 + frontend/test/playwright/utils/i18n.ts | 2 +- .../unit/specs/utils/attribution-html.spec.ts | 22 +- .../test/unit/specs/utils/license.spec.ts | 4 +- frontend/test/unit/test-utils/i18n.js | 21 - frontend/test/unit/test-utils/i18n.ts | 33 + packages/js/eslint-plugin/src/configs/vue.ts | 19 +- pnpm-lock.yaml | 703 +++++++++++------- 51 files changed, 762 insertions(+), 477 deletions(-) rename frontend/{src/locales/scripts => i18n/data}/en.json5 (100%) rename frontend/{src/locales/scripts => i18n}/locale-fallback.json (50%) create mode 100644 frontend/i18n/locales/README.md rename frontend/{src => i18n}/locales/scripts/README.md (100%) rename frontend/{src => i18n}/locales/scripts/axios.js (65%) rename frontend/{src => i18n}/locales/scripts/bulk-download.js (97%) rename frontend/{src => i18n}/locales/scripts/create-wp-locale-list.js (97%) rename frontend/{src => i18n}/locales/scripts/get-translations-status.js (100%) rename frontend/{src => i18n}/locales/scripts/get-translations.js (89%) rename frontend/{src => i18n}/locales/scripts/get-validated-locales.js (89%) rename frontend/{src => i18n}/locales/scripts/jed1x-json-to-json.js (100%) rename frontend/{src => i18n}/locales/scripts/json-helpers.js (100%) rename frontend/{src => i18n}/locales/scripts/json-pot-helpers.js (100%) rename frontend/{src => i18n}/locales/scripts/json-to-pot.js (100%) rename frontend/{src => i18n}/locales/scripts/ngx-json-to-json.js (100%) rename frontend/{src => i18n}/locales/scripts/parse-vue-files.js (93%) rename frontend/{src => i18n}/locales/scripts/read-i18n.js (98%) rename frontend/{src => i18n}/locales/scripts/types.d.ts (100%) rename frontend/{src => i18n}/locales/scripts/utils.js (98%) create mode 100644 frontend/i18n/vue-i18n.ts delete mode 100644 frontend/src/locales/README.md delete mode 100644 frontend/src/vue-i18n.ts delete mode 100644 frontend/test/unit/test-utils/i18n.js create mode 100644 frontend/test/unit/test-utils/i18n.ts diff --git a/.codespell/ignore_lines.txt b/.codespell/ignore_lines.txt index 2d869403ce2..3b339812842 100644 --- a/.codespell/ignore_lines.txt +++ b/.codespell/ignore_lines.txt @@ -5,7 +5,7 @@ ;; The release-drafter/release-drafter configuration variable name cannot be changed commitish: main -;; frontend/src/locales/scripts/en.json5 +;; frontend/i18n/data/en.json5 ;; Prettier insists we escape a single quote rather than the double quotes and codespell ;; does not understand the escaped `\'t` as "couldn't". It instead just sees "couldn". heading: 'We couldn\'t find anything for "{query}".', @@ -16,7 +16,3 @@ ;; block of Dutch text. "Identificatie Titel(s): Allegorie op kunstenaar Francesco Mazzoli, " "bekend als Parmigianino" - -;; packages/js/eslint-plugin/configs/vue.ts -;; `te` gets matched with `the` and others -const i18nDestructureRules = ["t", "tc", "te", "td", "d", "n"].map( diff --git a/.github/workflows/generate_pot.yml b/.github/workflows/generate_pot.yml index b1af0babeef..88959b87e0e 100644 --- a/.github/workflows/generate_pot.yml +++ b/.github/workflows/generate_pot.yml @@ -4,7 +4,7 @@ on: push: # The workflow will only run when both filters are satisfied. paths: - - frontend/src/locales/scripts/en.json5 + - frontend/i18n/data/en.json5 branches: - main diff --git a/frontend/.gitignore b/frontend/.gitignore index 70ccfce63f2..9acba1eab7a 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -18,6 +18,16 @@ coverage *.pot # Downloaded translation files +i18n/locales/openverse.zip +i18n/locales/*.json +i18n/locales/scripts/valid-locales.json +i18n/locales/scripts/untranslated-locales.json +i18n/locales/scripts/invalid-locales.json +i18n/locales/scripts/wp-locales.json +i18n/data/valid-locales.json +i18n/data/untranslated-locales.json +i18n/locales/scripts/*.json +# The old downloaded translation files. Can be deleted after the i18n folder changes are merged src/locales/openverse.zip src/locales/*.json src/locales/scripts/valid-locales.json diff --git a/frontend/src/locales/scripts/en.json5 b/frontend/i18n/data/en.json5 similarity index 100% rename from frontend/src/locales/scripts/en.json5 rename to frontend/i18n/data/en.json5 diff --git a/frontend/src/locales/scripts/locale-fallback.json b/frontend/i18n/locale-fallback.json similarity index 50% rename from frontend/src/locales/scripts/locale-fallback.json rename to frontend/i18n/locale-fallback.json index 22a1106ea22..cbffbcf0993 100644 --- a/frontend/src/locales/scripts/locale-fallback.json +++ b/frontend/i18n/locale-fallback.json @@ -6,5 +6,13 @@ "es-ec": ["es"], "es-mx": ["es"], "es-ve": ["es"], + "en-au": ["en"], + "en-ca": ["en"], + "en-gb": ["en"], + "en-za": ["en"], + "fa": ["fa-af"], + "fr-be": ["fr"], + "fr-ca": ["fr"], + "pt": ["pt-br"], "default": ["en"] } diff --git a/frontend/i18n/locales/README.md b/frontend/i18n/locales/README.md new file mode 100644 index 00000000000..ae613e25bfb --- /dev/null +++ b/frontend/i18n/locales/README.md @@ -0,0 +1,5 @@ +# Locales + +The primary internationalisation file is [`data/en.json5`](../data/en.json5). +All `.json` files present in this directory are re-generated when updating +translations, so they should not be modified. diff --git a/frontend/src/locales/scripts/README.md b/frontend/i18n/locales/scripts/README.md similarity index 100% rename from frontend/src/locales/scripts/README.md rename to frontend/i18n/locales/scripts/README.md diff --git a/frontend/src/locales/scripts/axios.js b/frontend/i18n/locales/scripts/axios.js similarity index 65% rename from frontend/src/locales/scripts/axios.js rename to frontend/i18n/locales/scripts/axios.js index f92100fca69..7367aa18274 100644 --- a/frontend/src/locales/scripts/axios.js +++ b/frontend/i18n/locales/scripts/axios.js @@ -1,6 +1,6 @@ const axios = require("axios") -const { userAgent } = require("../../constants/user-agent") +const { userAgent } = require("../../../src/constants/user-agent") module.exports = module.exports = axios.create({ headers: { "User-Agent": userAgent }, diff --git a/frontend/src/locales/scripts/bulk-download.js b/frontend/i18n/locales/scripts/bulk-download.js similarity index 97% rename from frontend/src/locales/scripts/bulk-download.js rename to frontend/i18n/locales/scripts/bulk-download.js index 5094b866277..163330366ae 100644 --- a/frontend/src/locales/scripts/bulk-download.js +++ b/frontend/i18n/locales/scripts/bulk-download.js @@ -22,7 +22,7 @@ const fetchBulkJed1x = async () => { params: { "export-format": "jed1x" }, responseType: "stream", }) - const destPath = process.cwd() + "/src/locales/openverse.zip" + const destPath = process.cwd() + "/i18n/locales/openverse.zip" await pipeline(res.data, createWriteStream(destPath)) return destPath } diff --git a/frontend/src/locales/scripts/create-wp-locale-list.js b/frontend/i18n/locales/scripts/create-wp-locale-list.js similarity index 97% rename from frontend/src/locales/scripts/create-wp-locale-list.js rename to frontend/i18n/locales/scripts/create-wp-locale-list.js index 51f4a2bcbb1..32a2426854f 100644 --- a/frontend/src/locales/scripts/create-wp-locale-list.js +++ b/frontend/i18n/locales/scripts/create-wp-locale-list.js @@ -110,7 +110,7 @@ async function getWpLocaleData() { getWpLocaleData() .then((data) => { try { - const fileName = process.cwd() + "/src/locales/scripts/wp-locales.json" + const fileName = process.cwd() + "/i18n/locales/scripts/wp-locales.json" fs.writeFileSync(fileName, JSON.stringify(data, null, 2) + "\n") console.log(`Successfully wrote locales list file to ${fileName}`) } catch (err) { diff --git a/frontend/src/locales/scripts/get-translations-status.js b/frontend/i18n/locales/scripts/get-translations-status.js similarity index 100% rename from frontend/src/locales/scripts/get-translations-status.js rename to frontend/i18n/locales/scripts/get-translations-status.js diff --git a/frontend/src/locales/scripts/get-translations.js b/frontend/i18n/locales/scripts/get-translations.js similarity index 89% rename from frontend/src/locales/scripts/get-translations.js rename to frontend/i18n/locales/scripts/get-translations.js index b731299eb01..c2519114b25 100644 --- a/frontend/src/locales/scripts/get-translations.js +++ b/frontend/i18n/locales/scripts/get-translations.js @@ -16,7 +16,7 @@ const { parseJson } = require("./read-i18n") const writeEnglish = () => { const rootEntry = parseJson("en.json5") writeFileSync( - process.cwd() + "/src/locales/en.json", + process.cwd() + "/i18n/locales/en.json", JSON.stringify(rootEntry, null, 2) + os.EOL ) console.log("Successfully saved English translation to en.json.") @@ -26,7 +26,7 @@ writeEnglish() if (process.argv.includes("--watch")) { console.log("Watching en.json5 for changes...") chokidar - .watch(process.cwd() + "/src/locales/scripts/en.json5") + .watch(process.cwd() + "/i18n/data/en.json5") .on("all", (event, path) => { console.log(`Event '${event}' for file ${path}`) writeEnglish() @@ -46,7 +46,7 @@ if (!process.argv.includes("--en-only")) { } else { // Create valid-locales.json if it doesn't exist. It is required for Nuxt to build the app. const validLocalesFilePath = - process.cwd() + "/src/locales/scripts/valid-locales.json" + process.cwd() + "/i18n/locales/scripts/valid-locales.json" if (!existsSync(validLocalesFilePath)) { writeFileSync(validLocalesFilePath, "[]") console.log("Created empty valid-locales.json.") diff --git a/frontend/src/locales/scripts/get-validated-locales.js b/frontend/i18n/locales/scripts/get-validated-locales.js similarity index 89% rename from frontend/src/locales/scripts/get-validated-locales.js rename to frontend/i18n/locales/scripts/get-validated-locales.js index 23a0c04f343..ec78f100e3d 100644 --- a/frontend/src/locales/scripts/get-validated-locales.js +++ b/frontend/i18n/locales/scripts/get-validated-locales.js @@ -39,7 +39,7 @@ const getValidatedLocales = async () => { translated: locale.translated, })) for (const locale of allLocales) { - const fileLocation = `${process.cwd()}/src/locales/${locale.file}` + const fileLocation = `${process.cwd()}/i18n/locales/${locale.file}` if (fs.existsSync(fileLocation)) { if (Object.keys(JSON.parse(fs.readFileSync(fileLocation))).length) { result.translated.push(locale) @@ -59,7 +59,7 @@ try { const fileName = "valid-locales.json" const valid = locales.translated fs.writeFileSync( - process.cwd() + `/src/locales/scripts/` + fileName, + process.cwd() + `/i18n/locales/scripts/` + fileName, JSON.stringify(valid, null, 2) + "\n" ) @@ -68,14 +68,14 @@ try { ) const untranslatedFileName = "untranslated-locales.json" fs.writeFileSync( - process.cwd() + `/src/locales/scripts/` + untranslatedFileName, + process.cwd() + `/i18n/locales/scripts/` + untranslatedFileName, JSON.stringify(locales.untranslated, null, 2) + "\n" ) console.log(`Found ${locales.invalid.length} invalid locales.`) const invalidFileName = "invalid-locales.json" fs.writeFileSync( - process.cwd() + `/src/locales/scripts/` + invalidFileName, + process.cwd() + `/i18n/locales/scripts/` + invalidFileName, JSON.stringify(locales.invalid, null, 2) + "\n" ) diff --git a/frontend/src/locales/scripts/jed1x-json-to-json.js b/frontend/i18n/locales/scripts/jed1x-json-to-json.js similarity index 100% rename from frontend/src/locales/scripts/jed1x-json-to-json.js rename to frontend/i18n/locales/scripts/jed1x-json-to-json.js diff --git a/frontend/src/locales/scripts/json-helpers.js b/frontend/i18n/locales/scripts/json-helpers.js similarity index 100% rename from frontend/src/locales/scripts/json-helpers.js rename to frontend/i18n/locales/scripts/json-helpers.js diff --git a/frontend/src/locales/scripts/json-pot-helpers.js b/frontend/i18n/locales/scripts/json-pot-helpers.js similarity index 100% rename from frontend/src/locales/scripts/json-pot-helpers.js rename to frontend/i18n/locales/scripts/json-pot-helpers.js diff --git a/frontend/src/locales/scripts/json-to-pot.js b/frontend/i18n/locales/scripts/json-to-pot.js similarity index 100% rename from frontend/src/locales/scripts/json-to-pot.js rename to frontend/i18n/locales/scripts/json-to-pot.js diff --git a/frontend/src/locales/scripts/ngx-json-to-json.js b/frontend/i18n/locales/scripts/ngx-json-to-json.js similarity index 100% rename from frontend/src/locales/scripts/ngx-json-to-json.js rename to frontend/i18n/locales/scripts/ngx-json-to-json.js diff --git a/frontend/src/locales/scripts/parse-vue-files.js b/frontend/i18n/locales/scripts/parse-vue-files.js similarity index 93% rename from frontend/src/locales/scripts/parse-vue-files.js rename to frontend/i18n/locales/scripts/parse-vue-files.js index 191222d0164..7b313fe7336 100644 --- a/frontend/src/locales/scripts/parse-vue-files.js +++ b/frontend/i18n/locales/scripts/parse-vue-files.js @@ -6,7 +6,10 @@ const path = require("path") const glob = require("glob") -const BASE_PATH = path.dirname(path.dirname(__dirname)) +const BASE_PATH = path.join( + path.dirname(path.dirname(path.dirname(__dirname))), + "src" +) function readVueFiles(src) { const targetFiles = glob.sync(src) @@ -14,8 +17,8 @@ function readVueFiles(src) { if (targetFiles.length === 0) { throw new Error("vueFiles glob has no files.") } - // Now that the script are inside `src/locales/scripts`, - // to get relative URL, the script needs to go up 3 levels + // Now that the script are inside `i18n/locales/scripts`, + // to get relative URL, the script needs to go up 4 levels return targetFiles.map((f) => { const fileName = path.relative(process.cwd(), f.replace(BASE_PATH, "src")) return { diff --git a/frontend/src/locales/scripts/read-i18n.js b/frontend/i18n/locales/scripts/read-i18n.js similarity index 98% rename from frontend/src/locales/scripts/read-i18n.js rename to frontend/i18n/locales/scripts/read-i18n.js index 0fa36df7e9c..6e426c8919d 100644 --- a/frontend/src/locales/scripts/read-i18n.js +++ b/frontend/i18n/locales/scripts/read-i18n.js @@ -182,7 +182,10 @@ const parseObjProperty = (node) => { const parseJson = (filename) => parseObjProperty({ value: babel.parseExpression( - fs.readFileSync(path.join(__dirname, filename), "utf-8") + fs.readFileSync( + path.join(__dirname, "..", "..", "data", filename), + "utf-8" + ) ), }) diff --git a/frontend/src/locales/scripts/types.d.ts b/frontend/i18n/locales/scripts/types.d.ts similarity index 100% rename from frontend/src/locales/scripts/types.d.ts rename to frontend/i18n/locales/scripts/types.d.ts diff --git a/frontend/src/locales/scripts/utils.js b/frontend/i18n/locales/scripts/utils.js similarity index 98% rename from frontend/src/locales/scripts/utils.js rename to frontend/i18n/locales/scripts/utils.js index f4fc54aa853..4e18db89396 100644 --- a/frontend/src/locales/scripts/utils.js +++ b/frontend/i18n/locales/scripts/utils.js @@ -139,7 +139,7 @@ exports.writeLocaleFile = (locale, rawTranslations, deprecatedKeys) => { ) return writeFile( - process.cwd() + `/src/locales/${locale}.json`, + process.cwd() + `/i18n/locales/${locale}.json`, JSON.stringify(translations, null, 2) + os.EOL ) } diff --git a/frontend/i18n/vue-i18n.ts b/frontend/i18n/vue-i18n.ts new file mode 100644 index 00000000000..d3029c8643a --- /dev/null +++ b/frontend/i18n/vue-i18n.ts @@ -0,0 +1,173 @@ +import { defineI18nConfig } from "#imports" + +import localeFallback from "./locale-fallback.json" + +import type { Locale } from "@intlify/core-base" + +const custom5Rule = (n: number): number => + n == 0 + ? 0 + : n == 1 + ? 1 + : n == 2 + ? 2 + : n % 100 >= 3 && n % 100 <= 10 + ? 3 + : n % 100 >= 11 && n % 100 <= 99 + ? 4 + : 5 + +export default defineI18nConfig(() => ({ + legacy: false, + globalInjection: true, + fallbackLocale: localeFallback as { [x: string]: Locale[] }, + silentFallbackWarn: true, + pluralizationRules: { + ar: custom5Rule, + arq: custom5Rule, + ary: custom5Rule, + bel: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + bs: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + cor: (n: number): number => + n == 0 + ? 0 + : n == 1 + ? 1 + : n % 100 == 2 || + n % 100 == 22 || + n % 100 == 42 || + n % 100 == 62 || + n % 100 == 82 || + (n % 1000 == 0 && + ((n % 100000 >= 1000 && n % 100000 <= 20000) || + n % 100000 == 40000 || + n % 100000 == 60000 || + n % 100000 == 80000)) || + (n != 0 && n % 1000000 == 100000) + ? 2 + : n % 100 == 3 || + n % 100 == 23 || + n % 100 == 43 || + n % 100 == 63 || + n % 100 == 83 + ? 3 + : n != 1 && + (n % 100 == 1 || + n % 100 == 21 || + n % 100 == 41 || + n % 100 == 61 || + n % 100 == 81) + ? 4 + : 5, + cs: (n: number): number => (n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2), + cy: (n: number): number => + n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3, + dsb: (n: number): number => + n % 100 == 1 + ? 0 + : n % 100 == 2 + ? 1 + : n % 100 == 3 || n % 100 == 4 + ? 2 + : 3, + ga: (n: number): number => + n == 1 + ? 0 + : n == 2 + ? 1 + : n >= 3 && n <= 6 + ? 2 + : n >= 7 && n <= 10 + ? 3 + : 4, + gd: (n: number): number => + n == 1 || n == 11 + ? 0 + : n == 2 || n == 12 + ? 1 + : (n >= 3 && n <= 10) || (n >= 13 && n <= 19) + ? 2 + : 3, + hr: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + hsb: (n: number): number => + n % 100 == 1 + ? 0 + : n % 100 == 2 + ? 1 + : n % 100 == 3 || n % 100 == 4 + ? 2 + : 3, + is: (n: number): number => (n % 10 != 1 || n % 100 == 11 ? 1 : 0), + lt: (n: number): number => + n % 10 == 1 && (n % 100 < 11 || n % 100 > 19) + ? 0 + : n % 10 >= 2 && n % 10 <= 9 && (n % 100 < 11 || n % 100 > 19) + ? 1 + : 2, + lv: (n: number): number => + n % 10 == 0 || (n % 100 >= 11 && n % 100 <= 19) + ? 0 + : n % 10 == 1 && n % 100 != 11 + ? 1 + : 2, + me: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) + ? 1 + : 2, + mk: (n: number): number => (n % 10 != 1 || n % 100 == 11 ? 1 : 0), + pl: (n: number): number => + n == 1 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + ro: (n: number): number => + n == 1 ? 0 : n == 0 || (n % 100 >= 2 && n % 100 <= 19) ? 1 : 2, + ru: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + sk: (n: number): number => (n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2), + sl: (n: number): number => + n % 100 == 1 + ? 0 + : n % 100 == 2 + ? 1 + : n % 100 == 3 || n % 100 == 4 + ? 2 + : 3, + sr: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + szl: (n: number): number => + n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && n % 100 == 20 ? 1 : 2, + uk: (n: number): number => + n % 10 == 1 && n % 100 != 11 + ? 0 + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) + ? 1 + : 2, + }, +})) diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts index 50060fd3123..1a37f4e89aa 100644 --- a/frontend/nuxt.config.ts +++ b/frontend/nuxt.config.ts @@ -1,7 +1,7 @@ import { defineNuxtConfig } from "nuxt/config" import { disallowedBots } from "./src/constants/disallowed-bots" -import locales from "./src/locales/scripts/valid-locales.json" +import locales from "./i18n/locales/scripts/valid-locales.json" import type { LocaleObject } from "@nuxtjs/i18n" @@ -124,6 +124,6 @@ export default defineNuxtConfig({ * */ detectBrowserLanguage: false, trailingSlash: false, - vueI18n: "./src/vue-i18n", + vueI18n: "./vue-i18n", }, }) diff --git a/frontend/package.json b/frontend/package.json index 1a418e43626..7d59ffdbd41 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -41,16 +41,15 @@ "test:storybook:local": "playwright test -c test/storybook", "test:storybook:debug": "PWDEBUG=1 pnpm test:storybook:local", "test:storybook:gen": "playwright codegen localhost:54000/", - "types": "pnpm run prepare:nuxt && vue-tsc -p .", + "types": "pnpm run i18n:copy-test-locales && pnpm run prepare:nuxt && vue-tsc -p .", "i18n": "pnpm i18n:create-locales-list && pnpm i18n:get-translations && pnpm i18n:update-locales", "i18n:en": "pnpm i18n:get-translations --en-only", - "i18n:copy-test-locales": "cp test/locales/**.json src/locales/ && mv src/locales/valid-locales.json src/locales/scripts/valid-locales.json", + "i18n:copy-test-locales": "cp test/locales/**.json i18n/locales/ && mv i18n/locales/valid-locales.json i18n/locales/scripts/valid-locales.json", "i18n:no-get": "pnpm i18n:create-locales-list && pnpm i18n:update-locales", - "i18n:create-locales-list": "node src/locales/scripts/create-wp-locale-list", - "i18n:get-translations": "node src/locales/scripts/get-translations", - "i18n:update-locales": "node src/locales/scripts/get-validated-locales", - "i18n:generate-pot": "node src/locales/scripts/json-to-pot", - "i18n:check": "vue-i18n-extract report --vueFiles './src/*/**.?(js|ts|vue)' --languageFiles './src/locales/en.json'", + "i18n:create-locales-list": "node i18n/locales/scripts/create-wp-locale-list", + "i18n:get-translations": "node i18n/locales/scripts/get-translations", + "i18n:update-locales": "node i18n/locales/scripts/get-validated-locales", + "i18n:generate-pot": "node i18n/locales/scripts/json-to-pot", "create:component-sfc": "remake component", "create:story": "remake story", "create:component-storybook-test": "remake component-storybook-test", @@ -86,8 +85,9 @@ }, "devDependencies": { "@babel/parser": "^7.24.8", + "@intlify/core-base": "^10.0.4", "@nuxt/test-utils": "^3.14.4", - "@nuxtjs/i18n": "8.5.5", + "@nuxtjs/i18n": "^9.1.0", "@nuxtjs/storybook": "8.3.2", "@playwright/test": "1.48.2", "@storybook-vue/nuxt": "8.3.2", diff --git a/frontend/src/app.vue b/frontend/src/app.vue index 19d5c025014..c8d93f8d5a8 100644 --- a/frontend/src/app.vue +++ b/frontend/src/app.vue @@ -35,11 +35,7 @@ const headerHeight = computed(() => { return `--header-height: ${uiStore.headerHeight}px` }) -const head = useLocaleHead({ - addDirAttribute: true, - identifierAttribute: "id", - addSeoAttributes: true, -}) +const head = useLocaleHead({ dir: true, key: "id", seo: true }) useHead({ bodyAttrs: { class: darkMode.cssClass }, @@ -78,7 +74,7 @@ onMounted(() => {