How to setup email translation with Django Allauth - django

I am trying to setup translations for emails with django-allauth.
I have rewritten my templates, translated my .po files and complied them.
The html translations work fine but for some reason just the emails don't get translated.
I have properly configured translations following the django tutorial
https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#how-django-discovers-language-preference
The related question doesn't help:
How does email translation work with django allauth?
Package versions:
Django==1.10
django-allauth==0.27.0

I had the same problem with django-allauth==0.32.0 and Django==1.11.1. Translations that are shipped with allauth are simply outdated or incomplete. In my project, for example, an email with a link to reset the password was always in English (in default language LANGUAGE_CODE = 'en') although the user set the language to Czech.
In .po file for Czech translations: https://github.com/pennersr/django-allauth/blob/master/allauth/locale/cs/LC_MESSAGES/django.po#L408 is this e-mail translation marked as fuzzy – so translations are not used. The same applies to other languages I've checked (de, es...).
The reason is explained in this comment from the author of allauth:
The allauth templates are merely meant as a starting point, something
to get you going quickly. Hence, I do not treat issues in the
translations as blocking for release, which can result in translations
getting left behind. Feel free to submit pull requests to fill in the
gaps.
Source: https://github.com/pennersr/django-allauth/issues/1113#issuecomment-141189606
I think there are two ways to solve this issue:
Fix/update translations on https://www.transifex.com/django-allauth/django-allauth/, submit pull request on Github and wait for a new release.
My recommendation: copy all templates from allauth to your project, make your own *.po files and ignore all default translations/templates. Do not forget that e-mail templates are in *.txt so you must call makemessages this way: python manage.py makemessages ... --extension html,txt,py.

Related

django app with different and dynamic translation files

currently I'm working over a task, which require every Django user to have different locale file and translation of course e.g. different translation for the same app.
I'm tried to do some changes on my own scenario and the next lines are finished and works fine but I also met some troubles
whole app is translated on english and german
when I create new user, I copy default translation file .po to new directory related to this user. For this case I made container app which hold all custom translation and directory with schema like this 'apps/trans/locale/user1/', 'apps/trans/locale/user2/' and so on.
these paths are added into settings.LOCALE_PATHS when app is started.
I have implemented rosetta into my Django admin and display correct .po file for all of them (custom .po)
The Django tempalatetags i18n.py was copied into my teplatetags directory and was extended for my purpose
I also want to do some custom modification into django.core.translation module and I also copy this file into my project, but now I do not know how to load this module correctly to override the default Django functionality, because I want to replace the default translation with custom here
for now I use _ _ import _ _ and then I just replace sys.modules['django.utils.translation'] with my module. is this a correct way?
So anyone with idea?
Thanks

Why are some strings in Django .po translated while others not?

This is the first time I used Django localization.
I generated the .po files with makemessages and randomly select a
few strings to fill in the translations, just to check if
localization works.
Then I generate the .mo file with
compilemessages.
I go to the web page and only see a string
'Username' translated, most other strings don't get the translated
version displayed.
What is going on here?
EDIT:
I found out why 'Username' is translated, it used the default translation in Django, but why Django didn't use my mo file is beyond me. I followed all the instructions in i18n doc.
I set the LOCALE_PATHS variable in settings.py to the path for my localization files.
I tried different LANGUAGE_CODE settings 'zh-cn', 'zh_CN'(both the setting variable and the directory name).
I tried msgunfmt django.mo, the file is valid.
There are some lines close to the beginning of po file:
#, fuzzy
msgid ""
msgstr ""
I believe this is normal.
I finally got it working after hours of trial and error.
I change my LOCALE_PATHS from:
LOCALE_PATHS = ("/path/to/locale/");
to:
LOCALE_PATHS = ("", "/path/to/locale/");
And it works right away. Maybe it is a bug with Django 1.5 (which I am using), or maybe I configured something wrong.
Anyway, hope this helps someone, and save you hours of time.
=========EDIT===========
As pointed out by #J.C.Leitão, you have to add comma to make the variable a tuple.
It was a rookie mistake of mine. But I think Django could be more friendly to developers if a single string is recognized, too.

Dajaxice: Having trouble getting Dajaxice working

I know, I know, the first thing you are thinking is to check all of the instructions online and on dajaxproject.com
Well I have checked and checked and rerun this installation and I cannot figure out what the problem is. I assume it has something to do with the version of Dajaxice I am using and the version the installation instructions are, but those details are usually missing.
At this point in the process, I have everything setup to accomplish a very simple task. Load a webpage from the IP:8000 (ie 1.2.3.4:8000) and have that page load a simple html form button. Once that button is pressed, the page should then send a mesage (using dajaxice) to the server, and once it returns an alert box will pop up, proving that the dajaxice install is working.
So, I have:
Installed Dajaxice (and dajax for that matter), by getting the zip from here: github [dot] com/jorgebastida/django-dajaxice/
Changed everything in a basic Django project to follow the details in this tutorial: http://django-dajaxice.readthedocs.org/en/latest/installation.html
I have setup all of the details of ajax.py, and index.html to work with this example: django-dajaxice [dot] readthedocs [dot] org/en/latest/quickstart.html
PS Sorry for the "[dot]"s, but being a new registered user they limit you to 2 per post, so I tried to give you the best links clickable.
I am stumped. I have been trying many different things, but the documentation available seems so sporadic. It's gotta be something simple I am messing up, but I cannot seem to find it.
Currently, the "Say Hello!" button shows up on the screen, but nothing happens when you press it. Any ideas?
Here is a link to the zip file of the Django project I am working with here: https://docs.google.com/open?id=0B5rzYk6W5HlrYk9veVRfM3JkTGc
The way I have it all organized, DjangoAjax is just the folder containing the Django project. ajax_prac is the project, and practice is an app. Also you'll see a folder called django_media...that's pretty self explanatory, it just holds all the "media" for my Django projects, including jquery.js and jquery.dajax.core.js
If there are some details that I have smudged in the code, contrary to the installation guide, I apologize. I have been working through so many iterations of this, that it is likely I could've forgotten to change something back when making this post.
Can anyone help?
All the documentation weirdness is probably related with the new release I made yesterday (8 hours ago). Probably you was using an old version of dajaxice reading the new documentation.
I've release django-dajaxice (0.5) and django-dajax (0.9.1), both fully compatible with the last version of Django (1.4.1).
django-dajaxice: http://pypi.python.org/pypi/django-dajaxice
django-dajax: http://pypi.python.org/pypi/django-dajax
For this release I've also rewrite both documentations and hosted them on readthedocs. Also, http://dajaxproject.com code is now opensource so everybody can read the code and see how dajaxice works in production.
django-dajaxice: http://django-dajaxice.readthedocs.org/en/latest/
django-dajax: http://django-dajax.readthedocs.org/en/latest/
example project: https://github.com/jorgebastida/dajaxproject.com
Could you please upgrade to django-dajaxice (0.5) follow the new installation steps (quite similar http://django-dajaxice.readthedocs.org/en/latest/installation.html) and post here any traceback/issue you could have?
Thanks
In your example code ( DjangoAjax / ajax_prac / templatedirectory / practice / index.html):
<input type="button" value="Send message to server!"
onclick="Dajaxice.ajax.sayhello(my_js_callback);">
Should be:
<input type="button" value="Send message to server!"
onclick="Dajaxice.ajax_prac.practice.views.sayhello(my_js_callback);">
I.e. It must reference a Python module that contains your registered Dajaxice view. And according to your sample code, ajax_prac.practice.views exists while ajax.sayhello does not.
Also the Python module must be prefaced with "Dajaxice" (which is probably a significant source of confusion).

django translation not working by django-rosetta

I have installed the django-rosetta for translation, made .po and .mo files through django command
django-admin.py makemessages -l ar
and translate all words through django-rosetta,
now when i change my language to Arabic from English, it show some words in Arabic and some in English, although i have translated all these words in Arabic,
Have you restarted you web server?
This means your project's labels will be translated right away, unfortunately you'll still have to restart the webserver for the changes to take effect. (NEW: if your webserver supports it, you can force auto-reloading of the translated catalog whenever a change was saved. See the note regarding the ROSETTA_WSGI_AUTO_RELOAD variable in conf/settings.py.
-- http://code.google.com/p/django-rosetta/
What kind of server are you running?
I had the same problem with Apache2 and FastCGI. I had to restart the FastCGI Process to see the modifications.
Have you added the local path properly to your settings?
PROJECT_PATH = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
LOCALE_PATHS = (
os.path.join(PROJECT_PATH, "locale"),
)
Do you have translations marked as fuzzy? (In Rosetta you can filter to display only fuzzy translations.) If some strings are fuzzy, make sure they are properly translated, uncheck the fuzzy flag and save the translations.
Another reason for translations not showing up could be that some python formatting strings (e.g. 'My %s apple') are not properly reproduced in the translated string. If formatting codes are unbalanced Rosetta should warn you, and the actual translation doesn't get written to the file.

django internationalization and translations issue

I have a problem with django translations.
Problem 1 - I updated string in django.po file, but the change does not appear on the webpage.
Problem 2 - I have created my own locale file with django-admin.py makemessages -l et, added the translation string into file, but they too do not appear on the page.
I do not think this is setting problem, because the translations from django.po file do appear on the website, its just the changes and the translations from my own generated file that do not appear.
Edit:
My settings.py contains this:
gettext = lambda s: s
LANGUAGE_CODE = 'et'
LANGUAGES = (
('et', gettext('Estonian')),
)
my own locale files are in
/path/to/project/locale/et/LC_MESSAGES/
and the files are
django.mo and django.po
the file I refer to in problem 1 is django own et transaltion, which I changed.
Well, I got this same error a few moments ago. I solved it deleting the "#, fuzzy" tag over the translation strings in my django.po files. It seems that translated text is not served if it got this tag, so make sure to translate the text and then delete this line.
Here is an example of a translated text not server on a po file:
#: course/models.py:13
#, fuzzy
msgid "code"
msgstr "código"
So, just delete the flag and leave it like this:
#: course/models.py:13
msgid "code"
msgstr "código"
I hope this work for you. Good luck!
Reference: http://share-experiences.com/blog/what-fuzzy-means-python-django-gettext/
PD: I know you got this issue a few month ago, but I leave this response due that you we never heard if you got this problem solved.
Had a same/similar issue with translations not showing up. Setting the LOCALE_PATHS fixed the issue:
# settings.py
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (
'/path/to/djangoapp/locale',
)
Translation files (PO) are loaded in memory only one time, changes to the PO files are not picked up by Django. In order to load the new translation files you need to restart Django (eg. stop/start runserver, Apache or NGINX).
One additional reason for Django translations not working is to compile the .po file with a Python version different than the one being used to run your application. Make sure you use the same version.
Make sure to use ugettext_lazy and not ugettext
If you are using gettext.translation to get the translations, i.e:
text_de = gettext.translation('django', locale_dir, ['de'], fallback=True).ugettext('Welcome to my site')
... and your translation works on the development server but not on production, note that locale_dir must point to your locale directory. It might be located elsewhere on one of the systems. Spent like 2 hrs finding it.
Check for the USE_I18N setting. More info. Anyway, I think by default it's True...