Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template localization doesn't work completely #786

Closed
dariaemacs opened this issue Apr 5, 2017 · 26 comments
Closed

Template localization doesn't work completely #786

dariaemacs opened this issue Apr 5, 2017 · 26 comments
Labels
area: backend This issue involves Python, Django or dependency (eg. database) area: localization bug

Comments

@dariaemacs
Copy link

dariaemacs commented Apr 5, 2017

Hello, guys!
I don't know this is the issue or this is my fault.
I tried to localize Misago forum.
I added new locale with django-admin.py makemessages -l ru

The localization of the templates doesn't work completely (the part of text translated). I changed django.po file:

/usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES/django.po

I made django-admin compilemessages and I see

processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES
processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/en/LC_MESSAGES    
processing file djangojs.po in /usr/local/lib/python2.7/dist-packages/misago/locale/en/LC_MESSAGES

When I reload the forum page I see my changes in during one second, but after all becomes the same as before. Web browser developer console shows that forum files were reloaded (Status 200, not 304).

This is the view of the forum page while it's loading. Right translations I marked red circles:
in during loading

This is the page after loading. I marked changing places:
after loading

The part of my ru/LC_MESSAGES/django.po

#: templates/misago/admin/index.html:81
#: templates/misago/admin/users/delete.html:36
#: templates/misago/admin/users/list.html:23
#: templates/misago/profile/posts.html:4
msgid "Posts"
msgstr "Сообщения"

#: templates/misago/profile/posts.html:35
msgid "You have posted no messages"
msgstr "У Вас нет ни одного сообщения"

For Javascript file I made the same localization.
Please, tell me why this happened? What did i miss? Where was I wrong?

I really like this engine! I don't want to use another. Please, help me!

@rafalp rafalp added bug area: frontend This issue involves JavaScript, React.js and Node labels Apr 5, 2017
@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Hey Daria,

First of, thanks for taking moment to file this issue.

That one second is most likely the moment when Misago displays fallback html template. Stuff turns into english the moment JavaScript kicks in and takes over the UI.

I could swear I've tested JS's i18n with polish language and it worked, but that was while now and this may be regression.

Could you go to http://127.0.0.1:8000/django-i18n.js on your installation and confirm that its same as default english one?

@rafalp rafalp added area: backend This issue involves Python, Django or dependency (eg. database) and removed area: frontend This issue involves JavaScript, React.js and Node labels Apr 5, 2017
@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Can you please confirm that there are no JS errors/warnings in your browser's js console?

@dariaemacs
Copy link
Author

Thank you for the answer!! :)
The difference is the date format only.

 diff my_django-i18n.js  your_django-i18n.js
65c65

