Problem/Motivation

Do not translate option value for County element of the Address!

Steps to reproduce

  1. Add element Address to the webform.
  2. 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;
  }
}

Issue fork webform-3536763

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hop created an issue. See original summary.

hop’s picture

Title: Country value option » Country option value (Address element)
Issue summary: View changes
hop’s picture

Issue summary: View changes
hop’s picture

Issue summary: View changes
liam morland’s picture

Version: 6.2.9 » 6.3.x-dev

Thanks. Please put your solution into an issue fork and merge request.

deepesh151086 made their first commit to this issue’s fork.

jrockowitz’s picture

Status: Active » Closed (won't fix)

We 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)

jrockowitz’s picture