yes,I'm using wxruby2 When I change "samples/text/unicode.rb" 's content: require 'wx' into begin require 'wx' rescue LoadError => no_wx_err begin require 'rubygems' require 'wx' rescue LoadError raise no_wx_err end end and run unicode.rb in this way: ruby -Ku unicode.rb I got the error message like this: unicode.rb:119: syntax error, unexpected tCONSTANT, expecting ')' fd = Wx::FileDialog.new( nil, 'Import file', "", "", ^ unicode.rb:128: warning: parenthesize argument(s) for future version unicode.rb:128: syntax error, unexpected tCONSTANT, expecting kEND Wx::MessageDialog.new(self, message, 'Wrong encoding', ^ and more ... all the string cause error. how can I do? Thanks 2007/4/2, Alex Fenton <alex@deleteme.pressure.to>:> yang cao wrote: > > I want to use Chinese characters in wxRuby,like this: > > Wx::Button.new(@panel,-1,'Chinese characters wanted to be placed') > > also in Chinese is: > > Wx::Button.new(@panel,-1,'汉字') > > Assuming you're using wxruby2, which you should be, ensure that your script is in UTF8 encoding, and that you have $KCODE = 'u' at the top of it. > > Have a look at the demo samples/text/unicode.rb which demonstrates the use of controls with labels and content in numerous different scripts including Chinese. > > The wxruby-users mailing list is a good place for any questions about the toolkit: > http://rubyforge.org/mail/?group_id=35 > > alex > >_______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
this is my ruby version: ruby --version ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] thanks 2007/4/5, yang cao <caoyangruby at gmail.com>:> yes,I''m using wxruby2 > When I change > "samples/text/unicode.rb" ''s content: > > require ''wx'' > > into > > begin > require ''wx'' > rescue LoadError => no_wx_err > begin > require ''rubygems'' > require ''wx'' > rescue LoadError > raise no_wx_err > end > end > > and run unicode.rb in this way: > ruby -Ku unicode.rb > I got the error message like this: > > unicode.rb:119: syntax error, unexpected tCONSTANT, expecting '')'' > fd = Wx::FileDialog.new( nil, ''Import file'', "", "", > ^ > unicode.rb:128: warning: parenthesize argument(s) for future version > unicode.rb:128: syntax error, unexpected tCONSTANT, expecting kEND > Wx::MessageDialog.new(self, message, ''Wrong encoding'', > ^ > and more ... > > all the string cause error. > how can I do? Thanks > > 2007/4/2, Alex Fenton <alex at deleteme.pressure.to>: > > yang cao wrote: > > > I want to use Chinese characters in wxRuby,like this: > > > Wx::Button.new(@panel,-1,''Chinese characters wanted to be placed'') > > > also in Chinese is: > > > Wx::Button.new(@panel,-1,''??'') > > > > Assuming you''re using wxruby2, which you should be, ensure that your script is in UTF8 encoding, and that you have $KCODE = ''u'' at the top of it. > > > > Have a look at the demo samples/text/unicode.rb which demonstrates the use of controls with labels and content in numerous different scripts including Chinese. > > > > The wxruby-users mailing list is a good place for any questions about the toolkit: > > http://rubyforge.org/mail/?group_id=35 > > > > alex > > > > >
Hi yang cao wrote:> yes,I''m using wxruby2 > When I change > "samples/text/unicode.rb" ''s content: > >Does the sample work if you don''t edit it? Try running the original sample with ruby -rubygems samples/text/unicode.rb> and run unicode.rb in this way: > ruby -Ku unicode.rb >You don''t need to run it with -Ku - the sample should be setting $KCODE = ''u'' itself.> I got the error message like this: > > unicode.rb:119: syntax error, unexpected tCONSTANT, expecting '')'' > fd = Wx::FileDialog.new( nil, ''Import file'', "", "", > ^ > unicode.rb:128: warning: parenthesize argument(s) for future version > unicode.rb:128: syntax error, unexpected tCONSTANT, expecting kEND > Wx::MessageDialog.new(self, message, ''Wrong encoding'', > ^ > and more ... > > all the string cause error.I wonder if perhaps the encoding of the script got changed when you edited it? wxRuby requires non-ASCII characters in scripts to be in UTF8. You could check whether the edited version is still valid UTF8 by doing: ruby -riconv -e ''Iconv.iconv("UTF-8", "UTF-8", File.read(ARGV[0]))'' samples/text/unicode.rb If this raises an IllegalSequenceError, then the script isn''t valid utf8. hth alex
Hi 2007/4/6, Alex Fenton <alex at pressure.to>:> Hi > > yang cao wrote: > > yes,I''m using wxruby2 > > When I change > > "samples/text/unicode.rb" ''s content: > > > > > Does the sample work if you don''t edit it? Try running the original > sample with > > ruby -rubygems samples/text/unicode.rbit works well. but when i add chinese characters in unicode.rb and save it using windows notepad.exe -encoding utf-8 like the attach files. it raise the error : samples/text/aunicode.rb:1: Invalid char `\357'' in expression samples/text/aunicode.rb:1: Invalid char `\273'' in expression samples/text/aunicode.rb:1: Invalid char `\277'' in expression samples/text/unicode.rb:119: syntax error, unexpected tCONSTANT, expecting '')'' fd = Wx::FileDialog.new( nil, ''Import file'', "", "",> > and run unicode.rb in this way: > > ruby -Ku unicode.rb > > > You don''t need to run it with -Ku - the sample should be setting $KCODE > = ''u'' itself. > > I got the error message like this: > > > > unicode.rb:119: syntax error, unexpected tCONSTANT, expecting '')'' > > fd = Wx::FileDialog.new( nil, ''Import file'', "", "", > > ^ > > unicode.rb:128: warning: parenthesize argument(s) for future version > > unicode.rb:128: syntax error, unexpected tCONSTANT, expecting kEND > > Wx::MessageDialog.new(self, message, ''Wrong encoding'', > > ^ > > and more ... > > > > all the string cause error. > I wonder if perhaps the encoding of the script got changed when you > edited it? wxRuby requires non-ASCII characters in scripts to be in > UTF8. You could check whether the edited version is still valid UTF8 by > doing: > > ruby -riconv -e ''Iconv.iconv("UTF-8", "UTF-8", File.read(ARGV[0]))'' > samples/text/unicode.rbwhen i add chinese charaters in unicode.rb ,save it in utf-8 using windows notepad, then tried this, it raise no error, but ruby -rubygems samples/text/unicode.rb still raise the errors: samples/text/unicode.rb:1: Invalid char `\357'' in expression samples/text/unicode.rb:1: Invalid char `\273'' in expression samples/text/unicode.rb:1: Invalid char `\277'' in expression samples/text/unicode.rb:119: syntax error, unexpected tCONSTANT, expecting '')'' fd = Wx::FileDialog.new( nil, ''Import file'', "", "", ^ and more ..... it likes that ruby can''t execute utf8 files without -Ku but wxruby2 cant understand ansi files with chinese charaters... how can i do...?> > If this raises an IllegalSequenceError, then the script isn''t valid utf8. > > hth > alex >thanks! cy> > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- A non-text attachment was scrubbed... Name: unicode.rb_save_in_utf-8.PNG Type: image/png Size: 101860 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20070412/c5b49eca/attachment-0001.png -------------- next part -------------- A non-text attachment was scrubbed... Name: unicode.rb Type: application/octet-stream Size: 8323 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20070412/c5b49eca/attachment-0001.obj
yang cao wrote:>> Does the sample work if you don''t edit it? Try running the original >> sample with >> >> ruby -rubygems samples/text/unicode.rb > > it works well. > but when i add chinese characters in unicode.rb and save it using > windows notepad.exe -encoding utf-8 like the attach files. > it raise the error :I''ve tried your example on Windows and I''m getting the same error. However, the wxruby unicode sample does work fine here. I feel pretty sure that your problem is coming from using notepad to edit the file.> samples/text/aunicode.rb:1: Invalid char `\357'' in expression > samples/text/aunicode.rb:1: Invalid char `\273'' in expression > samples/text/aunicode.rb:1: Invalid char `\277'' in expressionI think notepad is inserting these invalid characters into the sample - I''d strongly suggest you try using Scite, a free programming editor which should have been installed alongside your ruby installation. You will find it a much more helpful editor for writing ruby scripts generally. I was able to fix these ''Invalid char'' errors by simply copying your code and pasting it into a new file in Scite, setting the encoding to UTF-8 (in File -> Encoding) and saving.> samples/text/unicode.rb:119: syntax error, unexpected tCONSTANT, > expecting '')'' > fd = Wx::FileDialog.new( nil, ''Import file'', "", "",Similarly, your example has a broken UTF8 character on line 91. You should be able to put a Chinese (or any other) string in the button label on that line in Scite, and it should work fine. hth Alex
it seems that ruby1.8 doesn''t support utf8 files with bomb .... but windows notepad only can save utf8 encoded files with bomb. when i save the file with :set fileencoding=utf-8 :set nobomb in vim. Things goes well. Scite is also a nice programming editor, :) Thanks a lot! 2007/4/12, Alex Fenton <alex at pressure.to>:> yang cao wrote: > >> Does the sample work if you don''t edit it? Try running the original > >> sample with > >> > >> ruby -rubygems samples/text/unicode.rb > > > > it works well. > > but when i add chinese characters in unicode.rb and save it using > > windows notepad.exe -encoding utf-8 like the attach files. > > it raise the error : > I''ve tried your example on Windows and I''m getting the same error. > However, the wxruby unicode sample does work fine here. I feel pretty > sure that your problem is coming from using notepad to edit the file. > > samples/text/aunicode.rb:1: Invalid char `\357'' in expression > > samples/text/aunicode.rb:1: Invalid char `\273'' in expression > > samples/text/aunicode.rb:1: Invalid char `\277'' in expression > I think notepad is inserting these invalid characters into the sample - > I''d strongly suggest you try using Scite, a free programming editor > which should have been installed alongside your ruby installation. You > will find it a much more helpful editor for writing ruby scripts generally. > > I was able to fix these ''Invalid char'' errors by simply copying your > code and pasting it into a new file in Scite, setting the encoding to > UTF-8 (in File -> Encoding) and saving. > > samples/text/unicode.rb:119: syntax error, unexpected tCONSTANT, > > expecting '')'' > > fd = Wx::FileDialog.new( nil, ''Import file'', "", "", > Similarly, your example has a broken UTF8 character on line 91. You > should be able to put a Chinese (or any other) string in the button > label on that line in Scite, and it should work fine. > > hth > Alex > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >
yang cao wrote:> it seems that ruby1.8 doesn''t support utf8 files with bomb .... > but windows notepad only can save utf8 encoded files with bomb. >Ah, thanks for the info, that makes sense. Iconv knows about the BOM, becuase your sample file was not showing any IllegalSequence errors, but ruby doesn''t. http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3208 Honestly I''m surprised that this isn''t fixed in ruby... cheers alex
Thank you! ye, BOM(Byte Order Mark), not bomb, hehe. cheers cy Alex Fenton ??:> yang cao wrote: > >> it seems that ruby1.8 doesn''t support utf8 files with bomb .... >> but windows notepad only can save utf8 encoded files with bomb. >> >> > Ah, thanks for the info, that makes sense. Iconv knows about the BOM, > becuase your sample file was not showing any IllegalSequence errors, but > ruby doesn''t. > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3208 > > Honestly I''m surprised that this isn''t fixed in ruby... > > cheers > alex > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users > >