camptocamp / c2cgeoportal

c2cgeoportal application
http://geomapfish.org
Other
64 stars 46 forks source link

Encoding problem with translation script #2717

Closed gnerred closed 7 years ago

gnerred commented 7 years ago

Version 2.1.0.dev25

.build/venv/bin/l10nv1tov2 fr cartoriviera/static/js/Proj/Lang/fr.js cartoriviera/locale/fr/LC_MESSAGES/cartoriviera-client.po
Traceback (most recent call last):
  File ".build/venv/bin/l10nv1tov2", line 11, in <module>
    sys.exit(main())
  File "/var/www/vhosts/cartoriviera_preprod/private/cartoriviera_geomapfish_v2/cartoriviera_geomapfish/.build/venv/local/lib/python2.7/site-packages/c2cgeoportal/scripts/l10nv1tov2.py", line 96, in main
    """.format(key, value.replace('"', '\\"'))).encode("utf-8"),
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 25: ordinal not in range(128)

Something wrong in my base file ?

ger-benjamin commented 7 years ago

Looks like the same as #2725 but in the l10nv1tov2.py , but there is already a .encode("utf-8") that should handle the problem... I'll take a look.

ger-benjamin commented 7 years ago

Ok, that creates the problem, that doesn't handle it... We should convert this string as unicode.

To test, you can open the file in <your_project>.build/venv/lib/python2.7/site-packages/c2cgeoportal/scripts/c2cgeoportal/scripts/l10nv1tov2.py

And a u just before the 3 double-quotes at the line destionation.write((""" (line ~93 (and not 82))

So to get this:

    with open(options.po_v2, "w+") as destionation:                              
        destionation.write("""msgid ""                                           
msgstr ""                                                                        
"Last-Translator: Imported from {0!s}\\n"                                        
"Language: {1!s}\\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"                                  
""".format(options.json_v1, options.lang))                                       
        for key, value in source.items():                                        
            if isinstance(value, basestring):                                    
                destionation.write((u"""                                          
msgid "{0!s}"                                                                    
msgstr "{1!s}"                                                                   
""".format(key, value.replace('"', '\\"'))).encode("utf-8"),

Then do (only) a graceful an launch the script again.

Please, save your files before testing, I'm not 100% sur that it will write thème and not th\xc3\xa8me (for instance). I'll open a PR

gnerred commented 7 years ago

Ok thanks. I'll not be able to test before beginning 2017... Hope the PR solves the problem