Geoportail-Luxembourg / geoportailv3

geoportailv3 is the implementation of the v3 of the map viewer of the luxembourgish geoportal
MIT License
25 stars 16 forks source link

accented letters in template #876

Closed rmichaelis closed 9 years ago

rmichaelis commented 9 years ago

I try to use some accented letters but it seems that the mako renderer does not allow it. Example here : https://github.com/Geoportail-Luxembourg/geoportailv3/blob/renaud_test/geoportailv3/static/js/mymaps/mymaps.html#L3

The partial file is in UTF-8

Here is the compilation error :

Traceback (most recent call last):
  File "/home/mire/geoportailv3/.build/venv/lib/python2.7/site-packages/mako/cmd.py", line 56, in cmdline
    print(template.render(**kw))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 15674: ordinal not in range(128)
make: *** [geoportailv3/static/build/templatecache.js] Error 1

Do you have an idea ?

fredj commented 9 years ago

Try to add ## -*- coding: utf-8 -*- at the top of the file. See http://docs.makotemplates.org/en/latest/unicode.html#specifying-the-encoding-of-a-template-file

rmichaelis commented 9 years ago

I already tried, but unfortunately this has no effect.

rmichaelis commented 9 years ago

Ok I think I've understood the problem.

This is due to this line : https://github.com/Geoportail-Luxembourg/geoportailv3/blob/master/CONST_Makefile#L513

this is generating something like that :

.build/venv/bin/mako-render --var "partials=geoportailv3/static/js/mymaps/mymaps.html" templatecache.mako.js > test.js 

But the > test.js is not created as an UTF8 file and we try to push some utf8 content inside.

Now we have to find how to force the file to be created as utf8

rmichaelis commented 9 years ago

It works now. I had to add the following line :

export  PYTHONIOENCODING=UTF-8

here https://github.com/Geoportail-Luxembourg/geoportailv3/blob/master/CONST_Makefile#L513

Do you agree with this ???

elemoine commented 9 years ago

Let me have a quick look.

elemoine commented 9 years ago

Yes, that's the correct fix. This is what you want:

diff --git a/CONST_Makefile b/CONST_Makefile
index cfcd139..ab59ae2 100644
--- a/CONST_Makefile
+++ b/CONST_Makefile
@@ -510,7 +510,7 @@ $(OUTPUT_DIR)/build.css: $(LESS_FILES) .build/node_modules.timestamp

 $(OUTPUT_DIR)/templatecache.js: templatecache.mako.js $(APP_PARTIALS_FILES)
        mkdir -p $(dir $@)
-       $(VENV_BIN)/mako-render --var "partials=$(APP_PARTIALS_FILES)" $< > $@
+       PYTHONIOENCODING=UTF-8 $(VENV_BIN)/mako-render --var "partials=$(APP_PARTIALS_FILES)" $< > $@

 .build/externs/angular-1.4.js:
        mkdir -p $(dir $@)

I'll backport this to c2cgeoportal.

rmichaelis commented 9 years ago

Thank you

elemoine commented 9 years ago

Fixed with https://github.com/Geoportail-Luxembourg/geoportailv3/pull/880.