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

Conflict and Error When Push/Pull Plural Keys #145

Closed
soapproject opened this issue Jan 6, 2025 · 4 comments
Closed

Conflict and Error When Push/Pull Plural Keys #145

soapproject opened this issue Jan 6, 2025 · 4 comments
Assignees

Comments

@soapproject
Copy link

soapproject commented Jan 6, 2025

Apologies, I'm not sure if this issue should be filed under CLI or another project.

Description:

I encountered an issue when push/pull plural keys with Tolgee and react-i18next integration. Here's the situation:

  1. I configured a key foo.bar as plural in Tolgee.
    image

  2. When I run tolgee pull --api-key tgpak_xxx, the translation file generates the following structure:

// public/i18n/{ns}/{lng}.json
{
  "foo": {
    "bar_other": "These are {{count}} books.",
    "bar_one": "This is a book."
  }
}
  1. When I push this file back, a conflict warning appears. Selecting "KEEP" results in Tolgee adding an additional foo.bar_other key on the platform.
    image

  2. On the next pull, the cli fails with the following error:

🔴 API reported a server error. Please try again later [status: 500, code: unexpected_error_occurred]

And docker logs

   io.tolgee.ExceptionHandlers : java.lang.IllegalStateException: Cannot add item to node. This is a bug, data should be sorted by key name path. Path: foo.bar_other
  1. If I delete the additional foo.bar_other key, the pull works as normal.

Environment:

tolgee/tolgee:latest: amd/64 sha256:8cdf62883cde1b9305d8995175d17133ec968b4c868bea5d586212b440846958
@tolgee/cli: 2.4.1
.tolgeerc:

{
  "$schema": "https://docs.tolgee.io/cli-schema.json",
  "projectId": 4,
  "apiUrl": "https://xxx.com",
  "format": "JSON_I18NEXT",
  "pull": {
    "path": "/home/xxx/ws/test-tolgee/public/i18n"
  },
  "push": {
    "files": [
      {
        "path": "/home/xxx/ws/test-tolgee/public/i18n/common/en.json",
        "language": "en",
        "namespace": "common"
      },
      {
        "path": "/home/xxx/ws/test-tolgee/public/i18n/common/ja.json",
        "language": "ja",
        "namespace": "common"
      },
      {
        "path": "/home/xxx/ws/test-tolgee/public/i18n/common/zh-Hans.json",
        "language": "zh-Hans",
        "namespace": "common"
      },
      {
        "path": "/home/xxx/ws/test-tolgee/public/i18n/common/zh-Hant.json",
        "language": "zh-Hant",
        "namespace": "common"
      }
    ]
  }
}

How to Reproduce:

  1. Use Next.js to initialize a project with the default settings:
    npx create-next-app@latest
  2. Install Tolgee CLI.
  3. Create a Tolgee project with a namespace and set zh-Hant as the base language.
  4. Create some keys and set plural in Tolgee.
  5. Config .tolgeerc and run tolgee pull --api-key tgpak_xxx , tolgee push --api-key tgpak_xxx to sync translations.
  6. Handle conflicts by selecting "KEEP", then try pulling again.
@JanCizmar JanCizmar self-assigned this Jan 6, 2025
@JanCizmar
Copy link
Contributor

Hey!

Thanks you very much for reporting. I believe this is issue for @Anty0, who is responsible for the i18next support!

@Anty0
Copy link
Collaborator

Anty0 commented Jan 6, 2025

Thanks for the report! I'll try to reproduce the issue and let you know how it goes!

@Anty0
Copy link
Collaborator

Anty0 commented Jan 8, 2025

I was able to reproduce the issue!

Caused by: Some languages have only single plural form (for example the zh-Hant). When deciding wether the key is plural or not during import we check if there are multiple keys matching the the plural keywords and since there is only one such key for those languages Tolgee assumes the key is not a plural and creates separate entry for it.

Fix: tolgee/tolgee-platform#2820

Thank you for reporting the issue! Happy localizing!

@Anty0
Copy link
Collaborator

Anty0 commented Jan 14, 2025

Fixed in v3.92.6 🎉

@Anty0 Anty0 closed this as completed Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants