Hi guys,

i´ll explain my problem with a scenario. I hope it gets clear for you:

- Multilingual D7-Setup (EN + DE as default-language)

When i install the countries module with the previous settings i only get the field (and all the countries) in german, not in english.
But when i install the countries module with english as default-language i only get the field (with countries) in english, not in german.

Any ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

Component: Countries I18n » Code
Category: support » task
Status: Active » Needs review
FileSize
2.17 KB

This is by design as the strings are imported and treated as user data that should not override the default strings supplied by drupal. So set the default language to German and you will get country names returned in German due to the use of t() when defining this list in core. All other values will be imported in English (official names column)

Since the countries data file is (almost) static, we could run these values through t() during the import / update so that if there are available translations, the database would be populated with the correct (i.e. current) language.

I'll let webflo respond too, but this solution would be something like:

# countries.install
function countries_import_csv() {
....
      $countries[$row[0]] = array(
        'iso2' => $row[0],
        'iso3' => $row[1],
-        'name' => $row[2],
-        'official_name' => $row[3],
+        'name' => t($row[2]),
+        'official_name' => t($row[3]),
        'numcode' => $row[4],
        'continent' => $row[5],
        'enabled' => $row[6],
      );
....
}

Completely untested patch attached

Status: Needs review » Needs work

The last submitted patch, countries-t-function-for-imports.patch, failed testing.

Alan D.’s picture

[edit] Wrong thread.

firfin’s picture

Re-rolled to make it patch successfully.
Also made some small changes:
- As we already do $key = $headers[$index]; above changed the elseif statement to use $key (instead of $headers[$index] )for readability.
- removed a typo

firfin’s picture

Status: Needs work » Needs review

forgot to set status :-(

Status: Needs review » Needs work

The last submitted patch, countries-t-function-for-imports-1490864-4.patch, failed testing.

firfin’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, countries-t-function-for-imports-1490864-4.patch, failed testing.

firfin’s picture

Version: 7.x-2.0-beta2 » 7.x-2.x-dev
Status: Needs work » Needs review

Patched against dev of course, oops.

firfin’s picture

Status: Needs review » Needs work

The last submitted patch, countries-t-function-for-imports-1490864-4.patch, failed testing.

Alan D.’s picture

+ // Enable translation of country names during importation.
+ $value = t($value);

This doesn't assign the value and thus appears to completely break the import. Move to the last else in the statement where the value is assigned

Alan D.’s picture

ie:

         else {
+        if ($key == 'name' || $key == 'official_name') {
+          // Enable translation of country names during importation.
+          $value = t($value);
+        }
           $country->$key = $value;
         }
firfin’s picture

Status: Needs work » Needs review
FileSize
2.3 KB

Alan D.++
You are absolutely correct.
I corrected my mistake and tested locally.
No more errors, seems to be okay now.
Any other improvements needed?

Alan D.’s picture

Minor mods, will push if I get the green light (too lazy to manually test and there are very detailed tests for this)

Alan D.’s picture

Alan D.’s picture

Status: Needs review » Fixed

Thanks Marck - committed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.