Sha256: 153f335bf464ab96496b49438bd258f5ca6b60aec78b4326863f2211a54122fb

Contents?: true

Size: 681 Bytes

Versions: 3

Compression:

Stored size: 681 Bytes

Contents

# coding: utf-8
module I18n::Tasks::PluralKeys
  PLURAL_KEY_RE = /\.(?:zero|one|two|few|many|other)$/

  # @param [String] key i18n key
  # @param [String] locale to pull key data from
  # @return the base form if the key is a specific plural form (e.g. apple for apple.many), and the key as passed otherwise
  def depluralize_key(key, locale = base_locale)
    return key if key !~ PLURAL_KEY_RE
    node = node(key, locale)
    nodes = node.try(:siblings).presence || (locale != base_locale && node(key, base_locale).try(:siblings))
    if nodes && nodes.all? { |x| x.leaf? && ".#{x.key}" =~ PLURAL_KEY_RE }
      key.split('.')[0..-2] * '.'
    else
      key
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
i18n-tasks-0.4.5 lib/i18n/tasks/plural_keys.rb
i18n-tasks-0.4.4 lib/i18n/tasks/plural_keys.rb
i18n-tasks-0.4.3 lib/i18n/tasks/plural_keys.rb