Sha256: 01dbe076772496fde4e5cc865e1d504af36149308aaee89dab3733333461b084

Contents?: true

Size: 1.17 KB

Versions: 19

Compression:

Stored size: 1.17 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

19 entries across 19 versions & 1 rubygems

Version Path
phrase-0.4.33 lib/phrase/formats/xml.rb
phrase-0.4.32 lib/phrase/formats/xml.rb
phrase-0.4.31 lib/phrase/formats/xml.rb
phrase-0.4.30 lib/phrase/formats/xml.rb
phrase-0.4.29 lib/phrase/formats/xml.rb
phrase-0.4.28 lib/phrase/formats/xml.rb
phrase-0.4.27 lib/phrase/formats/xml.rb
phrase-0.4.26 lib/phrase/formats/xml.rb
phrase-0.4.25 lib/phrase/formats/xml.rb
phrase-0.4.24 lib/phrase/formats/xml.rb
phrase-0.4.23 lib/phrase/formats/xml.rb
phrase-0.4.22 lib/phrase/formats/xml.rb
phrase-0.4.21 lib/phrase/formats/xml.rb
phrase-0.4.20 lib/phrase/formats/xml.rb
phrase-0.4.19 lib/phrase/formats/xml.rb
phrase-0.4.18 lib/phrase/formats/xml.rb
phrase-0.4.17 lib/phrase/formats/xml.rb
phrase-0.4.16 lib/phrase/formats/xml.rb
phrase-0.4.15 lib/phrase/formats/xml.rb