Unicode support

61 views
Skip to first unread message

Parker

unread,
Mar 11, 2010, 2:51:14 AM3/11/10
to Closure Templates Discuss
When I have Chinese characters in my .soy file, the characters in
output js file are unrecognizable(erroneously parsed). I can't find
any options to specify the input character set. How can I avoid this?

Kai Huang

unread,
Mar 15, 2010, 3:57:57 PM3/15/10
to Closure Templates Discuss
As documented here:
http://code.google.com/closure/templates/docs/concepts.html#filestructure
the .soy files must be encoded in UTF-8. UTF-8 can handle all Chinese
characters, so you be okay.

Note for Windows users: The file must be UTF-8 without the BOM (byte
order mark). Some Windows programs generate a pointless BOM at the
start of a UTF-8 file, which you would need to strip off.

Parker

unread,
Mar 23, 2010, 10:19:02 PM3/23/10
to Closure Templates Discuss
Thanks kai, I encoded my soy file with UTF-8, but didn't notice it
should be encoded without BOM. Now it works.

On Mar 16, 3:57 am, Kai Huang <kai.hu...@gmail.com> wrote:
> As documented here:
>    http://code.google.com/closure/templates/docs/concepts.html#filestruc...

Parker

unread,
Mar 24, 2010, 3:25:35 AM3/24/10
to Closure Templates Discuss
But unfortunately, the browser does not recognize javascript file in
UTF-8 without BOM, so I have to add the BOM before I can use the
generated js files. Is it possible to provide an option to specify
whether the BOM is used?

Kai Huang

unread,
Mar 24, 2010, 1:50:28 PM3/24/10
to Closure Templates Discuss
If your main web page includes a JS file via a 'script' tag, e.g.
<script type="text/javascript" src="foo-bar.js"></script>
then the browser assumes the encoding of foo-bar.js is the same as the
encoding of the main page. There are two easy solutions:

(1) Encoding your main page in UTF-8, and then telling the browser,
e.g.
<meta http-equiv="Content-Type" content="text/html;
charset="UTF-8">

-or-

(2) Explicitly telling the browser that foo-bar.js is UTF-8, e.g.
<script type="text/javascript" charset="UTF-8" src="foo-bar.js"></
script>

Parker

unread,
Apr 1, 2010, 1:35:16 PM4/1/10
to Closure Templates Discuss
Yes, that helps a lot. Great Thanks!
Reply all
Reply to author
Forward
0 new messages