Sha256: 73665f540072fc7b06df012373c2cf3b53a10f74c155da4638624e8b0a55a846

Contents?: true

Size: 958 Bytes

Versions: 19

Compression:

Stored size: 958 Bytes

Contents

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

class Phrase::Formats::Custom < Phrase::Formats::Base
  def self.directory_for_locale(locale, format)
    setting = config.locale_directory
    return unless setting
    parse(setting, locale, format)
  end

  def self.filename_for_locale(locale, format)
    setting = config.locale_filename
    return unless setting
    parse(setting, locale, format)
  end

  def self.target_directory
    config.target_directory
  end

  def self.parse(str, locale, format)
    str.gsub(/#{regexp(locale, format)}/) do |match|
      replacements(locale, format)[match]
    end
  end
  private_class_method :parse

  def self.regexp(locale, format)
    "(#{replacements(locale, format).keys.join('|')})"
  end

  def self.replacements(locale, format)
    {
      '<domain>' => config.domain,
      '<format>' => format,
      '<locale.name>' => locale.name,
      '<locale.code>' => locale.code,
      '<locale>' => locale.name
    }
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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