Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when get_language returns None in Django 1.8 #14

Open
blodone opened this issue Jul 15, 2015 · 4 comments
Open

Fails when get_language returns None in Django 1.8 #14

blodone opened this issue Jul 15, 2015 · 4 comments

Comments

@blodone
Copy link

blodone commented Jul 15, 2015

When get_language returns None (supported in Django 1.8)

lang = get_language().split('-')[0] 

fails

@colinkingswood
Copy link

I get the same error (Django 1.9)

@colinkingswood
Copy link

Me too, Django1.9

@nakul-narayanan
Copy link

I'm getting the same error (Django 1.11), can someone help me to resolve it ?

@willmtl
Copy link

willmtl commented Aug 25, 2017

I ended up creating my own method with fallback to the default language.

def get_language():
     lang = django_get_language()
     if lang:
         return lang
     else:
         return settings.LANGUAGE_CODE
 def get_real_fieldname(field, lang=None):
     if lang is None:
         lang = get_language()
         lang = lang.split('-')[0]  # both 'en-US' and 'en' -> 'en'
     return str('%s_%s' % (field, lang))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants