Is it possible to manage accents in dialog boxes ?
ratus69_c6741fefbf
Posts: 34
hi,
when I run a script with words containing accent in a dialog box in script editor, everything goes fine
but when I launch this same script with a shortcut, accent is no longer managed
I've tried encodeURI / decodeURI but it's not working
thanks
var message = encodeURI("Le temps n'est pas à 0, relancer le script")MessageBox.information( decodeURI (message), "Temps incorrect !" , "&OK" )
Comments
The unicode value of à is 224. So you can use the fromCharCode method:
thanks cayman for your workaround, I thought there were a more practical solution
normaly encodeURI should encode the accent and decodeURI decode them
anyway thanks again
Interesting find.
It's a multibyte issue. Javascript natively understands UTF-8, other languages (and apps based on those) do differ, especially the older ones.
The encoding gets mixed up between "read script file" to "execute script". Why this happens only when you run the script with a shortcut, whereas in the IDE it works, I'm not sure why this happens.
But I might have a solution for you:
Long story made short - copy that UTF8 block and when you output strings, pipe them through UTF8.decode()
Is it just me, or is the code block collapsed? That's not very useful :|
So here again:
(function(){
UTF8 = {
encode: function(s){
for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
);
return s.join("");
},
decode: function(s){
for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
((a = s[i][c](0)) & 0x80) &&
(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
);
return s.join("");
}
};
MessageBox.information(UTF8.decode("Le temps n'est pas à 0, relancer le script"), "test", "ok", "cancel");
})();
Thanks Mork for this code. It has been very helpful to me. However, it seems to fail with Japanese/Chinese characters. Do you know how to fix it?