<     "DATETIME_FORMAT": "j E Y \u0433. G:i", 
---
>     "DATETIME_FORMAT": "N j, Y, P", 
67,74d66
<       "%d.%m.%Y %H:%M:%S", 
<       "%d.%m.%Y %H:%M:%S.%f", 
<       "%d.%m.%Y %H:%M", 
<       "%d.%m.%Y", 
<       "%d.%m.%y %H:%M:%S", 
<       "%d.%m.%y %H:%M:%S.%f", 
<       "%d.%m.%y %H:%M", 
<       "%d.%m.%y", 
78c70,78
<       "%Y-%m-%d"
---
>       "%Y-%m-%d", 
>       "%m/%d/%Y %H:%M:%S", 
>       "%m/%d/%Y %H:%M:%S.%f", 
>       "%m/%d/%Y %H:%M", 
>       "%m/%d/%Y", 
>       "%m/%d/%y %H:%M:%S", 
>       "%m/%d/%y %H:%M:%S.%f", 
>       "%m/%d/%y %H:%M", 
>       "%m/%d/%y"
80c80
<     "DATE_FORMAT": "j E Y \u0433.", 
---
>     "DATE_FORMAT": "N j, Y", 
82,84c82,84
<       "%d.%m.%Y", 
<       "%d.%m.%y", 
<       "%Y-%m-%d"
---
>       "%Y-%m-%d", 
>       "%m/%d/%Y", 
>       "%m/%d/%y"
86,88c86,88
<     "DECIMAL_SEPARATOR": ",", 
<     "FIRST_DAY_OF_WEEK": "1", 
<     "MONTH_DAY_FORMAT": "j F", 
---
>     "DECIMAL_SEPARATOR": ".", 
>     "FIRST_DAY_OF_WEEK": "0", 
>     "MONTH_DAY_FORMAT": "F j", 
90,93c90,93
<     "SHORT_DATETIME_FORMAT": "d.m.Y H:i", 
<     "SHORT_DATE_FORMAT": "d.m.Y", 
<     "THOUSAND_SEPARATOR": "\u00a0", 
<     "TIME_FORMAT": "G:i", 
---
>     "SHORT_DATETIME_FORMAT": "m/d/Y P", 
>     "SHORT_DATE_FORMAT": "m/d/Y", 
>     "THOUSAND_SEPARATOR": ",", 
>     "TIME_FORMAT": "P", 
99c99
<     "YEAR_MONTH_FORMAT": "F Y \u0433."
---
>     "YEAR_MONTH_FORMAT": "F Y"

@dariaemacs
Copy link
Author

One second, I am checking web developer console.

@dariaemacs
Copy link
Author

Rafał, I don't see any errors.

screenshot from 2017-04-05 11 24 21

screenshot from 2017-04-05 11 24 38

@dariaemacs
Copy link
Author

When I open the source of the page I see right translation (!), but when I open Firebug I see English.

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Oh, I've just noticed in your op:

processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES
processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/en/LC_MESSAGES    
processing file djangojs.po in /usr/local/lib/python2.7/dist-packages/misago/locale/en/LC_MESSAGES

Thise three lines mean respectively:

1. compile server-side language file for ru
2. compile server-side language file for en
3. compile client-side language file for en

You are missing djangojs.po for russian language, hence your django-i18n.js not containing Russian translations and javascript fallbacking to english.

Here's the makemessages script that I'm using that makes language strings for both backend and frontend.

@dariaemacs
Copy link
Author

Yes, I make Javascript file djangojs.po like this:
django-admin.py makemessages -d djangojs -l ru

django-admin compilemessages

processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES
processing file djangojs.po in /usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES
processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/en/LC_MESSAGES
processing file djangojs.po in /usr/local/lib/python2.7/dist-packages/misago/locale/en/LC_MESSAGES

And I change it on Russian.

@dariaemacs
Copy link
Author

I tried to understand different ways. I removed them and create again.
This is the source of file (right :) ):
source

