Sha256: d0628bf3313a730fa85ba77e688b99c4cbb96bbb1b7291f79221779d67a579f9

Contents?: true

Size: 961 Bytes

Versions: 13

Compression:

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

13 entries across 13 versions & 1 rubygems

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