Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix frontend to include languages that do not have iso-639-1 codes #4363

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion frontend/src/locales/scripts/create-wp-locale-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This script extracts data for locales available in GlotPress and translate.wp.or
const fs = require("fs")

const axios = require("./axios")

const { addFetchedTranslationStatus } = require("./get-translations-status")

const base_url =
Expand All @@ -34,6 +33,8 @@ const createPropertyRePatterns = ({
"english_name",
"native_name",
"lang_code_iso_639_1", // used for HTML lang attribute
"lang_code_iso_639_2", // used for HTML lang attribute, fallback from previous
"lang_code_iso_639_3", // used for HTML lang attribute, fallback from previous
"slug", // unique identifier used by Nuxt i18n
"text_direction",
],
Expand All @@ -49,12 +50,14 @@ function parseLocaleData(rawData) {
const wpLocalePattern = /wp_locale *= *'(.*)';/
const propertyRePatterns = createPropertyRePatterns()
const wpLocaleMatch = rawData.match(wpLocalePattern)

// ugly check to exclude English from the locales list,
// so we don't overwrite `en.json` later. See `get-translations.js`
// to check how `en.json` file is created.
if (wpLocaleMatch && wpLocaleMatch[1] !== "en_US") {
const wpLocale = wpLocaleMatch[1]
const data = {}

Object.keys(propertyRePatterns).forEach((key) => {
const pattern = propertyRePatterns[key]
const value = rawData.match(pattern)
Expand All @@ -66,6 +69,7 @@ function parseLocaleData(rawData) {
data[camelCasedPropName] = value[1]
}
})

return [wpLocale, data]
}
}
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/locales/scripts/get-validated-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ const getValidatedLocales = async () => {
code: locale.slug,
dir: locale.textDirection || "ltr",
file: `${locale.slug}.json`,
iso: locale.langCodeIso_639_1 ?? undefined,
// Check for a language in all three versions of the ISO 639 spec,
// defaulting to the v1 two-character codes before checking for the
// three-character codes in the v2 and v3 specs.
iso:
zackkrida marked this conversation as resolved.
Show resolved Hide resolved
locale.langCodeIso_639_1 ??
locale.langCodeIso_639_2 ??
locale.langCodeIso_639_3 ??
undefined,

/* Custom fields */

Expand Down
Loading