Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LowerDeez/25d867d21dfa1d3676fa0e3f0556df0c to your computer and use it in GitHub Desktop.
Save LowerDeez/25d867d21dfa1d3676fa0e3f0556df0c to your computer and use it in GitHub Desktop.
Django change translation fallback language
# This is a hack so that French translation falls back to English translation,
# not German translation (which is the default locale and the original
# strings).
from django.utils.translation import trans_real
class MyDjangoTranslation(trans_real.DjangoTranslation):
def _add_fallback(self, localedirs=None):
if self._DjangoTranslation__language[:2] in {'de', 'en'}:
return super()._add_fallback(localedirs)
else:
# Special case for French
if self.domain == 'django':
default_translation = trans_real.translation('en_GB')
else:
default_translation = self.__class__(
'en_GB', domain=self.domain, localedirs=localedirs)
self.add_fallback(default_translation)
trans_real.DjangoTranslation = MyDjangoTranslation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment