Closed stantond closed 7 years ago
It's possible to do this, but not currently very easy.
For each country you can get the languages spoken in that country, eg:
>>> Country.objects.get(code='ES')
<Country: Spain>
>>> country.languages
u'es-ES,ca,gl,eu,oc'
You can then get the name in the most popular language doing something like:
country.alt_names.filter(language=country.languages.split(',')[0].split('-')[0])
That could return multiple results (or none) though.
One of the languages packages for Django might help with this.
If you'll forgive me advertising my own package, check out django-world-languages.
You will still need to have the database compare two letter language codes between cities.AlternativeName.language_code
and world_languages.Language. iso639_1
1, but you should be able to do the rest of the JOIN
s with foreign keys.
Also, just curious, but how do you want to handle countries that have more than one main language (Canada: English and French)? Get the name in both languages or pick one language over the other?
1 Or world_languages.Language. iso639_2t
, world_languages.Language. iso639_2b
, or world_languages.Language. iso639_3
, depending on what you want.
Since this is possible with a custom manager, I'm closing this issue. Feel free to reopen it if you run into issue or have any further questions. Cheers!
Would an option to provide the list of countries with all names in their main language be feasible?