Sha256: c183f3b96955d79c6de79f7db03754b93e28acf886833b730c2e03da6b1d8f5d

Contents?: true

Size: 1.84 KB

Versions: 7

Compression:

Stored size: 1.84 KB

Contents

class LangaugeFile
  
  def executeStage(message) 
    puts message
    yield
  end
  
  def generate_language_file(language,duplicate)
    filename = File.join("lang", "#{language}.rb");
    
    
    stringMap = {}
    executeStage "Loading last language file #{filename}" do
      File.read(filename).scan(/["](.*?)["],(.*)/u).each do |pp|
        stringMap[pp[0]] = pp[1]
      end
    end

    
    stringAll = []
    executeStage "Generating #{filename}" do
      rc  = ""
      rc += "Localization.define(\"#{language}\") do |l|"
      Dir.glob("**/*.{erb,rhtml,rb}").collect do |ff|
        strings   = File.read(ff).scan(/_\([ ]*["](.*?)["]/)
        strings  += File.read(ff).scan(/_\([ ]*['](.*?)[']/)
        if strings.length > 0
          strings.uniq!
          stringsRemove = strings          
          strings -= stringAll           
          stringAll += stringsRemove
          stringAll.uniq!
          if strings.length > 0
            rc += "\n\n  # #{ff}"
            strings.each do |ss|
              key = ss[0]
              if ( duplicate )
                rc += "\n  l.store \"#{key}\", \"#{key}\""
              else
                if stringMap.has_key?(key)
                  rc += "\n  l.store \"#{key}\",#{stringMap[key]}"
                else
                  rc += "\n  l.store \"#{key}\", \"\""
                end
              end
            end
          end
        end
      end
      rc += "\nend"
      ff = File.new(filename,"w")
      ff.write(rc)
      ff.close()
    end
  end
end

class Tool
  def initialize
    @language  = 'en_US'
    @duplicate = true  
    
    if ( ARGV[0] )
      @language  = ARGV[0]
      @duplicate = false
    end    
  end
 
  def run 
    lang = LangaugeFile.new 
    lang.generate_language_file(@language,@duplicate);  
  end
end

# should be run on the Rails directory
tool = Tool.new
tool.run

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
typo-5.5 vendor/plugins/localization/bin/make_language.rb
typo-5.4.4 vendor/plugins/localization/bin/make_language.rb
typo-5.4.3 vendor/plugins/localization/bin/make_language.rb
typo-5.4.2 vendor/plugins/localization/bin/make_language.rb
typo-5.4.1 vendor/plugins/localization/bin/make_language.rb
typo-5.4 vendor/plugins/localization/bin/make_language.rb
typo-5.3 vendor/plugins/localization/bin/make_language.rb