Sha256: fb56c8b9261516766f946e615b524d643c48fda86ad282a7c244c4c8e6bce2c0

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

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

module Phrase
  module Formats
    class Xml < Phrase::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
      
      def self.extensions
        [:xml]
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
phrase-0.4.14 lib/phrase/formats/xml.rb
phrase-0.4.13 lib/phrase/formats/xml.rb
phrase-0.4.12 lib/phrase/formats/xml.rb
phrase-0.4.11 lib/phrase/formats/xml.rb
phrase-0.4.10 lib/phrase/formats/xml.rb
phrase-0.4.9 lib/phrase/formats/xml.rb
phrase-0.4.8 lib/phrase/formats/xml.rb
phrase-0.4.7 lib/phrase/formats/xml.rb
phrase-0.4.6 lib/phrase/formats/xml.rb
phrase-0.4.5 lib/phrase/formats/xml.rb
phrase-0.4.4 lib/phrase/formats/xml.rb
phrase-0.4.3 lib/phrase/formats/xml.rb
phrase-0.4.2 lib/phrase/formats/xml.rb