Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defining one, other is detected as missing keys. #473

Open
nov opened this issue Sep 26, 2022 · 10 comments
Open

defining one, other is detected as missing keys. #473

nov opened this issue Sep 26, 2022 · 10 comments
Labels

Comments

@nov
Copy link

nov commented Sep 26, 2022

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
Copy link
Author

nov commented Sep 26, 2022

probably fixing #464 caused another bug.

@glebm
Copy link
Owner

glebm commented Sep 26, 2022

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
Copy link
Owner

glebm commented Sep 26, 2022

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

@nov
Copy link
Author

nov commented Sep 26, 2022

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

@nov
Copy link
Author

nov commented Sep 26, 2022

Interestingly, with

foo:
  one: One
  two: Two

other is reported as missing.

foo:
  one: One
  two: Two
  three: Three

no missing keys.

@glebm
Copy link
Owner

glebm commented Sep 26, 2022

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

@nov
Copy link
Author

nov commented Sep 26, 2022

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
Copy link
Author

nov commented Sep 26, 2022

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.

@glebm glebm added the bug label Sep 26, 2022
@patrickarnett
Copy link

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.

@colinbruce
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants