Created
September 24, 2018 11:18
-
-
Save jonashaag/c69b5213d18b2fd8da1ef7b0ee61b9f8 to your computer and use it in GitHub Desktop.
Django change translation fallback language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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