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

For nested pluralization keys, i18n-ally usage report inaccurately indicates unused/not found keys #953

Closed
mkevinosullivan opened this issue Jun 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@mkevinosullivan
Copy link
Contributor

Describe the bug
When using nested pluralization keys, e.g., with a locale file like

{
  "levelOne" : {
    "levelTwo": {
      "one": "{{count}} level",
      "other": "{{count}} levels"
    },
  }
}

and a code snippet of

const content = t("levelOne.levelTwo", { count: count})

the usage report indicates that the levelOne.levelTwo key is missing, and that keys levelOne.levelTwo.one and levelOne.levelTwo.other are not in use.

When using nested pluralization keys, the expectation would be that levelOne.levelTwo is not reported as missing and that keys levelOne.levelTwo.one and levelOne.levelTwo.other are considered in use IF levelOne.levelTwo is used in the source file.

Extension Version
i18n Ally (v2.9.1)

Framework/i18n package you are using
react-i18next (will also apply to yet-to-be-released i18next-shopify framework, based on react-i18next)

To Reproduce
Steps to reproduce the behavior:

  1. Go to examples/by-framework/react-i18next in the i18n-ally repo
  2. Update the public/locales/en/translation.json file to be
{
  "title": "hello",
  "description": {
    "part1": "To get started, edit <1>src/App.js</1> and save to reload.",
    "part2": "Switch language between english and german using buttons above."
  },
  "titlew": "ok",
  "foo": {
    "bar": "foobar"
  },
  "messages": {
    "one": "You have {count} message.",
    "other": "You have {count} messages."
  }
}
  1. Open the src/App.jsx file and add the following component after MyComponent:
function MyMessagesComponent() {
  return <p>{t('translation:messages', { count: 1 })}</p>
}
  1. Refresh the usage report
  2. See error
    Screenshot 2023-06-23 at 12 31 12 PM

Device Information

  • OS: Mac OS
  • Version: Ventura 13.4
  • VS Code Version: 1.79.2

Extension Log
Go to View -> Output -> i18n Ally, and paste the content below.

🈶 Activated, v2.9.1

――――――

💼 Workspace root changed to "/Users/XXXXXXXXXX/src/github.com/lokalise/i18n-ally/examples/by-frameworks/react-i18next"
🌞 Enabled
🧩 Enabled frameworks: React I18next, General
🧬 Enabled parsers: json, yaml, json5

📈 Telemetry id: 135ba03d-a31d-47be-bb68-22da5751c001
[telemetry] enabled: undefined
[telemetry] user: {"version":"2.9.1","feature_auto_detection":true,"feature_annotation_in_place":true,"feature_annotations":true,"feature_disable_path_parsing":false,"feature_extract_auto_detect":false,"feature_keep_fulfilled":false,"feature_prefer_editor":false,"feature_review_enabled":true,"feature_has_path_matcher":true,"feature_has_custom_framework":false}
🚀 Initializing loader "/Users/XXXXXXXXXX/src/github.com/lokalise/i18n-ally/examples/by-frameworks/react-i18next"
📂 Directory structure: dir
🗃 Custom Path Matcher: {locale}/{namespaces}.json
🗃 Path Matcher Regex: /^(?<locale>[\w-_]+)\/(?<namespace>.+)\.json$/

📂 Loading locales under /Users/XXXXXXXXXX/src/github.com/lokalise/i18n-ally/examples/by-frameworks/react-i18next/public/locales
	📑 Loading (de) de/translation.json [1686234424753.6492]
	📑 Loading (en) en/translation.json [1687378585111.2266]
	📑 Loading (de) de/pages/home.json [1686234424752.8743]
	📑 Loading (en) en/pages/home.json [1686234424753.829]

👀 Watching change on /Users/XXXXXXXXXX/src/github.com/lokalise/i18n-ally/examples/by-frameworks/react-i18next/public/locales
✅ Loading finished
@mkevinosullivan mkevinosullivan added the bug Something isn't working label Jun 23, 2023
mkevinosullivan added a commit to Shopify/i18n-ally that referenced this issue Jun 27, 2023
Derived keys (e.g., such as plurals) were being miscategorised as
missing in the usage report.  This commit checks if keys derived from
those found in the missing list (keys that are in use but considered
"not defined") are included in the list of idle keys (keys defined but
not considered in use), indicating that they are indeed defined and in
use.

Fixes lokalise#953
mkevinosullivan added a commit to Shopify/i18n-ally that referenced this issue Jun 28, 2023
Derived keys (e.g., such as plurals) were being miscategorised as
missing in the usage report.  This commit checks if keys derived from
those found in the missing list (keys that are in use but considered
"not defined") are included in the list of idle keys (keys defined but
not considered in use), indicating that they are indeed defined and in
use.

Fixes lokalise#953
huacnlee pushed a commit to huacnlee/i18n-ally that referenced this issue Aug 28, 2023
* Return first available counting value if nested

* Add extraction support to react-i18next framework

This commit adds the `supportAutoExtraction` array of supported formats
and the `detectHardStrings` method from `GeneralFramework` to enable
hard-coded string extraction for react-i18next framework, without
needing the "general" framework to be enabled/loaded in the
`.vscode/settings.json` file.

* Add i18next-shopify framework

This commit adds the i18next-shopify framework to the list of supported
frameworks. It is an extension of the React i18next framework, with some
configuration changes.

Also add i18next-shopify example app, including a pluralization example.

* Add support for Go to Definition of a translation key

* Fixes usage report for non-missing derived keys

Derived keys (e.g., such as plurals) were being miscategorised as
missing in the usage report.  This commit checks if keys derived from
those found in the missing list (keys that are in use but considered
"not defined") are included in the list of idle keys (keys defined but
not considered in use), indicating that they are indeed defined and in
use.

Fixes lokalise#953

* Fixes Current File Panel report of not found keys

Derived keys (e.g., such as plurals) are being miscategorised as not
found in the Current File Panel report.  This commit checks if any
existing key paths match derived keys paths, and if so, includes them in
the list of in use key paths and removed from the "not found" list.

Fixes lokalise#959

* Chore: fix spellings in code base

---------

Co-authored-by: Kevin O'Sullivan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant