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

Add validator for default_language in language control panel #6811

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/configuration/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ In the following example, the `urlValidator` method validator will be applied fo
config.registerUtility({
type: 'validator',
name: 'url',
dependencies: { format: 'url' },
method: urlValidator,
})
```
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ca/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,11 @@ msgstr ""
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "El procés de registre ha estat satisfactori. Si us plau, comproveu la vostra bústia d'entrada de correu electrònic per obtenir informació sobre com activar el vostre compte."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/de/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,11 @@ msgstr "Die angegebene alternative URL existiert bereits."
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "Bitte prüfen Sie Ihr E-Mail Postfach. Sie sollten eine E-Mail erhalten haben mit Anweisungen, wie Sie Ihren Zugang aktivieren können."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,11 @@ msgstr ""
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr ""

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/es/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3770,6 +3770,11 @@ msgstr "¡La URL alternativa ya existe!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "El registro fue exitoso. Por favor, verifique su bandeja de entrada para obtener información sobre cómo activar su cuenta."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/eu/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3770,6 +3770,11 @@ msgstr "Eman duzun ordezko bidea jada badago!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "Izen-emate prozesua ondo egin duzu. Begiratu zure eposta, kontua aktibatzeko informazioa bertara bidali dizugu-eta."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/fi/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,11 @@ msgstr "Ehdotettu vaihtoehtoinen URL on jo olemassa!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "Rekisteröinti onnistui. Tarkista, saitko sähköpostiisi ohjeet käyttäjätunnuksesi aktivoimiseksi."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/fr/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3770,6 +3770,11 @@ msgstr "L'URL alternative fournie existe déjà !"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "Le processus d'inscription a réussi. Veuillez vérifier votre boîte e-mail pour savoir comment activer votre compte."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/hi/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,11 @@ msgstr "प्रदान किया गया वैकल्पिक य
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "रजिस्ट्रेशन प्रक्रिया सफल रही है। कृपया अपने ईमेल इनबॉक्स में अपने खाते को सक्रिय करने के लिए जानकारी के लिए जाँच करें।"

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/it/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,11 @@ msgstr "L'url alternativo inserito è già stato utilizzato!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "La registrazione è avvenuta correttamente. Per favore controlla la tua casella di posta per informazioni su come attivare il tuo account."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ja/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,11 @@ msgstr ""
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "The registration process has been successful. Please check your e-mail inbox for information on how activate your account. (未翻訳)"

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/nl/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3767,6 +3767,11 @@ msgstr "De ingevoerde alternatieve URL bestaat reeds!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "Het registratieproces was succesvol. Controleer jouw e-mails voor informatie over hoe jouw account te activeren."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/pt/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,11 @@ msgstr ""
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "O processo de registo foi bem sucedido. Por favor verifique no seu e-mail a informação sobre como activar a sua conta."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/pt_BR/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,11 @@ msgstr "A URL alternativa já existe!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "O processo de registro foi bem sucedido. Verifique sua caixa de entrada de e-mail para obter informações sobre como ativar sua conta."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ro/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,11 @@ msgstr "URL-ul alternativ furnizat există deja!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "Procesul de înregistrare a avut succes. Vă rugăm să verificați căsuța de e-mail pentru informații despre modul de activare a contului dvs."

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
7 changes: 6 additions & 1 deletion packages/volto/locales/volto.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2024-12-06T13:45:21.266Z\n"
"POT-Creation-Date: 2025-03-05T13:04:20.470Z\n"
"Last-Translator: Plone i18n <[email protected]>\n"
"Language-Team: Plone i18n <[email protected]>\n"
"Content-Type: text/plain; charset=utf-8\n"
Expand Down Expand Up @@ -3765,6 +3765,11 @@ msgstr ""
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr ""

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/zh_CN/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,11 @@ msgstr "提供的替代url已经存在!"
msgid "The registration process has been successful. Please check your e-mail inbox for information on how activate your account."
msgstr "注册过程成功完成。请在您的电子邮箱中查看有关如何激活账户的信息。"

#. Default: "The selected default language must be in the list of the field 'Available languages'"
#: helpers/MessageLabels/MessageLabels
msgid "The selected default language must be in the list of the field 'Available languages'"
msgstr ""

#. Default: "The site configuration is outdated and needs to be upgraded."
#: components/manage/Controlpanels/Controlpanels
#: components/manage/Controlpanels/UpgradeControlPanel
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/6811.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add validator for `default_language` in language control panel. @sneridagh
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class SelectWidget extends Component {
this.props.placeholder ??
this.props.intl.formatMessage(messages.select)
}
onBlur={() => this.props.onBlur(id, value)}
onChange={(selectedOption) => {
if (isMulti) {
return onChange(
Expand Down
8 changes: 8 additions & 0 deletions packages/volto/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
startEventDateRangeValidator,
endEventDateRangeValidator,
patternValidator,
defaultLanguageControlPanelValidator,
} from '@plone/volto/helpers/FormValidation/validators';

const registerValidators = (config: ConfigType) => {
Expand Down Expand Up @@ -150,6 +151,13 @@ const registerValidators = (config: ConfigType) => {
dependencies: { behaviorName: 'plone.eventbasic', fieldName: 'end' },
method: endEventDateRangeValidator,
});

config.registerUtility({
name: 'default_language',
type: 'validator',
dependencies: { format: 'default_language' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use fieldName: 'default_language' so plone/plone.i18n#73 isn't needed?

Copy link
Member Author

@sneridagh sneridagh Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have this feature (yet). Do you really think it's the way to go? For me, the problem is the lack of expressivity in the definition of the fields in the backend source, which is not Volto to blame. And it's not only here. It's all over the place in the backend fields definitions.

Specially on control panels. So the field fix in plone/plone.i18n#73 should not only be the hint for the client side validation, but also having a server one where the validation of the default_language field is tied to the available_languages one.

method: defaultLanguageControlPanelValidator,
});
};

export { registerValidators };
14 changes: 14 additions & 0 deletions packages/volto/src/helpers/FormValidation/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,17 @@ export const minItemsValidator = ({
? formatMessage(messages.minItems, { minItems: field.minItems })
: null;
};

export const defaultLanguageControlPanelValidator = ({
value,
formData,
formatMessage,
}: Validator) => {
const isValid =
value &&
(formData.available_languages.find(
(lang: { token: string }) => lang.token === value,
) ||
formData.available_languages.includes(value));
return !isValid ? formatMessage(messages.defaultLanguage) : null;
};
5 changes: 5 additions & 0 deletions packages/volto/src/helpers/MessageLabels/MessageLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,9 @@ export const messages = defineMessages({
defaultMessage:
'The number of items must be greater than or equal to {minItems}',
},
defaultLanguage: {
id: "The selected default language must be in the list of the field 'Available languages'",
defaultMessage:
"The selected default language must be in the list of the field 'Available languages'",
},
});