home *** CD-ROM | disk | FTP | other *** search
/ Freelog 100 / FreelogNo100-NovembreDecembre2010.iso / Graphisme / GoogleSketchUp / GoogleSketchUpWFR.exe / GoogleSketchUp8.msi / SketchUpMeta.cab / langhandler.rb.78D17A5F_0E0A_44D2_877D_2C56D45D16B7 < prev    next >
Encoding:
Text File  |  2010-08-26  |  2.4 KB  |  102 lines

  1. # Copyright 2005-2008, Google, Inc.
  2.  
  3. # This software is provided as an example of using the Ruby interface
  4. # to SketchUp.
  5.  
  6. # Permission to use, copy, modify, and distribute this software for 
  7. # any purpose and without fee is hereby granted, provided that the above
  8. # copyright notice appear in all copies.
  9.  
  10. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  11. # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  12. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. #-----------------------------------------------------------------------------
  14.  
  15. class LanguageHandler
  16.  
  17.   def initialize(fileName)
  18.     @strings = Hash.new;
  19.     self.ParseLangFile(fileName)
  20.   end
  21.  
  22.   def ParseLangFile(sub_path)
  23.     full_file_path = Sketchup.get_resource_path(sub_path)
  24.  
  25.     if full_file_path==nil || full_file_path.length==0
  26.       return false
  27.     end
  28.  
  29.     langFile = File.open(full_file_path, "r")
  30.     entryString = ""
  31.     inComment = false
  32.  
  33.     langFile.each do |line|
  34.       #ignore simple comment lines - BIG assumption the whole line is a comment
  35.       if !line.include?("//")
  36.         #also ignore comment blocks
  37.         if line.include?("/*")
  38.           inComment = true
  39.         end
  40.  
  41.         if inComment==true
  42.           if line.include?("*/")
  43.             inComment=false
  44.           end
  45.         else
  46.           entryString += line
  47.         end
  48.       end
  49.  
  50.       if entryString.include?(";")
  51.         #parse the string into key and value
  52.         
  53.         #remove the white space
  54.         entryString.strip!
  55.  
  56.         #pull out the key
  57.         keyvalue = entryString.split("\"=\"")
  58.         
  59.         #strip the leading quotation out
  60.         key = keyvalue[0][(keyvalue[0].index("\"")+1)..(keyvalue[0].length+1)]
  61.  
  62.         #pull out the value
  63.         keyvalue[1].gsub!(";", "")
  64.         value = keyvalue[1].gsub("\"", "") 
  65.  
  66.         #add to @strings
  67.         @strings[key]=value
  68.  
  69.         entryString = ""
  70.       end
  71.     end
  72.  
  73.     return true
  74.   end
  75.  
  76.   def GetString(key)
  77.     #puts "GetString key = " + key.to_s
  78.     retval = @strings[key]
  79.     #puts "GetString retval = " + retval.to_s
  80.  
  81.     if retval!= nil
  82.         retval.chomp!
  83.     else
  84.         retval = key
  85.     end
  86.     return retval
  87.   end
  88.  
  89.   def GetStrings
  90.     return @strings
  91.   end
  92.  
  93.   def LanguageHandler::GetResourceSubPath()
  94.     fullPath = Sketchup.get_resource_path("")
  95.     startIndex = fullPath.index("Resources")
  96.     subPath = fullPath[startIndex..fullPath.length]
  97.     #puts "subPath=" + subPath.to_s
  98.     return subPath
  99.   end
  100.  
  101. end
  102.