Results 1 to 2 of 2

Thread: serDiff - Language file merge tool

  1. #1
    Join Date
    Jan 2009
    Posts
    10

    Lightbulb serDiff - Language file merge tool

    Hello,

    I coded a small tool for merge languages files with Ruby.

    After DirectAdmin updates, if the string is not in your own language file (maybe new added line or new file) the view of directadmin broken up.

    The tool, add new lines from original files to own language files. Also, copy new files to own language directories.

    It is coded in Ruby with power of 'wc' and 'tail' command.
    It tested with ruby 1.8.7.

    Example log:
    Code:
    Y admin/admin_cron_jobs.html
    D admin/admin_settings.html : 9
    Y admin/brute_force_ip_info.html
    Y admin/brute_force_monitor.html
    D admin/content_main.html : 3
    D admin/create_reseller.html : 3
    Y means 'new file', 'D' means new lines (also show how many lines added up)

    Usage:
    Code:
    ruby serdiff.rb ORG-LANG-DIR OWN-LANG-DIR
    serDiff.rb
    Code:
    # serDiff.rb
    # directadmin dil dosyalari guncelleme araci
    #
    # SERENAY YAZILIM
    # www.serenay.net.tr | info (@) serenay.net.tr
    #
    # 0.1 - 01/09/2011
    #
    
    # gerekli parametreler
    #
    if ARGV.length != 2
      puts "Kullanım: serdiff.rb orj-dir lang-dir"
      exit
    end
    
    $klasor1 = ARGV[0]    # orjinal directadmin dil klasoru
    $klasor2 = ARGV[1]    # cevirilerimizin oldugu klasor
    ['find', 'ftools', 'fileutils'].each { |req| require req }
    
    # dosyadaki satir sayisini dondurur
    # performans icin 'wc' tercih edildi
    #
    def satir_adet(dosya, klasor) 
      count = `wc -l < #{klasor}#{dosya}`
      return Integer(count.chomp)
    end
    
    # son eklenen satirlari mevcut dosyamiza aliyoruz
    # not: sistem hic satir silinmeme uzerine kurulu
    #
    def satir_kopyala(dosya, adet)
      `tail -n#{adet} #{$klasor1}#{dosya} >> #{$klasor2}#{dosya}`
    end
    
    # bizde olmayan dosyalari, klasor yapisina sadik kalarak 
    # kopyaliyoruz
    #
    def dosya_kopyala(dosya) 
      klasor = File.dirname(dosya)
      hedef_klasor = "#{$klasor2}#{klasor}"
      unless File.exists?(hedef_klasor) 
        Dir.mkdir(hedef_klasor) 
        puts "K #{$klasor2}#{klasor}"
      end
      File.copy("#{$klasor1}#{dosya}", hedef_klasor)
    end
    
    # serDiff.rb
    #
    arr1, arr2 = [], []
    Find.find($klasor1) { |file| arr1 << file.slice($klasor1.length..-1) unless File.directory?(file) }
    Find.find($klasor2) { |file| arr2 << file.slice($klasor2.length..-1) unless File.directory?(file) }
    [arr1, arr2].each { |arr| arr.sort! }
    
    arr1.each do |file|
      
      if arr2.include?(file)
        # yeni eklenen satırlar
        adet1 = satir_adet(file, $klasor1)
        adet2 = satir_adet(file, $klasor2)
        if adet1 > adet2
          fark = adet1-adet2
          puts "D #{file} : #{adet1-adet2}"
          satir_kopyala(file, fark)
        end
      else
        # yeni eklenen dosyalar
        puts "Y #{file}"
        dosya_kopyala(file)
      end
      
    end

  2. #2
    Join Date
    Jan 2009
    Posts
    10

    Lightbulb

    Quote Originally Posted by mr.applesauce View Post
    1. All the stdout text is written in your native language
    Just to clarify. The aren't any stdout texts in my native language (Turkish) or any language.
    # lines are Ruby comments. The tool only print this texts:

    1. Y FILENAME means new file
    2. D FILENAME : COUNT means added COUNT lines end of FILENAME
    3. K DIR means created a new directory


    Quote Originally Posted by mr.applesauce View Post
    2. Its written in the ruby programming language
    I don't think it's a problem. I like coding with Ruby language.

Similar Threads

  1. How to merge DA SPF with GoogleApps SPF?
    By ditto in forum E-Mail
    Replies: 18
    Last Post: 01-22-2010, 01:34 AM
  2. Enhanced skin (dutch language file) DA version 1.34.4
    By Djunity in forum Skin Releases
    Replies: 0
    Last Post: 12-09-2009, 11:36 AM
  3. Merge 2 nameservers
    By nieuwhier in forum DNS
    Replies: 0
    Last Post: 01-10-2008, 09:01 AM
  4. account move/merge
    By bashy in forum Admin-Level Difficulties
    Replies: 3
    Last Post: 12-22-2006, 01:17 AM
  5. Language history file
    By Hunter in forum General Technical Discussion & Troubleshooting
    Replies: 1
    Last Post: 11-04-2004, 06:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •