doc/send-translations.rb
# Handle data with full key value key
Handle data with full key value key
Handle data with full key value key
def process_data(lang, key, data)
  if data.is_a?(Hash)
    data.each do |subkey, subdata|
      subkey_fullname = key + (key == '' ? '' : '.') + subkey
      process_data(lang, subkey_fullname, subdata)
    end
  elsif data.is_a?(String)
    if $CURRENT_TRANSLATIONS[lang].key?(key)
      this_current_translation = $CURRENT_TRANSLATIONS[lang][key]['target']
                                 .rstrip
      new_translation = data.rstrip
      if this_current_translation != new_translation
        id = $CURRENT_TRANSLATIONS[lang][key]['id']
        puts "CHANGE TRANSLATION #{lang} KEY \"#{key}\""
        puts " \"#{this_current_translation}\""
        puts "=> id: #{id}"
        puts " \"#{new_translation}\""
        puts
        if !change_translation(id, new_translation)
          STDERR.puts "Failed to update #{key} - halting"
          exit 1
        end
      end
    else
      new_translation = data
      if !$SOURCE.key?(key)
        STDERR.puts "Source does not have key #{key}"
        exit 1
      end
      source = $SOURCE[key]
      puts "ADD TRANSLATION #{lang} KEY \"#{key}\":"
      puts " \"#{source}\""
      puts ' =>'
      puts " \"#{new_translation}\""
      puts
      if !post_translation(key, lang, source, new_translation)
        STDERR.puts "Failed to insert new translation for #{key} - halting"
        exit 1
      end
    end
  elsif data.nil?
  else
    STDERR.puts "Error: Bad class. Value '#{data}' has type #{data.class}"
    exit 1
  end
end
def process_data ( lang , key , data ) if data . is_a? ( Hash ) data . each do | subkey , subdata | subkey_fullname = key + ( key == '' ? '' : '.' ) + subkey process_data ( lang , subkey_fullname , subdata ) end elsif data . is_a? ( String ) if $CURRENT_TRANSLATIONS [ lang ] . key? ( key ) this_current_translation = $CURRENT_TRANSLATIONS [ lang ] [ key ] [ 'target' ] . rstrip new_translation = data . rstrip if this_current_translation != new_translation id = $CURRENT_TRANSLATIONS [ lang ] [ key ] [ 'id' ] puts "CHANGE TRANSLATION #{lang} KEY \"#{key}\"" puts " \"#{this_current_translation}\"" puts "=> id: #{id}" puts " \"#{new_translation}\"" puts if ! change_translation ( id , new_translation ) STDERR . puts "Failed to update #{key} - halting" exit 1 end end else new_translation = data if ! $SOURCE . key? ( key ) STDERR . puts "Source does not have key #{key}" exit 1 end source = $SOURCE [ key ] puts "ADD TRANSLATION #{lang} KEY \"#{key}\":" puts " \"#{source}\"" puts ' =>' puts " \"#{new_translation}\"" puts if ! post_translation ( key , lang , source , new_translation ) STDERR . puts "Failed to insert new translation for #{key} - halting" exit 1 end end elsif data . nil? else STDERR . puts "Error: Bad class. Value '#{data}' has type #{data.class}" exit 1 end end
Handle data with full key value key
Handle data with full key value key
# Potential change to an existing translation # Translation has changed! # Entirely NEW entry. # Ignore nil values # Crash, something went wrong
lang
<not_specific>
key
<not_specific>
data
<not_specific>