I want to create a Django 2.0 powered website(including auto generated Admin site) that should support multiple languages.
For now I only want to keep 2 languages English and Arabic.
I read number of tutorials articles on web to use django-admin's makemessages and compilemessages commands to generate language files(.po files) & compile .mo files(generated by makemessages command).
But I did not get any specific solution regarding this integration using Django2.0 and still I am facing the issue.
Can anyone please help me in solving this problem.
And also suggest how will I make it for English to Arabic translation.
Now I got the solution of question, I am explaining it one by one.
As I want to translate my
model names,model field names, some othertextsavailable in modules and somestatic/dynamic textspresent in my Django template.Let's assume, I have the
models.pyandindex.htmlas follows.models.py
index.html
Now, I need to place translation texts in my
modulesandtemplates. I want my Django application to supportArabic&English.models.pyandindex.htmlas follows.models.py
index.html
In settings.py, add the following(In my case I created folder named
localeinsideBASE_DIRyou can choose another location and specify the location insettings.py).Run the
makemessagescommand from any one of the 2 places based on the requirement as the command looks for the translation texts through all the child directories from which it is run.a. Project's root directory where
manage.pyresides.b. App's root directory where
models.py,views.pyresides.Click here to check the language codes
The above command will create a directory named
arinsidelocaledirectory with the following folder structure.In my case,
django.pocontains the following lines.Now, fill the value of
msgstras the Arabic translation of the English string denoted bymsgidas follows.Now run the
compilemessagesfrom the same directory as mentioned above, it will generatedjango.mofile.django-admin.py compilemessagesThe directory structure of
loacledirectory will look like this.Start the development server using
python manage.py runserverVisit http://127.0.0.1:8000/en/admin/ to view/access the
Englishbased Admin site. You will see the login page like below.Visit http://127.0.0.1:8000/ar/admin/ to view/access the
Arabicbased Admin site. Now, you will see the login page like below.Add as many as translation texts to
modulesandtemplates, do proper configurations insettings.py, execute commands from proper place, choose proper language code and enjoy themultilingual supportin yourDjango poweredwebsite.References:
how to use django-admin.py makemessages --all
https://docs.djangoproject.com/en/2.0/topics/i18n/translation/
Localization: How to Create Language Files