i18n-tasks 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f58d7230282098539847235735bc09557e3fd32099b2ead2ce9fc7287c4969db
4
- data.tar.gz: 6e1770f00a2d53ce2a9230207bd8fd18934ab513c756e076b6f383427323a092
3
+ metadata.gz: 0421245b4fe6deb24eea33dfad64824082a922b001c715752fe6eeb46e11dad0
4
+ data.tar.gz: 37fc213cb277308d2a674d96ded8e04771e1d3b9dff00769fb547c302dc7ed9b
5
5
  SHA512:
6
- metadata.gz: f6d4ffa008c35b7969e9ca339070d03c37b52596a39daac89ad03a59c0c5a2518e6f3e684faab7717000de5685f3c7b8c1270d5fc7770c4c650ada28edb98a60
7
- data.tar.gz: 6939446588b8a0775257fd25b55d2ce1868b8a644531aea244cf69bbe088f303c181ea744065f7569c3dd277a149738dbc8c285802fe67cb6ab0ba35d37b7cf7
6
+ metadata.gz: 021c6346d749fd8d38f7286fa41bb6b6de663a37f1a13eb5b1aae2acaec28f640095faa7136ab1b4fc5d89c02a055126d3ba5655776c73cd33160fe6f06d329c
7
+ data.tar.gz: 4e137eab8dc05d80d03892d8ac119fc438cca22439b004f0b14686cefa5783ee64568a634451d27739ed55dc31b4a6d4f30dbf442cd6f6ab747198f690253b75
data/README.md CHANGED
@@ -71,7 +71,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
71
71
  1. Add to your `Gemfile`:
72
72
 
73
73
  ```ruby
74
- gem 'i18n-tasks', '~> 1.2.0', group: :development
74
+ gem 'i18n-tasks', '~> 1.2.1', group: :development
75
75
  ```
76
76
 
77
77
  2. Copy the default [configuration file](#configuration):
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bigdecimal/util"
3
4
  require "set"
4
5
  module I18n::Tasks::PluralKeys
5
6
  # Ref: http://cldr.unicode.org/index/cldr-spec/plural-rules
@@ -25,7 +25,7 @@ module I18n::Tasks::Scanners::AstMatchers
25
25
  return if value.nil?
26
26
  return unless %i[str sym].include?(value.type) || adjacent_string_literals?(value)
27
27
 
28
- model_name = underscore(receiver.to_a.last)
28
+ model_name = model_key(receiver)
29
29
  attribute = extract_string(value)
30
30
  # Convert dots to slashes to match Rails' human_attribute_name behavior
31
31
  # Rails converts "status.active" in Product.human_attribute_name("status.active")
@@ -63,7 +63,7 @@ module I18n::Tasks::Scanners::AstMatchers
63
63
 
64
64
  return unless class_node&.type == :const && base_children[1] == :model_name
65
65
 
66
- model_name = underscore(class_node.to_a.last)
66
+ model_name = model_key(class_node)
67
67
  key = "activerecord.models.#{model_name}"
68
68
  [
69
69
  key,
@@ -74,6 +74,16 @@ module I18n::Tasks::Scanners::AstMatchers
74
74
  ]
75
75
  end
76
76
 
77
+ # Foo::Bar -> "foo/bar", like Rails' model_name.i18n_key
78
+ def model_key(const_node)
79
+ names = []
80
+ while const_node&.type == :const
81
+ names.unshift(underscore(const_node.children[1]))
82
+ const_node = const_node.children[0]
83
+ end
84
+ names.join("/")
85
+ end
86
+
77
87
  def underscore(value)
78
88
  value = value.to_s.dup
79
89
  value.gsub!(/(.)([A-Z])/, '\1_\2')
@@ -315,6 +315,8 @@ module I18n::Tasks::Scanners::PrismScanners
315
315
  current_class.path.flatten.map!(&:underscore).join("/")
316
316
  elsif node.receiver&.receiver&.type == :constant_read_node
317
317
  node.receiver&.receiver&.name&.to_s&.underscore
318
+ elsif node.receiver&.receiver.is_a?(Prism::ConstantPathNode)
319
+ node.receiver.receiver.full_name.gsub(/^::/, "").gsub("::", "/").underscore
318
320
  end
319
321
 
320
322
  return if model_name.nil?
@@ -20,9 +20,10 @@ module I18n
20
20
  strict = strict?(strict)
21
21
  used_key_names ||= used_tree(strict: true).key_names.to_set
22
22
  collapse_plural_nodes!(data[locale].select_keys do |key, _node|
23
+ depluralized_key = depluralize_key(key, locale)
23
24
  !ignore_key?(key, :unused) &&
24
- (strict || !used_in_expr?(key)) &&
25
- !key_used?(depluralize_key(key, locale), used_key_names)
25
+ (strict || !(used_in_expr?(key) || used_in_expr?(depluralized_key))) &&
26
+ !key_used?(depluralized_key, used_key_names)
26
27
  end)
27
28
  end
28
29
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Tasks
5
- VERSION = "1.2.0"
5
+ VERSION = "1.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm