sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Unicode characters problem

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 265 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • voljankoV Offline
      voljanko
      last edited by

      Hello.
      If I put the code

      UI.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?

      SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          More reading on Unicode: http://forums.sketchucation.com/viewtopic.php?f=180&t=20657

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • voljankoV Offline
            voljanko
            last edited by

            Thank you for the very useful reading.
            Seems that is a lot of work to implement multilingual support.

            SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              You mean for the UI?

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • voljankoV Offline
                voljanko
                last edited by

                Yes, I'm implementing my own translation system.Strings are in files,like you suggested.

                SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

                1 Reply Last reply Reply Quote 0
                • voljankoV Offline
                  voljanko
                  last edited by

                  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*')
                  	end
                  

                  The 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?


                  fr1.lang

                  SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    1) Try packing the array with "U3" (and unpacking the String with "U3" also.)

                    2) IO.foreach sets 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.read or IO.readlines, but before unpacking, you need to chop() 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") ) end

                    3) Your datafiles DO NOT belong in the Plugins folder. Create a subfolder for them.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • voljankoV Offline
                      voljanko
                      last edited by

                      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 😄

                      SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement