Sha256: 26176a03bea1400518841849b9fa27a2e31efbc484c8bc4566902d75a065c258

Contents?: true

Size: 832 Bytes

Versions: 21

Compression:

Stored size: 832 Bytes

Contents

module I18n
  module Tasks
    module RelativeKeys
      # @param key [String] relative i18n key (starts with a .)
      # @param path [String] path to the file containing the key
      # @return [String] absolute version of the key
      def absolutize_key(key, path, roots = relative_roots)
        # normalized path
        path = File.expand_path path
        (path_root = roots.map { |path| File.expand_path path }.sort.reverse.detect { |root| path.start_with?(root + '/') }) or
            raise "No relative key root detected for \"#{key}\" at #{path}. Please set relative_roots in config/i18n-tasks.yml (currently set to #{relative_roots})"
        # key prefix based on path
        prefix = path.gsub(%r(#{path_root}/|(\.[^/]+)*$), '').tr('/', '.').gsub(%r(\._), '.')
        "#{prefix}#{key}"
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
i18n-tasks-0.2.17 lib/i18n/tasks/relative_keys.rb