Sha256: 9de4ce2750712d3949bdc8ac1317613b1f9a4b0684c664d056320679c689f270

Contents?: true

Size: 868 Bytes

Versions: 8

Compression:

Stored size: 868 Bytes

Contents

# coding: utf-8
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 CommandError.new("Error scanning #{path}: cannot resolve relative key \"#{key}\".\nSet relative_roots in config/i18n-tasks.yml (currently #{relative_roots.inspect})")
        # key prefix based on path
        prefix = path.gsub(%r(#{path_root}/|(\.[^/]+)*$), '').tr('/', '.').gsub(%r(\._), '.')
        "#{prefix}#{key}"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
i18n-tasks-0.5.4 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.5.3 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.5.2 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.5.1 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.5.0 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.4.5 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.4.4 lib/i18n/tasks/relative_keys.rb
i18n-tasks-0.4.3 lib/i18n/tasks/relative_keys.rb