Search code examples
.netutf-8cultureinfoyui-compressor

Yahoo YUI Compressor UTF-8 and Culture support


I am using YUI JavaScriptCompressor to compress JavaScript on the fly, and one JavaScript file contains Russian and other languages letters, and apart from that if my current thread culture is set to hr-HR then it changes decimal separator from '.' to ',' !?

Here are the examples, Croatian culture

  Thread.CurrentThread.CurrentCulture = new CultureInfo("hr-HR");
  string js = "var dd = 0.9; var tt = 'Хорватия'";
  string compressed = JavaScriptCompressor.Compress(js);

and value of variable compressed is :

var dd=0,9;var tt="????????";

Decimal separator is changed, single quotes are turned into double ones and Russian script is lost. If I set current culture to en-US, then compressed is :

var dd=0.9;var tt="????????";

Now decimal separator is unchanged, but all other problems are present, even if I set culture to Russian ("ru-RU"), Russian script is still returned as question marks.

I am totally puzzled, so my question is where can I set Encoding and other options to change that behavior, only thing that I see that can affect this compression is parameters in Compress method but none of that helped.

UPDATE 1

I looked at source and there is a way to set Encoding, but YUI Compressor is still changing my decimal separator, here is the code :

  Thread.CurrentThread.CurrentCulture = new CultureInfo("hr-HR");
  string js = "var dd = 0.9; var tt = 'Хорватия'";
  JavaScriptCompressor jsc = new JavaScriptCompressor(js, false, Encoding.UTF8, CultureInfo.InvariantCulture);
  string compressed = jsc.Compress();

and results are :

var dd=0,9;var tt="Хорватия";

Changing culture in 4th parameter to "en-US" didn't help either.


Solution

  • It seems that there is a bug in 1.7.0.0 version that I used, when I upgraded to 1.7.1.0 this code works as expected :

      Thread.CurrentThread.CurrentCulture = new CultureInfo("hr-HR");
      string js = "var dd = 0.9; var tt = 'Хорватия'";
      JavaScriptCompressor jsc = new JavaScriptCompressor(js, false, Encoding.UTF8, CultureInfo.InvariantCulture);
      string compressed = jsc.Compress();