How to translate django-allauth templates? - django

I've already translated my project in Malagasy (mg_Mg) but when installing django-allauth and override templates, translation won't be applied.
After python manage.py makemessages, python manage.py compilemessages and testing some translations eg: sign up -> Hisoratra anarana in render it show sign up.
But in my local app, all templates are translated correctly.
In config/setting.py
import environ
BASE_DIR = environ.Path(__file__) - 2
...
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = [
('en-us', 'English'),
('fr-fr', 'French'),
('mg-mg', 'Malagasy'),
]
LOCALE_PATHS = [BASE_DIR('locale')]
In fandaharana/views.py
def month(request, month_num, year_num):
translation.activate('mg-mg')
...
return render(request, 'month.html', data)

Related

django admin automatic rtl for some languages

I'm trying to add multi language support for a django project using Django i18n official documentaion:
https://docs.djangoproject.com/en/4.1/topics/i18n/translation/
When I change the LANGUAGE_CODE to something like 'fa', by default the admin panel changes to RTL.
But the problem is when I use other RTL languages like 'ku' (kurdish) the page remains in ltr.
I know we can change the css manualy, but wonder what is the problem here and how some languages like Arabic or persian does the RTL part automaticaly but others dont.
Thanks in advance
# settings.py
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True
TIME_ZONE = 'UTC'
USE_TZ = True
LANGUAGES = (
('en', _('English')),
('ku', _('Kurdish')),
('fa', _('Persian')),
)
LOCALE_PATHS = [
Path(BASE_DIR, 'django_i18n', 'locale'),
]
# url.py
urlpatterns = i18n_patterns(
path('admin/', admin.site.urls),
) +static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
just found the answer here:
https://github.com/django/django/blob/main/django/conf/global_settings.py#L158
So all I had to do was add this to setting.py:
LANGUAGES_BIDI = ["ku",]

django settings default time zone

here is a question i can use django time zone for utc and it worked fine
but when i switch the default time zone to 'Asia/Tehran' it wont work and i get the error
ValueError: Incorrect timezone setting: ASIA/TEHRAN
the actual code in settings.py is:
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Tehran'
USE_I18N = True
USE_L10N = True
USE_TZ = True
and it is on django time zone list i checked it
the system is ubuntu 20 and django version is 3.2
try this
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC+3:30'
USE_I18N = True
USE_L10N = True
USE_TZ = True

How to set the default language for all users or browsers

There are two working versions of the translation on the site - Russian and English using i18n. How to make sure that everyone has a website loaded in Russian and then, at the request of the user, he can change it to English?
MIDDLEWARE = [
...
'django.middleware.locale.LocaleMiddleware',
...
]
LANGUAGE_CODE = 'ru'
LANGUAGES = (
('ru', _('Russian')),
('en', _('English')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
TIME_ZONE = 'Europe/Kiev'
USE_I18N = True
USE_L10N = True
USE_TZ = True

Admin Site shows the timezone wrong

Trying my hands on Django. TIME_ZONEat admin module shows different than the local time. I would like to edit the time according to the current time. Which Django file should I edit to synchronize the time?
I tried the documentation on official Django website but did not help me out.
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
```
On your settings.py, add a TIME_ZONE config:
E.G:
TIME_ZONE = "UTC"
or
TIME_ZONE = "America/Boise"
Plus, enable USE_TZ:
USE_TZ = True
You can read more here

translation not working in Django 1.5 even after compiling message

I'm using Django 1.5
I have to enable internationalization in my application. For that, I have added a few things to the settings.py file
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
)
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'...local context processrors...'
)
# global_settings.TEMPLATE_CONTEXT_PROCESSORS contains
# TEMPLATE_CONTEXT_PROCESSORS = (
# 'django.contrib.auth.context_processors.auth',
# 'django.core.context_processors.debug',
# 'django.core.context_processors.i18n',
# ...
# )
USE_I18N = True
USE_L10N = True
LANGUAGE_CODE = 'es'
# List of languages available for translation
ugettext = lambda s: s
LANGUAGES = (
('en', ugettext('English')),
('es', ugettext('Spanish'))
)
LOCALE_PATHS = (
os.path.join(PROJECT_ROOT, 'locale/'),
)
The LOCALE_PATHS has the location output as
('/media/path_to_project/workbench/workbench/settings/../locale/',)
But on running ./manage.py makemessages -l es it generates *.po file in
/media/path_to_project/workbench/workbench
instead of
/media/path_to_project/workbench/workbench/locale
Also, the compiled language is not showing in the template.
You need to check following things.
Ensure that you added USE_L10N = True and USE_I18N = True into your settings.py file
Check for PROJECT_ROOT and LOCALE_PATHS and make sure that it is correct
Add django.core.context_processors.i18n to TEMPLATE_CONTEXT_PROCESSORS in setting.py.
Translation and formatting are controlled by USE_I18N and USE_L10N settings respectively. However, both features involve internationalization and localization. The names of the settings are an unfortunate result of Django’s history.