1

I need to get the user's current locale name as part of some internationalization proccess of a specific plugin, in the format ll_CC (like pt_BR, en_US, pl_PL), as described at https://docs.djangoproject.com/en/dev/topics/i18n/ inside of a Django template. I've been able to get only the language code so far (which is in the format pt-br, en-us, pl) using:

{% load i18n %}
{% get_current_language as LANG %}
Your language is: {{ LANG }}

But I need the locale name. How can I get this? Thank you very much.

Bruno Finger
  • 2,105
  • 3
  • 27
  • 47
  • 2
    Have you looked at [this question](http://stackoverflow.com/questions/6361858/django-display-current-locale-in-a-template) – NT3RP Mar 20 '13 at 21:35
  • I didn't try this link that you mentioned, but I also found it before.. Anyway I found my own solution: As I'm already using Django to translate the pages, I just marked the place that I need to get the locale to be translated as well, for example, I have in the template `//connect.facebook.net/{% trans "pt_BR" %}/all.js#xfbml=1` and then I just need to translate this with the rest, and will change automatically as Django detects the browser's language. – Bruno Finger Mar 23 '13 at 01:24
  • what an ackward salution when django gives the tools you need – maazza Jun 07 '13 at 07:42
  • @NT3RP I looked at that, but the accepted answer appears to not answer the question at all. – kasperd Sep 10 '15 at 16:58
  • @BrunoFinger I'm working with a code base where a previous developer has used roughly the same hack. I was hoping to find a cleaner solution, but if I don't I'll probably copy that hack to even more locations. – kasperd Sep 10 '15 at 17:01
  • Well, this question is more than 2 years old and, actually rereading it now I feel somehow embarrassed of this solution I used. I'll see if there's another way, maybe with Django's current version it's possible to do this in a more correct way now. – Bruno Finger Sep 10 '15 at 21:22

0 Answers0