Chris@0: #!/bin/php Chris@0: main->en->localeDisplayNames->territories as $code => $name) { Chris@0: // Use any alternate codes the Drupal community wishes to. Chris@14: $alt_codes = [ Chris@0: // 'CI-alt-variant', // Use CI-alt-variant instead of the CI entry. Chris@14: ]; Chris@0: if (in_array($code, $alt_codes)) { Chris@0: // Just use the first 2 character part of the alt code. Chris@0: $code = strtok($code, '-'); Chris@0: } Chris@0: Chris@0: // Skip any codes we wish to exclude from our country list. Chris@14: $exclude_codes = [ Chris@14: // The European Union is not a country. Chris@14: 'EU', Chris@14: // Don't allow "Unknown Region". Chris@14: 'ZZ', Chris@14: ]; Chris@0: if (in_array($code, $exclude_codes)) { Chris@0: continue; Chris@0: } Chris@0: Chris@0: // Ignore every territory that doesn't have a 2 character code. Chris@0: if (strlen($code) !== 2) { Chris@0: continue; Chris@0: } Chris@0: $countries[(string) $code] = $name; Chris@0: } Chris@0: if (empty($countries)) { Chris@0: echo 'ERROR: Did not find expected country names.' . PHP_EOL; Chris@0: exit; Chris@0: } Chris@0: // Sort by country code (to minimize diffs). Chris@0: ksort($countries); Chris@0: Chris@0: // Produce PHP code. Chris@0: $out = ''; Chris@0: foreach ($countries as $code => $name) { Chris@0: // For .po translation file's sake, use double-quotes instead of escaped Chris@0: // single-quotes. Chris@0: $name = (strpos($name, '\'') !== FALSE ? '"' . $name . '"' : "'" . $name . "'"); Chris@0: $out .= ' ' . var_export($code, TRUE) . ' => t(' . $name . '),' . "\n"; Chris@0: } Chris@0: Chris@0: // Replace the actual PHP code in standard.inc. Chris@0: $file = DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php'; Chris@0: $content = file_get_contents($file); Chris@14: $content = preg_replace('/(\$countries = \[\n)(.+?)(^\s+\];)/ms', '$1' . $out . '$3', $content, -1, $count); Chris@0: file_put_contents($file, $content);