i18n-tasks icon indicating copy to clipboard operation
i18n-tasks copied to clipboard

defining `one`, `other` is detected as missing keys.

Open nov opened this issue 2 years ago • 10 comments

with the latest i18n-tasks gem, defining those keys

ja:
  foo:
    one: いち
en:
  foo:
    one: One

then others are detected as missing, even when it's not actually required by application.

% bundle exec i18n-tasks missing
#StandWithUkraine
Missing translations (2) | i18n-tasks v1.0.12
+--------+-----+----------------------------------+
| Locale | Key | Value in other locales or source |
+--------+-----+----------------------------------+
|   en   | foo | other                            |
|   ja   | foo | other                            |
+--------+-----+----------------------------------+

nov avatar Sep 26 '22 08:09 nov

probably fixing https://github.com/glebm/i18n-tasks/issues/464 caused another bug.

nov avatar Sep 26 '22 08:09 nov

Yeah, there is no longer any special handling for these keys (because the previous heuristic missed some legitimate non-plural keys).

One option to improve this in i18n-tasks would be to determine whether a key is plural by looking at how it is used.

For now, you can work around this by adding such keys to ignore_missing.

glebm avatar Sep 26 '22 10:09 glebm

I am assuming you have foo.other defined in en but not ja, right?

glebm avatar Sep 26 '22 10:09 glebm

no, I'm not defining foo.other anywhere.

nov avatar Sep 26 '22 10:09 nov

Interestingly, with

foo:
  one: One
  two: Two

other is reported as missing.

foo:
  one: One
  two: Two
  three: Three

no missing keys.

nov avatar Sep 26 '22 10:09 nov

How're you using this key (the t(...) call)?

glebm avatar Sep 26 '22 10:09 glebm

actually, we're overwriting datetime.distance_in_words.x_days.one and rails itself uses it via time_ago_in_words helper method.

plus, we have specs for i18n strings. our missing key spec (the first one) is failing after update i18n-tasks v1.0.11 to v1.0.12.

RSpec.describe I18n do
  let(:i18n) { I18n::Tasks::BaseTask.new }

  it do
    expect(i18n.missing_keys).to be_empty
  end

  it do
    expect(i18n.unused_keys).to be_empty
  end

  it do
    expect(i18n.inconsistent_interpolations).to be_empty
  end
end

nov avatar Sep 26 '22 11:09 nov

this is the most simple rails app including single i18n string welcome_message.one. https://github.com/nov/i18n_demo

you'll see the missing other by running bundle exec i18n-tasks missing.

nov avatar Sep 26 '22 11:09 nov

I'm seeing something similar when only other is defined.

en:
  some_key:
    other: this is flagged as unused

some_key.other is flagged as unused and some_key.one as missing.

patrickarnett avatar Sep 26 '22 14:09 patrickarnett

This bug is still in effect. I added a new key with

shared:
  addresses:
    guidance:
      one: "Do this"
      two: "not that"

To an existing locale file and got flagged as

Missing translations (1) | i18n-tasks v1.0.14
+--------+---------------------------+----------------------------------+
| Locale | Key                       | Value in other locales or source |
+--------+---------------------------+----------------------------------+
|   en   | shared.addresses.guidance | other                            |
+--------+---------------------------+----------------------------------+

Renaming the new keys to first and second

shared:
  addresses:
    guidance:
      first: "Do this"
      second: "not that"

and the warning no longer appears

colinbruce avatar Jun 05 '24 12:06 colinbruce