4
votes

I am using Python 3.5.2 and Django 1.10.

I have received the French translation .po file and can run the compilemessages command without receiving any errors.

However, when I run the site, many pages refuse to load.

I suspect that this is because the French translation .po file contains many single quotes (') in the translation strings.

For example,

#: .\core\constants\address_country_style_types.py:274
msgid "Ascension Island"
msgstr "Île de l'Ascension"

I remember reading somewhere (but cannot find that reference anywhere) that the single quotes must have either a forward or back slash before them. So I tried that, but when I ran the compilemessage command, I got an error message of:

C:\Users\me\desktop\myapp\myapp\locale\fr\LC_MESSAGES\django.po:423:18: invalid control sequence

So how do I escape the French single quote in strings issue?

here is the header of my French language .po file:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-04 12:55+1000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
4
I'm not sure that is the problem, I have worked on many django projects that included french and I don't remember having this problem.Jonas Grumann
It may be a character encoding (aka 'codecs') issue. Not ' characters. Are you sure the files are valid utf8 (check with a good text editor).Brandin
@Jonas Giuro - did you use standard single quotation marks? For example: '?user1261774
Yes, I used it like this "Île de l'Ascension", from my experience, messed up translations render as messed up translations, they don't block the whole page from rendering.Jonas Grumann
@Jonas Giuro - I have used and it works OK - the compilemessage command works and pages load. Unsure what the issue is with '. Do you think it is OK to use - "Île de l′Ascension" for the French translation? Is it correct French grammar?user1261774

4 Answers

2
votes

I am unsure what is the cause of this issue (maybe that the translator somehow corrupted the file?).

However, a workaround is instead of using the standard single quotation mark ', I have used this single quotation mark (taken from symbols in MS Word):

I am yet to check this with the French translator, but it looks and works OK.

I hope this helps someone.

1
votes

The correct way is to "Escape" the single quote, however, you need to know the end-point consuming the text. Like you found out with the backslash, as in: L\'Ascension

Trust me, nobody that is French will like seeing the backquote. Back in the DOS days of the 90's, visually, there was almost no difference. Now with fonts, it gets ugly.

Since you're producing for the web, use a HTML replacement, like '

See this article: Why shouldn't `&apos;` be used to escape single quotes?

1
votes

The solution is

#: .\core\constants\address_country_style_types.py:274
msgid "Ascension Island"
msgstr "Ile de l&lsquo;Ascension"

It works, even if it will be used in some JavaScript. Don't use the numeric code &#39;, it will not work inside Form fields, it will not be rendered and you will see the ugly number. I already tested all this.

As I said in the comments, beginning a word with a uppercase accented letter is not recommended. If you put Île and you then sort the list of countries, the Î character will come after the Z and will not be sorted following a natural order, as you would expect.

This is another problem with Python sorting capabilities. It will only follow the extended ASCII code according of each letter encoding number. And Î has an ANSI code of 206, it comes after the Z, which is 90.

Maybe Python provides a solution to this, but I didn't find yet. If someone found it I would be glad to know.

0
votes

I'm a French speaker, so are most of my users. Very annoying bug. the normal django escaping techniques (through \' or format_html(my_translated_string)) do not work for me as well. I have used instead of ' and it works OK - the compilemessage command works and the html node works ok.

it is however not very elegant or Robust as any future message needs to take this into account, and it is not very common to use the character ´

I found out another better and more robust solution: escaping through template filters.

in html template:

<h5 class="modal-title">{{help_message_body|escape}}</h5>

and in javascript:

modal.find('.modal-message').html('<h5 class="modal-title">{{help_message_body|escapejs}}</h5>')