question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using --keyasareference with duplicate text breaks when converting back to i18next

See original GitHub issue

I have the an i18next JSON source file that contains duplicate text items for different keys. One instance looks something like this:

{
  "role-a": {
    "step": {
      "intro": "Intro",
    },
  },
  "role-b": {
    "step": {
      "intro": "Intro",
    }
  }
}

I convert this to gettext with

i18next-conv --pot -l en -s source.json -b source.json -t target.pot -K

The resulting source.pot file looks like this:

#: role-a##step##intro role-b##step##intro
msgid "Intro"
msgstr ""

Now translators provide a translation in a tool supporting gettext and I convert it back to i18next JSON with

i18next-conv -l ${locale} -s source.pot -t target.json -K

The resulting i18next JSON looks like this:

{
    "role-a": {
        "step": {
            "intro role-b": {
                "step": {
                    "intro": "Intro"
                }
            },
        }
    }
}

It’s wildly different from the original JSON and broken as well.

Now I appreciate that the problem is caused by using the source string as a key which overlaps where the original msgid does not, and in any case, providing one translation for two keys results in ambiguities. However, I was hoping that the conversion would at least allow me to recover the original structure of the JSON. Am I missing something? Or am I asking the impossible?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oasalonencommented, Mar 7, 2020

But just to clarify: even if this is somehow fixed, I will not be using this approach going forward because all the instances of the ‘City’ text will get the same translation, which may not always be the case. I will use my original keys as msgids

0reactions
jamuhlcommented, Mar 9, 2020

Ah I see…while there is i18next-fluent - there is no real extraction tooling to get that saved as .ftb files…

Hm…guess that is still a good selling point for our locize.com - which works out of the box using the runtime submission of missing keys.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fallback - i18next documentation
By default, if a variant (containing region, script, etc) is not found, i18next will look for the same key in the broader version...
Read more >
React i18n break lines in JSON String - Stack Overflow
I'm struggling to break lines within the string in my JSON language file. This is what I already tried, which doesn't break a...
Read more >
React localization with i18next - LogRocket Blog
To localize a React application using the i18next, we must add the ... Using the same approach, let's translate the other text in...
Read more >
React-i18next: Internationalization and translation ... - Lokalise
Translating plain text with i18next. In this section, we are going to learn how to translate normal text from one language to another....
Read more >
Change quite option for verbose about i18next-gettext-converter
i18next commented on November 19, 2022 Change quite option for verbose ... Using --keyasareference with duplicate text breaks when converting back to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found