Problem/Motivation
Do not translate option value for County element of the Address!
Steps to reproduce
- Add element Address to the webform.
- View the webform in different website languages and check the country option value.
Proposed resolution
Country option value should be the same for all language versions of the website. Translate only the label, not the option value!
Solution proposal example:
function hook_webform_options_country_names_alter(array &$options, array $element = []): void {
/** @var \Drupal\Core\Locale\CountryManagerInterface $country_manager */
$country_manager = \Drupal::service('country_manager');
$countries_en = $country_manager->getList('en');
// Set the option value to "ISO code + English name of the country" (e.g. CZ Czechia) and keep the translation of the labels according to the language version of the website
foreach ($countries_en as $code => $label_translated) {
$label_en = $label_translated->getUntranslatedString();
$options["$code $label_en"] = $label_translated;
}
}
Comments
Comment #2
hop commentedComment #3
hop commentedComment #4
hop commentedComment #5
liam morlandThanks. Please put your solution into an issue fork and merge request.
Comment #7
jrockowitz commentedWe can't update the existing country names options because it will impact existing implementations.
You should create your own custom country options list with English as the values. (/admin/structure/webform/options/manage)
Comment #8
jrockowitz commented