Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix frontend to include languages that do not have iso-639-1 codes (#4363)
zack48e300d10286
diff --git a/frontend/src/locales/scripts/create-wp-locale-list.js b/frontend/src/locales/scripts/create-wp-locale-list.jsindex fec81aa14..51f4a2bcb 100644--- a/frontend/src/locales/scripts/create-wp-locale-list.js+++ b/frontend/src/locales/scripts/create-wp-locale-list.js@@ -7,7 +7,6 @@ This script extracts data for locales available in GlotPress and translate.wp.orconst fs = require("fs")const axios = require("./axios")-const { addFetchedTranslationStatus } = require("./get-translations-status")const base_url =@@ -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",],@@ -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)@@ -66,6 +69,7 @@ function parseLocaleData(rawData) {data[camelCasedPropName] = value[1]}})+return [wpLocale, data]}}diff --git a/frontend/src/locales/scripts/get-validated-locales.js b/frontend/src/locales/scripts/get-validated-locales.jsindex 6416b44e0..7bbef4c80 100644--- a/frontend/src/locales/scripts/get-validated-locales.js+++ b/frontend/src/locales/scripts/get-validated-locales.js@@ -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:+ locale.langCodeIso_639_1 ??+ locale.langCodeIso_639_2 ??+ locale.langCodeIso_639_3 ??+ undefined,/* Custom fields */