Properly Translated Country Dropdowns
On our eCommerce website, we have clients who come in expecting to have a user experience in their preferred language, of which there are three:- Traditional Chinese
- Simplified Chinese
- English
The problem we are facing here is the fact that the country dropdown in the checkout phase features a bunch of ENGLISH country names mixed into the CHINESE country names.
Here's what I mean. In this example the user has composed a typical order in Chinese:
But clicking on the Proceed to Checkout button (written in Chinese, of course) renders this screen:
WTF? Everything needs to be in Chinese!
Maybe what's happening is the countries are only being "half translated", with a bunch of English entries showing at the top because of the sort order of the dropdown population is in SQL, which counts ENGLISH words as lower id than CHINESE words, thus placing them at the top.
Here's a screenshot of the mixed up country list in Drupal 7 / Ubercart 7.
What's bizarre about this situation is that Hong Kong isn't translated, when it actually is a Chinese place. Weird!
What might be happening is a bunch of untranslated junk entries are filling the dropdown.
So how do we fix this?
Looking under the hood, here's the table schema of the uc_countries table:
+--------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+------------------+------+-----+---------+-------+
| country_id | int(10) unsigned | NO | PRI | NULL | |
| country_name | varchar(255) | NO | MUL | | |
| country_iso_code_2 | char(2) | NO | | | |
| country_iso_code_3 | char(3) | NO | | | |
| version | smallint(6) | NO | | 0 | |
+--------------------+------------------+------+-----+---------+-------+
Looking at the entry for Hong Kong in the uc_countries table, I found this:
| 344 | Hong Kong | HK | HKG | 1 |
Again, everything looks fine to me. Standard ISO codes are being used
So this really looks like some countries simply haven't been translated to Chinese (yet), and are therefore failling through the code to show up in the dropdown, untranslated.
So, is this why Hong Kong is not being translated properly to 香港?
Let's have a look at the Translate Interface to find out.
Aha!
The string Hong Kong was untranslated - so let's translate it:
Now, the translated term for Hong Kong shows up in the dropdown in Ubercart....yaay!
So the way to fix this problem is to get the translation strings for the all the untranslated countries loaded into Drupal 7 via the Translate Interface....hmmm
All 29 of them.
Here they are, including the incredibly bizarre Nauru (諾魯) entry, which should by all rights be impossible, considering it's a mixed translation case.
Bolivia, Plurinational State of
Bonaire, Saint Eustatius and Saba
Brunei Darussalam
Congo
Congo, the Democratic Republic of the
Côte d'Ivoire
Falkland Islands (Malvinas)
Heard Island and McDonald Islands
Holy See (Vatican City State)
Hong Kong
Iran, Islamic Republic of
Korea, Democratic People's Republic of
Korea, Republic of
Lao People's Democratic Republic
Macau
Micronesia, Federated States of
Moldovoa, Republic of
Nauru (諾魯)
Palestinian Territory, Occupied
Russian Federation
Réunion
Saint Helena, Ascension and Tristan da Cunha
Syrian Arab Republic
Taiwan, Province of China
Tanzania, United Republic of
Venezuela, Bolivarian Republic of
Viet Nam
Virgin Islands, British
Virgin Islands, U.S.
Åland Islands
Some of these countries are of little size or consequence (Virgin Islands, U.S.) but others are seriously important and big places (Iran, Islamic Republic of ) or spots with equally a heavy-duty economy and top-tier global standing (Hong Kong).
So, we need a way to add 29 country translations because they are missing in the .po files.
Checking a Country Translation Entry
Seeing as I fixed the entry for Hong Kong already, let's reproduce the error with another country we might be selling into one day: VietnamFirst, let's check to see if this string is present in the String Translations database, the interface to which is located at:
Executing the query, we get the following response:
OK, let's enter the information for it in the interface
And then check the translation status:
What does a .po file look like?
The format of .po files are pretty simple. Here's an example:msgid "Hong Kong S.A.R., China"
msgstr "香港特别行政区,中国"
In the above example, the string Hong Kong S.A.R., China would be replaced by 香港特别行政区,中国 if the site was appropriately configured to be multilingual.
Our problem is that the strings that don't translate in the Ubercart checkout screen are not included in the .po file for Simplifed Chinese (zh-hans) or Traditional Chinese (zh-hant)
Let's make an entry for one of the other untranslated entries: Viet Nam
Traditional Chinese
msgid "Viet Nam"
msgid "越南"
msgid "Viet Nam"
msgid "越南"
REFERENCES
https://www.drupal.org/project/addressfield/issues/1405336
https://drupal.stackexchange.com/questions/214803/way-to-programmatically-add-string-translations
No comments:
Post a Comment