update-countries.sh inadvertently broken by Issue #3328454

Created on 3 October 2024, 5 months ago
Updated 3 March 2025, 4 days ago

Problem/Motivation

While attempting to run the update-countries.sh script with an appropriate territories.json file, the resulting CountryManager.php file consisted of country codes mapped to t() verbatim (no country name within quotes) unlike the original CountryManager.php file provided with composer, which is correctly formatted.

This results in the country names being removed from the file and subsequent runs of update-countries.sh file to error on an invalid call to t() in CountryManager.php.

Steps to reproduce

Place the requested territories.json file in DRUPAL_ROOT and run core/scripts/update-countries.sh. The resulting core/lib/Drupal/Core/Locale/CountryManager.php will be "corrupted" with lines such as

'AC' => t(),

instead of

'AC' => t('Ascension Island'),

This was tested with PHP 8.3 and Drupal 10.3.5. The file appears to have the same bug in v11.x too.

Proposed resolution

Line 96 of core/scripts/update-countries.php needs to be changed from

$name = str_contains($name, '\'' ? '"' . $name . '"' : "'" . $name . "'");

to

$name = str_contains($name, '\'') ? '"' . $name . '"' : "'" . $name . "'";

Note the misplaced closing bracket inadvertently wrapping the entire ternary rather than just the two parameters to the str_contains function.

Remaining tasks

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

locale.module

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

    Also, I reproduce this problem.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Binoli Lalani Gujarat

    binoli lalani โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    3 months ago
    Total: 4863s
    #349318
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia jaydev bhatt Pune, Maharashtra

    jaydev bhatt โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Success
    4 days ago
    Total: 385s
    #438509
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia jaydev bhatt Pune, Maharashtra

    I have tested the updated code on Drupal 11.1.1 and reviewed the changes thoroughly. With the updates made to the script, the update-countries.sh file now runs without any issues. Additionally, I have ensured that the code aligns with the latest version of the 11.x branch.

    I am moving this issue to Needs Review (NR) for further verification. However, based on my testing and review, this patch appears to be ready for RTBC (Reviewed & Tested by the Community).

    Thank you!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Was previously tagged for tests which are still needed it appears.

  • Pipeline finished with Failed
    3 days ago
    Total: 163s
    #439798
  • Pipeline finished with Failed
    3 days ago
    Total: 465s
    #439808
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia jaydev bhatt Pune, Maharashtra

    I am working on writing PHPUnit test cases for the update-countries script. The test currently verifies the following:
    โ€ข The script correctly reads and processes the territories.json file.
    โ€ข Excluded country codes (e.g., โ€˜EUโ€™, โ€˜UNโ€™, โ€˜ZZโ€™) are not included in the final country list.
    โ€ข The updated country list is properly written to CountryManager.php.

    Are there any additional test cases that should be considered to ensure full coverage? Feedback is welcome!

  • Pipeline finished with Failed
    2 days ago
    Total: 637s
    #440391
  • Pipeline finished with Failed
    2 days ago
    Total: 417s
    #440425
  • Pipeline finished with Failed
    2 days ago
    Total: 571s
    #440507
  • Pipeline finished with Failed
    2 days ago
    Total: 404s
    #440731
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia jaydev bhatt Pune, Maharashtra

    Upon debugging the issue further and for writing the test properly.
    found out that the issue which is mentioned in the description to run the update-countries.sh to Update the CountryManager.php

    here the .sh file it self is generating the error with the 11.x code base and not updating the CountryManager.php file.

    i setup the drupalsetup using ddev and was trying to run the sh file like this ddev exec php core/scripts/update-countries.sh
    and got the following error

    PHP Fatal error:  Uncaught Error: Call to undefined function Drupal\Core\Locale\t() in /Users/abc/Developer/DrupalProject/core/lib/Drupal/Core/Locale/CountryManager.php:45
    Stack trace:
    #0 /Users/abc/Developer/DrupalProject/core/scripts/update-countries.sh(43): Drupal\Core\Locale\CountryManager::getStandardList()
    #1 {main}
      thrown in /Users/abc/Developer/DrupalProject/core/lib/Drupal/Core/Locale/CountryManager.php on line 45

    keep this on need work as need more input on this error of the .sh file.

Production build 0.71.5 2024