Sha256: fc4eb14c2c80be6c388562a8a703c42ca8c1acd17da5c4c6514279585e0bfd8a

Contents?: true

Size: 1006 Bytes

Versions: 8

Compression:

Stored size: 1006 Bytes

Contents

# -*- encoding : utf-8 -*-

class Phrase::Tool::Formats::Xml < Phrase::Tool::Formats::Base
  def self.directory_for_locale(locale)
    if locale.default?
      "values" 
    else
      name = locale.code || locale.name
      "values-#{formatted(name)}"
    end
  end
  
  def self.filename_for_locale(locale)
    "strings.xml"
  end

  def self.target_directory
    "res/"
  end
  
  def self.extract_locale_name_from_file_path(file_path)
    return default_locale_name if file_path.scan(/\/values\/strings.xml/i).first
    locale_part = file_path.scan(/\/values-([a-zA-Z\-_]*)\/strings.xml/i).first.try(:first)
    if locale_part and locale_part.include?("-r")
      "#{locale_part.split("-r").first}-#{locale_part.split("-r").last}"
    else
      locale_part
    end
  end
  
  def self.locale_aware?
    true
  end
  
  def self.formatted(name)
    return name unless name.include?("-")
    parts = name.split("-")
    "#{parts.first}-r#{parts.last.upcase}"
  end
  private_class_method :formatted
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
phrase-0.4.1 lib/phrase/tool/formats/xml.rb
phrase-0.4.0 lib/phrase/tool/formats/xml.rb
phrase-0.3.7 lib/phrase/tool/formats/xml.rb
phrase-0.3.6 lib/phrase/tool/formats/xml.rb
phrase-0.3.5 lib/phrase/tool/formats/xml.rb
phrase-0.3.4 lib/phrase/tool/formats/xml.rb
phrase-0.3.3 lib/phrase/tool/formats/xml.rb
phrase-0.3.2 lib/phrase/tool/formats/xml.rb