0

I'm trying to use a UTF8 string with accents in Opal.

Ruby Code:

test = "Français"
puts test
$document['#test'].inner_html = test

Compiled JavaScript :

test = "Fran\xC3\xA7ais";
self.$puts(test);
return (($a = [test]), $b = $gvars.document['$[]']("#test"), $b['$inner_html='].apply($b, $a), $a[$a.length-1]);

#test and browser console display :

Français

If I manually edit the compiled JavaScript replacing "Fran\xC3\xA7ais" by "Français" :

#test and browser console display :

Français

What am I doing wrong?

Is there a way to tell Opal to pass the UTF8 string untouched to JavaScript?

Thanks

James
  • 1,928
  • 3
  • 13
  • 30
elphoton
  • 1
  • 1
  • Which version of Ruby do you use? If it is 1.x, try to add `# Encoding: utf-8` at the beginning of source file – Artem Sep 24 '17 at 21:39

1 Answers1

0

One important thing for UTF8 to work with Opal is to have the whole page to be correctly identified as UTF8 in its own encoding.

This can be done easily with a meta tag:

<meta charset="utf-8">
Elia Schito
  • 989
  • 7
  • 18
  • I'have a in the head section of my html page, utf-8 display fine, but how to deal with the JavaScript String literal "Fran\xC3\xA7ais" generated by Opal compiler ? cf here : https://jsfiddle.net/ohogorpL/. – elphoton Aug 17 '17 at 12:27
  • (sorry for the delay) try with opal v0.11 which is better on every level, there's a strong chance it's been fixed/improved – Elia Schito Feb 27 '18 at 23:29