This is web console (wrong :( ):
console

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

This is because you have html that is rendered on server and uses django.po and javascript that runs in client and uses djangojs.po, and your's djangojs.po is either missing or invalid.

What you are seeing is following events taking place:

  1. You open page in browser
  2. Browser loads html from Django that uses django.po and is translated in russian
  3. Browser loads javascript files
  4. Russian djangojs.po is missing/incorrect and so javascript fallbacks to english strings

Are you sure your djangojs.po for ru has valid translations and djangojs.mo exists?

@dariaemacs
Copy link
Author

/usr/local/lib/python2.7/dist-packages/misago$ tree locale/
locale/
├── en
│   └── LC_MESSAGES
│       ├── djangojs.mo
│       ├── djangojs.po
│       ├── django.mo
│       └── django.po
└── ru
    └── LC_MESSAGES
        ├── djangojs.mo
        ├── djangojs.po
        ├── django.mo
        └── django.po

4 directories, 8 files

I removed them *.mo and create again by compilemessages.

@dariaemacs
Copy link
Author

the part of my djangojs.po:

#: static/misago/js/misago.js:10
msgid "Posts"
msgstr "Сообщения"
#: static/misago/js/misago.js:10
msgid "You have posted no messages."
msgstr "У Вас нет ни одного сообщения."

@dariaemacs
Copy link
Author

Honestly, I think you are right about djangojs.po, because all my changes in it I don't see in the forum.
Maybe I forgot something like collectstatic?

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

That view is cached aggressively, so perhaps its that, but then in runserver cache should be turned off.

@dariaemacs
Copy link
Author

Rafał! When I make error in django.po like this (i removed 's):

#: templates/misago/admin/bans/list.html:33
#, python-format
msgid "%(check_type)s, registration only"
msgstr "%(check_type)"

And try to compile, the compiler throws the error:

django-admin compilemessages
processing file django.po in /usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES
CommandError: Execution of msgfmt failed: /usr/local/lib/python2.7/dist-packages/misago/locale/ru/LC_MESSAGES/django.po:242: 'msgstr' is not a valid Python format string, unlike 'msgid'. Reason: The string ends in the middle of a directive.
msgfmt: found 1 fatal error

But, when I make the same error in djangojs.po compilation is ok and djangojs.mo is created.

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Could you upload your ru dir somewhere for me to download and test locally?

@dariaemacs
Copy link
Author

Yes Rafał of course, one second.

@dariaemacs
Copy link
Author

djangojs.po https://yadi.sk/d/YdpTZBGy3GgC9E
django.po https://yadi.sk/d/9M-w2ACh3GgCCL
But Rafał, I write in not all ids.

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Thanks, I'll check this out when I'm back home and reach back to you what I've found.

@dariaemacs
Copy link
Author

Thank you very much!

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Allright, time for wrap up!

I've fixed the logic behind JS catalog. Turns out it explicitly requires one to specify packages to search for javascript translations. This will land in next alpha release, perhaps in two weeks.

Next thing, I'm unsure how you've created your po files, but djangojs.po one contains incorrect Plural-Forms entry:

"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

Whereas correct one generated by makemessages ru utility looks like this:

"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
"%100>=11 && n%100<=14)? 2 : 3);\n"

Incorrect plural forms declaration caused Misago to error with ValueError: plural forms expression could be dangerous. After swapping those, Misago's javascript started using your translations:

zrzut ekranu 2017-04-05 o 20 48 17


Just a note on translations from fellow slav: it looks like makemessages will not generate more than two blanks for plural strings:

msgid "%(threads)s thread"
msgid_plural "%(threads)s threads"
msgstr[0] ""
msgstr[1] ""

Whereas slavic languages have more forms. You'll need to fill in missing blanks manually apparenlty, by adding them as needed to your .po files:

msgid "%(threads)s thread"
msgid_plural "%(threads)s threads"
msgstr[0] "%(threads)s temat"
msgstr[1] "%(threads)s tematy"
msgstr[2] "%(threads)s tematów"
msgstr[3] "%(threads)s tematu" # as in "one and half of thread, dumb really"

Apparently last form may be optional for now. There's discussion on Django's bugtracker.

@dariaemacs
Copy link
Author

dariaemacs commented Apr 5, 2017

Thank you for your research! It's work for me! :)

ok

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Glad I've helped;)

On sidenote, if you are interested in translating Misago to Russian, there's already an translation project on Misago's transifex that you may help with:

https://www.transifex.com/misago/misago/language/ru/

@dariaemacs
Copy link
Author

dariaemacs commented Apr 5, 2017

I'm not professional, but I can load my translation when I finish.
I have 403 page :) by your link :).

@rafalp
Copy link
Owner

rafalp commented Apr 5, 2017

Well, then here's link to project's page:

https://www.transifex.com/misago/misago/dashboard/

@dariaemacs
Copy link
Author

Ok, I see now, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend This issue involves Python, Django or dependency (eg. database) area: localization bug
Projects
None yet
Development

No branches or pull requests

2 participants