-
-
Save iKlotho/ef633e4eba7b7d1aff13742eb18e6e73 to your computer and use it in GitHub Desktop.
i18n django
This file contains hidden or 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
#django muti language | |
#add settings.py middleware | |
'django.middleware.locale.LocaleMiddleware', | |
#add settings.py | |
from django.utils.translation import ugettext_lazy as _ | |
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),) | |
LANGUAGES = ( | |
('tr', _('Turkish')), | |
('en', _('English')), | |
) | |
#create the "locale" folder in the root directory | |
#execute | |
django-admin.py makemessages -l tr | |
django-admin.py makemessages -l en | |
django-admin.py compilemessages | |
#add views.py | |
def language(request, lang_code): | |
translation.activate(lang_code) | |
request.session[translation.LANGUAGE_SESSION_KEY] = lang_code | |
return HttpResponseRedirect('/') | |
#add template file | |
{% load i18n %} | |
{% get_current_language as LANGUAGE_CODE %} | |
#example usage | |
{% trans "Dashboard"%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment