coderholic / django-cities

Countries and cities of the world for Django projects
MIT License
921 stars 375 forks source link

Request: List in native language #97

Closed stantond closed 7 years ago

stantond commented 9 years ago

Would an option to provide the list of countries with all names in their main language be feasible?

coderholic commented 8 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.

blag commented 7 years ago

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 JOINs 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.

blag commented 7 years ago

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!