From 3eea7dc6cdb90a04fddfe936a183e817dd6d3d5d Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Wed, 29 May 2024 09:44:56 -0400 Subject: [PATCH] Use valid locale for translation test (#20899) --- build-scripts/gulp/translations.js | 11 +- .../src/pages/date-time/date-time-numeric.ts | 80 +++++++------- .../src/pages/date-time/date-time-seconds.ts | 80 +++++++------- .../pages/date-time/date-time-short-year.ts | 80 +++++++------- .../src/pages/date-time/date-time-short.ts | 80 +++++++------- gallery/src/pages/date-time/date-time.ts | 80 +++++++------- gallery/src/pages/date-time/date.ts | 102 +++++++++--------- gallery/src/pages/date-time/time-seconds.ts | 80 +++++++------- gallery/src/pages/date-time/time-weekday.ts | 80 +++++++------- gallery/src/pages/date-time/time.ts | 80 +++++++------- src/common/number/format_number.ts | 18 +--- 11 files changed, 372 insertions(+), 399 deletions(-) diff --git a/build-scripts/gulp/translations.js b/build-scripts/gulp/translations.js index e1abf487ac..dde4dd89f4 100755 --- a/build-scripts/gulp/translations.js +++ b/build-scripts/gulp/translations.js @@ -19,6 +19,7 @@ const inBackendDir = "translations/backend"; const workDir = "build/translations"; const outDir = join(workDir, "output"); const EN_SRC = join(paths.translations_src, "en.json"); +const TEST_LOCALE = "en-x-test"; let mergeBackend = false; @@ -150,7 +151,7 @@ const createTestTranslation = () => : gulp .src(EN_SRC) .pipe(new CustomJSON(null, testReviver)) - .pipe(rename("test.json")) + .pipe(rename(`${TEST_LOCALE}.json`)) .pipe(gulp.dest(workDir)); /** @@ -192,7 +193,7 @@ const createTranslations = async () => { // each locale, then fragmentizes and flattens the data for final output. const translationFiles = await glob([ `${inFrontendDir}/!(en).json`, - ...(env.isProdBuild() ? [] : [`${workDir}/test.json`]), + ...(env.isProdBuild() ? [] : [`${workDir}/${TEST_LOCALE}.json`]), ]); const hashStream = new Transform({ objectMode: true, @@ -254,8 +255,8 @@ const createTranslations = async () => { const mergeFiles = []; for (let i = 1; i <= subtags.length; i++) { const lang = subtags.slice(0, i).join("-"); - if (lang === "test") { - mergeFiles.push(`${workDir}/test.json`); + if (lang === TEST_LOCALE) { + mergeFiles.push(`${workDir}/${TEST_LOCALE}.json`); } else if (lang !== "en") { mergeFiles.push(`${inFrontendDir}/${lang}.json`); if (mergeBackend) { @@ -284,7 +285,7 @@ const writeTranslationMetaData = () => new CustomJSON((meta) => { // Add the test translation in development. if (!env.isProdBuild()) { - meta.test = { nativeName: "Test" }; + meta[TEST_LOCALE] = { nativeName: "Translation Test" }; } // Filter out locales without a native name, and add the hashes. for (const locale of Object.keys(meta)) { diff --git a/gallery/src/pages/date-time/date-time-numeric.ts b/gallery/src/pages/date-time/date-time-numeric.ts index a90f6a6131..25f2db7c45 100644 --- a/gallery/src/pages/date-time/date-time-numeric.ts +++ b/gallery/src/pages/date-time/date-time-numeric.ts @@ -56,48 +56,46 @@ export class DemoDateTimeDateTimeNumeric extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatDateTimeNumeric( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatDateTimeNumeric( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatDateTimeNumeric( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatDateTimeNumeric( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatDateTimeNumeric( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatDateTimeNumeric( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/date-time-seconds.ts b/gallery/src/pages/date-time/date-time-seconds.ts index cc1d518184..3cd5b4518b 100644 --- a/gallery/src/pages/date-time/date-time-seconds.ts +++ b/gallery/src/pages/date-time/date-time-seconds.ts @@ -56,48 +56,46 @@ export class DemoDateTimeDateTimeSeconds extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatDateTimeWithSeconds( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatDateTimeWithSeconds( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatDateTimeWithSeconds( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatDateTimeWithSeconds( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatDateTimeWithSeconds( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatDateTimeWithSeconds( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/date-time-short-year.ts b/gallery/src/pages/date-time/date-time-short-year.ts index 9b6c8a3807..ecd50c369b 100644 --- a/gallery/src/pages/date-time/date-time-short-year.ts +++ b/gallery/src/pages/date-time/date-time-short-year.ts @@ -56,48 +56,46 @@ export class DemoDateTimeDateTimeShortYear extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatShortDateTimeWithYear( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatShortDateTimeWithYear( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatShortDateTimeWithYear( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatShortDateTimeWithYear( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatShortDateTimeWithYear( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatShortDateTimeWithYear( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/date-time-short.ts b/gallery/src/pages/date-time/date-time-short.ts index 018e3a84e9..67bde5a50d 100644 --- a/gallery/src/pages/date-time/date-time-short.ts +++ b/gallery/src/pages/date-time/date-time-short.ts @@ -56,48 +56,46 @@ export class DemoDateTimeDateTimeShort extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatShortDateTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatShortDateTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatShortDateTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatShortDateTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatShortDateTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatShortDateTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/date-time.ts b/gallery/src/pages/date-time/date-time.ts index 3900deef4d..31b2e03bd2 100644 --- a/gallery/src/pages/date-time/date-time.ts +++ b/gallery/src/pages/date-time/date-time.ts @@ -56,48 +56,46 @@ export class DemoDateTimeDateTime extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatDateTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatDateTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatDateTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatDateTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatDateTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatDateTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/date.ts b/gallery/src/pages/date-time/date.ts index 1ddc60ea7f..0015d1e566 100644 --- a/gallery/src/pages/date-time/date.ts +++ b/gallery/src/pages/date-time/date.ts @@ -35,59 +35,57 @@ export class DemoDateTimeDate extends LitElement {
Month-Day-Year
Year-Month-Day
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatDateNumeric( - date, - { - ...defaultLocale, - language: key, - date_format: DateFormat.language, - }, - demoConfig - )} -
-
- ${formatDateNumeric( - date, - { - ...defaultLocale, - language: key, - date_format: DateFormat.DMY, - }, - demoConfig - )} -
-
- ${formatDateNumeric( - date, - { - ...defaultLocale, - language: key, - date_format: DateFormat.MDY, - }, - demoConfig - )} -
-
- ${formatDateNumeric( - date, - { - ...defaultLocale, - language: key, - date_format: DateFormat.YMD, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatDateNumeric( + date, + { + ...defaultLocale, + language: key, + date_format: DateFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatDateNumeric( + date, + { + ...defaultLocale, + language: key, + date_format: DateFormat.DMY, + }, + demoConfig + )} +
+
+ ${formatDateNumeric( + date, + { + ...defaultLocale, + language: key, + date_format: DateFormat.MDY, + }, + demoConfig + )} +
+
+ ${formatDateNumeric( + date, + { + ...defaultLocale, + language: key, + date_format: DateFormat.YMD, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/time-seconds.ts b/gallery/src/pages/date-time/time-seconds.ts index be6c1ffa41..d4c08ab643 100644 --- a/gallery/src/pages/date-time/time-seconds.ts +++ b/gallery/src/pages/date-time/time-seconds.ts @@ -56,48 +56,46 @@ export class DemoDateTimeTimeSeconds extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatTimeWithSeconds( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatTimeWithSeconds( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatTimeWithSeconds( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatTimeWithSeconds( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatTimeWithSeconds( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatTimeWithSeconds( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/time-weekday.ts b/gallery/src/pages/date-time/time-weekday.ts index 68b1a75186..55f01368c5 100644 --- a/gallery/src/pages/date-time/time-weekday.ts +++ b/gallery/src/pages/date-time/time-weekday.ts @@ -56,48 +56,46 @@ export class DemoDateTimeTimeWeekday extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatTimeWeekday( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatTimeWeekday( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatTimeWeekday( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatTimeWeekday( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatTimeWeekday( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatTimeWeekday( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/gallery/src/pages/date-time/time.ts b/gallery/src/pages/date-time/time.ts index a02ad389ff..db15fc3d4f 100644 --- a/gallery/src/pages/date-time/time.ts +++ b/gallery/src/pages/date-time/time.ts @@ -56,48 +56,46 @@ export class DemoDateTimeTime extends LitElement {
12 Hours
24 Hours
- ${Object.entries(translationMetadata.translations) - .filter(([key, _]) => key !== "test") - .map( - ([key, value]) => html` -
-
${value.nativeName}
-
- ${formatTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.language, - }, - demoConfig - )} -
-
- ${formatTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.am_pm, - }, - demoConfig - )} -
-
- ${formatTime( - this.date, - { - ...defaultLocale, - language: key, - time_format: TimeFormat.twenty_four, - }, - demoConfig - )} -
+ ${Object.entries(translationMetadata.translations).map( + ([key, value]) => html` +
+
${value.nativeName}
+
+ ${formatTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.language, + }, + demoConfig + )}
- ` - )} +
+ ${formatTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.am_pm, + }, + demoConfig + )} +
+
+ ${formatTime( + this.date, + { + ...defaultLocale, + language: key, + time_format: TimeFormat.twenty_four, + }, + demoConfig + )} +
+
+ ` + )} `; } diff --git a/src/common/number/format_number.ts b/src/common/number/format_number.ts index 9980308163..b97c4b71fd 100644 --- a/src/common/number/format_number.ts +++ b/src/common/number/format_number.ts @@ -65,20 +65,10 @@ export const formatNumber = ( localeOptions?.number_format !== NumberFormat.none && !Number.isNaN(Number(num)) ) { - try { - return new Intl.NumberFormat( - locale, - getDefaultFormatOptions(num, options) - ).format(Number(num)); - } catch (err: any) { - // Don't fail when using "TEST" language - // eslint-disable-next-line no-console - console.error(err); - return new Intl.NumberFormat( - undefined, - getDefaultFormatOptions(num, options) - ).format(Number(num)); - } + return new Intl.NumberFormat( + locale, + getDefaultFormatOptions(num, options) + ).format(Number(num)); } if (