Page 1 of 1

Country and state list Translation

Posted: Wed Mar 11, 2020 1:36 am
by nudylady
I added a language pack. But country and state list are not translated. How to translate them?

Re: Country and state list Translation

Posted: Wed Mar 11, 2020 1:47 am
by Quino
default you cannot as those are stored in the database, not files, and those tables do not come with a language_id.

Re: Country and state list Translation

Posted: Wed Mar 11, 2020 7:33 am
by nudylady
is there any extension or instruction can do this?

Re: Country and state list Translation

Posted: Wed Mar 11, 2020 8:58 am
by sw!tch
Admin ->System -> Localisation -> Countries
Admin ->System -> Localisation -> Zones

As mentioned they are not language dependent so keep that in mind.

Re: Country and state list Translation

Posted: Wed Mar 11, 2020 5:25 pm
by letxobnav
depends on how many languages you have now and in the future.

I only have two so I just added a column to the country and zone tables for those names and changed the original name column to name_en.
name_en and name_zh, using the _language-code appendix.
If you have many languages, it would become more economical to put the name in a separate table.


then in model localization country I altered the queries (to select that name field based on language code) from

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE country_id = '" . (int)$country_id . "' AND status = '1'");
to

Code: Select all

$query = $this->db->query("SELECT country_id,name_".$this->language->data['code']." as name,iso_code_2,iso_code_3,address_format,postcode_required, status FROM " . DB_PREFIX . "country WHERE country_id = '" . (int)$country_id . "' AND status = '1'");
and

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE status = '1' ORDER BY name ASC");
to

Code: Select all

$query = $this->db->query("SELECT country_id,name_".$this->language->data['code']." as name,iso_code_2,iso_code_3,address_format,postcode_required, status FROM " . DB_PREFIX . "country WHERE status = '1' ORDER BY name DESC");
so the rest of the code remains the same, the queries just return the name in english or chinese depending on the current language code.

same principle for the zones
You just have to remember that if you add a language, you also have to add a column with the name+language code appendix to those tables or you will get an sql error.