Skip to the content
Documentation

Translatable country names

No ratings yet

Lists of countries, such as the select of a country attribute (the ezcountry datatype), the shop's account form and the VAT rules, show the country names in the language of the siteaccess's locale: "Frankrike" and "Norge" on a Norwegian siteaccess instead of "France" and "Norway".

Where the names come from

The list of countries, with their codes and other properties, is settings/country.ini. The translated names are in the group [CountryNames] of the locale file of the siteaccess's [RegionalSettings] Locale, keyed by the two-letter ISO 3166 code:

# share/locale/nor-NO.ini (shipped)
[CountryNames]
Countries[AD]=Andorra
Countries[AE]=De forente arabiske emirater
Countries[AF]=Afghanistan

In 6.0.15 most locale files ship with a full [CountryNames] group, so translated names need no work. A country without a name in the locale keeps its name from country.ini. The list is sorted by the translated names.

Changing names

Do not edit a shipped locale file. Create a variation of the locale and use it as the locale of the siteaccess. A [CountryNames] group in the variation replaces the whole list of the locale (eZLocale::initCountry()), so copy the complete group from the locale file into the variation and change the names you want there; the example shows only two lines of it:

# share/locale/[email protected]
[CountryNames]
Countries[FR]=Frankrike
Countries[NO]=Noreg
# settings/siteaccess/no/site.ini.append.php
[RegionalSettings]
Locale=nor-NO@custom

Then clear the INI caches (php bin/php/ezcache.php --clear-tag=ini). See Configuring your site locale for variations.

The grouped list

Since 6.0.15 every country select shows two groups: the most used countries first, then all countries from A to Z by their translated name. See The grouped country list.

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.