The problem:
When creating a CSV-export of multi-lingual content using Views, the field "Content: Language" does not give the option to use the language code, but only the English or native name. This results in issues like this one, because the imported field does not contain the ISO code that Drupal recognizes as a valid language, but the language name.
Solutions would be possible in several modules:
- In Views (would make the most sense, as the data to be imported usually gets generated here): Make "Language code" available as one of the output options of "Content: Language" (see http://drupal.org/node/1222204).
- In Feeds: see http://drupal.org/node/840142 (since 2010).
The Feeds Tamper solution:
The solution here is provided in the form of a plugin. It simply replaces the language name with the corresponding code at import. If that fails or the language field is empty , "und" (undefined) will be used, resulting in "Language neutral".
Just rename the attached file to language_to_code.inc and place it in the modules/feeds_tamper/plugins folder.
After that a new plugin "Language to ISO code" is available, obviously to be applied on a field with English language names.
A more sophisticated piece of code might be possible using the Drupal API:
$languages = language_list('enabled');
that returns a list of installed languages. I didn't look into that.
Resources:
Along the way I wrote a small reference article with a list of languages used in Drupal. Feel free to copy and paste it somewhere in the Drupal documentation (leave a cross-link here), as I couldn't find it there.
Comment | File | Size | Author |
---|---|---|---|
language_to_code.txt | 3.78 KB | lolandese |
Comments
Comment #0.0
lolandese CreditAttribution: lolandese commentedBolded the action required to apply this solution.
Comment #0.1
lolandese CreditAttribution: lolandese commentedReadability enhancement
Comment #0.2
lolandese CreditAttribution: lolandese commentedClarified the use.
Comment #1
lolandese CreditAttribution: lolandese commentedChanged status. Forgive me for not providing a patch, as it is just a one file plugin addition (no alteration of existing code).
Comment #1.0
lolandese CreditAttribution: lolandese commentedEmphasize what needs to
Comment #2
lolandese CreditAttribution: lolandese commentedNo objections for some time, thus changing status.
Comment #3
twistor CreditAttribution: twistor commentedWe should definitely load the language list from Drupal and not hardcode it in the plugin.
I'm not sure why you RTBC'd your own issue without anyone reviewing it.
Comment #3.0
twistor CreditAttribution: twistor commentedClarification of application