DEV: Fix case inconsistency in translation file (#26456)

Why this change?

Our translation files use the snake case convention.
This commit is contained in:
Alan Guo Xiang Tan 2024-04-02 14:39:46 +08:00 committed by GitHub
parent 972db687fe
commit 6c1b320e2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 25 deletions

View File

@ -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
}`
);
}
});
}

View File

@ -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"

View File

@ -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