From 6c1b320e2ee14c86a5c10c063068399a0a9f54e6 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 2 Apr 2024 14:39:46 +0800 Subject: [PATCH] DEV: Fix case inconsistency in translation file (#26456) Why this change? Our translation files use the snake case convention. --- .../app/lib/form-template-validation.js | 32 ++++++++++++------- config/locales/client.en.yml | 20 ++++++------ .../composer/template_validation_spec.rb | 8 ++--- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/form-template-validation.js b/app/assets/javascripts/discourse/app/lib/form-template-validation.js index 656de3138a3..cf9e7c9cf4e 100644 --- a/app/assets/javascripts/discourse/app/lib/form-template-validation.js +++ b/app/assets/javascripts/discourse/app/lib/form-template-validation.js @@ -101,11 +101,17 @@ function _validateFormTemplateData(form) { function _showErrorMessage(field, element) { if (field.validity.valueMissing) { - const prefix = "form_templates.errors.valueMissing"; + const prefix = "form_templates.errors.value_missing"; const types = ["select-one", "select-multiple", "checkbox"]; - _showErrorByType(element, field, prefix, types); + + const i18nMappings = { + "select-one": "select_one", + "select-multiple": "select_multiple", + }; + + _showErrorByType(element, field, prefix, types, i18nMappings); } else if (field.validity.typeMismatch) { - const prefix = "form_templates.errors.typeMismatch"; + const prefix = "form_templates.errors.type_mismatch"; const types = [ "color", "date", @@ -118,35 +124,39 @@ function _showErrorMessage(field, element) { ]; _showErrorByType(element, field, prefix, types); } else if (field.validity.tooShort) { - element.textContent = I18n.t("form_templates.errors.tooShort", { + element.textContent = I18n.t("form_templates.errors.too_short", { count: field.minLength, }); } else if (field.validity.tooLong) { - element.textContent = I18n.t("form_templates.errors.tooLong", { + element.textContent = I18n.t("form_templates.errors.too_long", { count: field.maxLength, }); } else if (field.validity.rangeOverflow) { - element.textContent = I18n.t("form_templates.errors.rangeOverflow", { + element.textContent = I18n.t("form_templates.errors.range_overflow", { count: field.max, }); } else if (field.validity.rangeUnderflow) { - element.textContent = I18n.t("form_templates.errors.rangeUnderflow", { + element.textContent = I18n.t("form_templates.errors.range_underflow", { count: field.min, }); } else if (field.validity.patternMismatch) { - element.textContent = I18n.t("form_templates.errors.patternMismatch"); + element.textContent = I18n.t("form_templates.errors.pattern_mismatch"); } else if (field.validity.badInput) { - element.textContent = I18n.t("form_templates.errors.badInput"); + element.textContent = I18n.t("form_templates.errors.bad_input"); } } -function _showErrorByType(element, field, prefix, types) { +function _showErrorByType(element, field, prefix, types, i18nMappings) { if (!types.includes(field.type)) { element.textContent = I18n.t(`${prefix}.default`); } else { types.forEach((type) => { if (field.type === type) { - element.textContent = I18n.t(`${prefix}.${type}`); + element.textContent = I18n.t( + `${prefix}.${ + i18nMappings && i18nMappings[type] ? i18nMappings[type] : type + }` + ); } }); } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 45c5702e435..9d2cf7ba5bc 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -4718,12 +4718,12 @@ en: upload: "Upload" uploading: "Uploading" errors: - valueMissing: + value_missing: default: "Please fill out this field." - select-one: "Please select an item in the list." - select-multiple: "Please select at least one item in the list." + select_one: "Please select an item in the list." + select_multiple: "Please select at least one item in the list." checkbox: "Please check this box if you want to proceed." - typeMismatch: + type_mismatch: default: "Please enter a valid value." color: "Please enter a color." date: "Please enter a date." @@ -4733,20 +4733,20 @@ en: tel: "Please enter a valid telephone number." text: "Please enter a text value." url: "Please enter a valid URL." - tooShort: + too_short: one: "The input must be %{count} character or longer." other: "The input must be %{count} characters or longer." - tooLong: + too_long: one: "The input must be less than %{count} character." other: "The input must be less than %{count} characters." - rangeOverflow: + range_overflow: one: "The input must be less than %{count}." other: "The input must be less than %{count}." - rangeUnderflow: + range_underflow: one: "The input must be more than %{count}." other: "The input must be more than %{count}." - patternMismatch: "Please match the requested format." - badInput: "Please enter a valid input." + pattern_mismatch: "Please match the requested format." + bad_input: "Please enter a valid input." table_builder: title: "Table Builder" diff --git a/spec/system/composer/template_validation_spec.rb b/spec/system/composer/template_validation_spec.rb index 3c10ea8c34e..366a3a3b990 100644 --- a/spec/system/composer/template_validation_spec.rb +++ b/spec/system/composer/template_validation_spec.rb @@ -72,7 +72,7 @@ describe "Composer Form Template Validations", type: :system do composer.fill_title(topic_title) composer.create expect(composer).to have_form_template_field_error( - I18n.t("js.form_templates.errors.valueMissing.default"), + I18n.t("js.form_templates.errors.value_missing.default"), ) end @@ -83,7 +83,7 @@ describe "Composer Form Template Validations", type: :system do composer.create composer.fill_form_template_field("input", "Bruce Wayne") expect(composer).to have_form_template_field_error( - I18n.t("js.form_templates.errors.typeMismatch.email"), + I18n.t("js.form_templates.errors.type_mismatch.email"), ) end @@ -94,7 +94,7 @@ describe "Composer Form Template Validations", type: :system do composer.create composer.fill_form_template_field("input", "b@b.com") expect(composer).to have_form_template_field_error( - I18n.t("js.form_templates.errors.tooShort", count: 10), + I18n.t("js.form_templates.errors.too_short", count: 10), ) end @@ -105,7 +105,7 @@ describe "Composer Form Template Validations", type: :system do composer.fill_form_template_field("input", "www.example.com") composer.create expect(composer).to have_form_template_field_error( - I18n.t("js.form_templates.errors.patternMismatch"), + I18n.t("js.form_templates.errors.pattern_mismatch"), ) end end