question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django 1.8 get_language returns None

See original GitHub issue

Django 1.8 changed the default behaviour of get_language:

Returns the currently selected language code. Returns None if translations are temporarily deactivated (by deactivate_all() or when None is passed to override()).

Changed in Django 1.8:
Before Django 1.8, get_language() always returned LANGUAGE_CODE when translations were deactivated.

Now, when fetching objects without specifying the language language_code is no longer populated:

print Colour.objects.language('en-gb').all()[0].language_code
>>> 'en-gb'
print Colour.objects.all()[0].language_code
>>> None

And I cannot create objects on the shell:

c = Colour.objects.create(name='Black', slug='black')
>>> IntegrityError: (1048, "Column 'language_code' cannot be null")

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
vdboorcommented, Aug 23, 2016

For now, you’re required to manually activate the translations:

from django.utils import translation
translation.activate(settings.LANGUAGE_CODE)

we’re a bit cautious to allow working with translations without having an language activated, it brings parler into untested territory.

1reaction
yakkycommented, May 4, 2016

I guess that supporting this transparently it’s a bit of a nightmare, and probably it will mean going too far I think that one of the best point of parler is that it uses very little magic (comparing to hvad) and does very little “transparently” This helps a lot in being simpler to use and it poses far less restrictions than other “magical” solutions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get the current language in Django? - Stack Overflow
Caveat: Returns None if translations are temporarily deactivated (by deactivate_all() or when None is passed to override()). Before Django 1.8, get_language() ...
Read more >
Translation | Django documentation
This emulates the gettext function but does nothing, returning whatever is passed to it: document.write(gettext_noop('this will not be translated ...
Read more >
solid_i18n - PyPI
Use default language for urls without language prefix (django) ... If True, redirect to url with non-default language prefix from url without prefix, ......
Read more >
Python get operations - ProgramCreek.com
SetValue(None, dynamic_operations) return ClrClass.dynamic_operations_field ... if you upgrade Django to 1.8 having already applied this migration in 1.7.
Read more >
Locale | Android Developers
Use getCountry to get the country (or region) code and getLanguage to get the ... Returns a locale for the specified IETF BCP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found