SmileyChris / django-countries

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Home Page:https://pypi.python.org/pypi/django-countries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change country order based on user language

HenryMehta opened this issue · comments

I have a Django app which django-countries. I would like to alter the order of the countries shown based on the user's language. For example if the user is using French, I will bring France, Belgium, Luxumburg, Switzerland etc to the top, whereas if they select German I will bring up Germany, Austria, Switzerland etc.

I can set COUNTRIES_FIRST = ['FR','BE','LU','CH'] within settings, but that ordering is then used for all user languages.

Is there a way to base the order on the user's language?

I have tried modifying the COUNTRIES_FIRST within a view, for example

    if self.administration_instance.study.instrument.language == 'French':
        settings.COUNTRIES_FIRST = ['FR','CH','BE','LU']
    translation.activate(self.user_language)

But this clearly doesn't work

There's not a way at the moment to have the countries_first ordered by user language. It'd be an easy addition with a new setting if someone wanted to tackle it!