After apply #1415284: Countries in profile select-list not translated #10 patch on edit form translated country names are displayed.

I can translate country names one-by-one on admin/config/regional/countries/XX/translate. Is there any procedure/possibility to load the translated names for each language?

Comments

fraweg’s picture

Hello,

I am interested in such a feature too. There should be a list witch can be imported. So after that not every user should have the work to translate it. With many people this list can be final quick...

Best regards
Frank

nlambert’s picture

I haven't looked into the subject, but I did notice that countries implements hook_feeds_processor_targets_alter.

I can only imagine that feeds must be the foreseen solution.

drzraf’s picture

In #1843958: countries i18n database I talk about a free database I found.
In #1843996: snippet to convert text field to country field I provided a snippet to parse these (simple) YAML files (using pecl-syck).

So now what's left is:

  • either convert this to a po file loadable in the "country" textgroup of Drupal
    • find, if possible, a PHP po-writer class to ease the job
  • either insert directly into the Drupal DB (i18n tables)

related: #1830198: Better support for various providers of Country data. (let's close one of them ?)

drzraf’s picture

I'm in favor of direct DB use because people may have several languages.
Each one needs uploading a po-file what could be painful, especially since no drush command exists today for that job.

attisan’s picture

I'm still wondering why this all is necessary. to my understanding and knowledge all the country names are already translated in the according core language .po file.

however, installing countries module still leaves out the opportunity to simply grab all those present translations and instead asks for his own set of translations? this might be due to the veeeery obscure way drupal7 handles translations (using some sort of context - which, at least, I'm unable to put to some sort of use) but it feels clunky none the less.

still worse, after installing countries module other translations regarding country names seem to fail all together, simply showing the native form no matter my language choice. (after uninstalling countries / countries translation the translations came back).

perhaps it would be better to have some way of entity translating (using the power of entity translation) each country and not to use the legacy i18n module.

greets

ps.: this module IS very useful - as long as one isn't using a multilingual webpage.

alan d.’s picture

Status: Active » Closed (duplicate)
estebant’s picture

Issue summary: View changes
StatusFileSize
new50.73 KB
new50.29 KB
new4.98 KB

This is the procedure I followed:

* Go to: Configuration » Regional and language » Translate interface » Export
Select the Language you want, and "Text group": Countries

* You will obtain a "template" of the .po file, with all the names of the countries ready to be translated.
Then manually translate them. For me the field "name" was enough, ignoring the "official_name", and only those countries whose name in English is different from the name of the desired language.
You can get the translations of the countries names, for example here:
https://github.com/onomojo/i18n-country-translations/tree/master/rails/l...
where you also have the country codes, that may be useful if you are not familiar with the language you want to translate.

* Once you have the .po ready, go to: Configuration » Regional and language » Translate interface » Import
Select the file, the language, and "Text group": Countries

* Now you have the strings stored in the database.
By the way, it would be really interesting to have a repository where the people can leave their own .po files, to avoid everybody has to do the above steps.
I attach the files I created for Spanish and for Vietnamese languages, they may be useful for somebody.

1) To show the translated string of the field in the View mode, you must select Format = "Default translated" in the Manage display section of the content type.
2) To show the translated value in the dropdown list when creating/editing the content, you can apply this patch in countries.fields.inc

/**
 * Returns a set of valid countries of a countries field.
 */
function countries_allowed_values($field) {
  $countries = countries_get_countries('name', $field['#filters']);
  
+  global $language;
+  if($language->language != 'en') {  
+    $countries_aux = Array();
+    foreach($countries as $key => $value) {
+      $countries_aux[$key] = t($value);  
+    }
+    asort($countries_aux);
+    $countries = $countries_aux;
+  }

  // Allow other modules to update this list.
  countries_invoke_additional_countries_alter($countries);

  return $countries;
}
dpico’s picture

@estebant Thank you very much for sharing your solution and your .po files! I can't download the Spanish .po file, that would save me a fair amount of time to generate. I can't download it, though. I get a "You don't have permission to access /files/issues/countries-names.es_.po on this server." error. Would you upload them again, please? I wonder why I'm not having the permissions. I'm a registered user, etc.

estebant’s picture

StatusFileSize
new50.73 KB

Hola David,
I upload it again, if you have any problem, send me an email to estebantejedor@yahoo.es

alan d.’s picture

maybe upload as iso2.txt?

estebant’s picture

StatusFileSize
new50.73 KB

There we go

alan d.’s picture

That one works. So strange. The po extension must not be trusted :(

Thanks!

estebant’s picture

Good :)

sano’s picture

StatusFileSize
new51.48 KB

po file for Slovakia - only "familiar" names of countries are listed.

sano’s picture

StatusFileSize
new8.17 KB

Hmm, as per above, .po files must be uploaded with a different extension. Here is the Slovakia file zipped.