Unicode characters problem
-
Hello.
If I put the codeUI.messagebox "weiΓ"in the Ruby console inside Sketchup,is working ok.
But the same code inside the plugin is giving me an error.
I have try it in notepad++ and NetBeans with the some result.Why is that,what to do about?
-
Because SketchUp is using UTF-8 encoding - and plugins needs to be written in ANSI. Γ is a multi-byte character. If you really need it hard coded in your plugin script then either store it as the raw byte characters.
Or - you can store the strings in a UTF-8 text file and load it - that will work. I use UTF-8 encoded files for my translations for Vertex Tools. The strings are loaded into a hash file where the keys are ANSI characters. -
More reading on Unicode: http://forums.sketchucation.com/viewtopic.php?f=180&t=20657
-
Thank you for the very useful reading.
Seems that is a lot of work to implement multilingual support. -
You mean for the UI?
-
Yes, I'm implementing my own translation system.Strings are in files,like you suggested.
-
Hello.
Another unicode related problem.I can repeat this one only reading from a file,so the file with 1 character is attached.
I can read a character,but is causing some problems if I want to unpack it or concatenate it with other strings.
Here is the sample,where I want to unpack it:langfile= Sketchup.find_support_file("fr1.lang" , "Plugins/") IO.foreach(langfile) do |line| UI.messagebox line.unpack('U*') endThe error is :"Error Loading File new.rb
malformed UTF-8 character (expected 3 bytes, given 2 bytes)"Why is this,how to deal with it?
-
1) Try packing the array with "U3" (and unpacking the String with "U3" also.)
2)
IO.foreachsets the separator string to$/by default. ($/is set to a newline character by Ruby, and probably should not be changed.)Make sure you write a newline char to the file after the unicode char(s), for each line.
ADD:puts()will add a newline char for you, so:
` plugdir = File.expand_path(Sketchup.find_support_file("Plugins"))
subdir = "voljanko/xlate"
langfile = File.new( File.join( plugdir, subdir, "fr1.lang" ))
langfile.puts( ["chars"].pack("U3") )4 bytes should be written, the last should be 10.chr
langfile.close()`
You may also use
IO.readorIO.readlines, but before unpacking, you need tochop()the linestring to remove the record separator ( a "\n" char.)
ADD:
lines = IO.readlines( File.join( plugdir, subdir, "fr1.lang" )) lines.each do |line| UI.messagebox( line.chop.unpack("U3") ) end3) Your datafiles DO NOT belong in the Plugins folder. Create a subfolder for them.
-
The problem was in the file,not in the code.
I have saved the file in notepad as UFT-8 ,so I can "unpack" the character.
I have tried to save the file in other formats (unicode,ANSI,unicode big endian) and is always giving me errors.
So only UFT-8 is ok.
Problem solved
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement