Re: Django template translation not working as expected

2019-01-10 Thread shiva kumar
Can you explain what are django translation

On Thu 10 Jan, 2019 11:59 pm Ashutosh Das  I am using django 2.1 , here is all the settings related to translation:
>
>
> MIDDLEWARE = [
> 'corsheaders.middleware.CorsMiddleware',
> 'django.middleware.security.SecurityMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.locale.LocaleMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> 'debug_toolbar.middleware.DebugToolbarMiddleware',]
>
> LANGUAGE_CODE = 'en'
>
> LANGUAGES = (
> ('en', _('English')),
> ('bn', _('Bengali')))
>
> LOCALE_PATH = (
> os.path.join(BASE_DIR, 'locale'))
>
> TIME_ZONE = 'Asia/Dhaka'
>
> USE_I18N = True
>
> USE_L10N = True
>
> USE_TZ = False
>
> Template tag that I want to translate:
>
>
> {% load i18n %}
>   {% trans "About Us" %}
> I run both ./manage.py makemessages --all ./manage.py compilemessages
> commands , also added translation in .po file after makemessages command:
>
>
> # locale/bn/LC_MESSAGES/django.po#: templates/partials/footer.html:8
> msgid "About Us"
> msgstr "আমাদের সম্পর্কে"
>
> When I changed the language code from en to bn, template string still
> rendering the default english "About Us".
>
> Here are all the codes that I am using for changing language:
>
>
> 
> {% get_current_language as LANGUAGE_CODE %}
> {% if LANGUAGE_CODE == 'en' %}
> ENGLISH
> {% else %}
> বাংলা
> {% endif %}
> 
> 
> ENGLISH
> বাংলা
> 
> 
>
>
> views.py :
>
>
> def change_lan(request):
> allowed_lan = ('en', 'bn')
> get_lan = request.GET.get('lan', 'en')
> if get_lan in allowed_lan:
> translation.activate(get_lan)
> request.session[translation.LANGUAGE_SESSION_KEY] = get_lan
> return redirect(request.META.get('HTTP_REFERER', '/'))
> else:
> return redirect(request.META.get('HTTP_REFERER', '/'))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3ed3c00a-148e-4817-a470-bada1af10ba3%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMsYeuG%3DB65MCOZAz-z3x40iB94jG4HmR2TY-8Ma3siycQ7EJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django template translation not working as expected

2019-01-10 Thread Ashutosh Das
 

I am using django 2.1 , here is all the settings related to translation:


MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',]

LANGUAGE_CODE = 'en'

LANGUAGES = (
('en', _('English')),
('bn', _('Bengali')))

LOCALE_PATH = (
os.path.join(BASE_DIR, 'locale'))

TIME_ZONE = 'Asia/Dhaka'

USE_I18N = True

USE_L10N = True

USE_TZ = False

Template tag that I want to translate:


{% load i18n %}
  {% trans "About Us" %}
{% get_current_language as LANGUAGE_CODE %}
{% if LANGUAGE_CODE == 'en' %}
ENGLISH
{% else %}
বাংলা
{% endif %}


ENGLISH
বাংলা

 


views.py :


def change_lan(request):
allowed_lan = ('en', 'bn')
get_lan = request.GET.get('lan', 'en')
if get_lan in allowed_lan:
translation.activate(get_lan)
request.session[translation.LANGUAGE_SESSION_KEY] = get_lan
return redirect(request.META.get('HTTP_REFERER', '/'))
else:
return redirect(request.META.get('HTTP_REFERER', '/'))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ed3c00a-148e-4817-a470-bada1af10ba3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.