i18next-parser icon indicating copy to clipboard operation
i18next-parser copied to clipboard

Parsing translation with `returnObjects: true` replaces the object with a string

Open salockhart opened this issue 4 years ago • 12 comments

  • Is this a bug or a feature request? Bug

  • What version are you running (0.x or 1.x)? 1.0.6

  • Which runner (cli, gulp...)? cli

What I'm trying to do?

I have a namespace for translating country names. I want to request this as an object, so that I can simply iterate through the countries.

t('country:countries', { returnObjects: true })
{
  "countries": {
    "AFGHANISTAN": "Afghanistan",
    "ALAND_ISLANDS": "Aland Islands",
    "ALBANIA": "Albania",
    "ALGERIA": "Algeria",
    ...

How am I doing it?

Here is my config file:

module.exports = {
  input: ['src/**/*.{ts,tsx,js}'],
  output: 'i18n/$LOCALE/$NAMESPACE.json',

  // only write to english, since it is the fallback for other languages
  // which would be translated externally
  locales: ['en'],
};

The command I'm running:

i18next

What was the result?

After parsing, the countries object is replaced with a blank string

{
  "countries": ""
}

What was I expecting?

Translations that are marked as returning objects should not be parsed as having a string result. I would expect this to have been ignored.

salockhart avatar May 12 '20 08:05 salockhart

It's not per say a bug but a missing feature. The parser doesn't support the returnObjects option, I didn't even know it existed. You are welcome to submit a PR with the change, I don't have lots of time to work on this project atm.

karellm avatar May 13 '20 01:05 karellm

Okay, good to know! I will see about submitting a fix

salockhart avatar May 13 '20 07:05 salockhart

Any update on this? 😅

stophecom avatar Nov 17 '21 22:11 stophecom

This would be extremely helpful

wjramos avatar Jan 04 '22 01:01 wjramos

Feel free to submit a PR

karellm avatar Jan 04 '22 13:01 karellm

Same Problem

ytytsophia avatar May 18 '22 03:05 ytytsophia

Is this project maintained any more? We're looking for a parsing module for i18n but if issues like this are getting ignored for 3+ years then maybe this one is not a good idea to adopt. Thank you.

steodor avatar Jul 18 '23 11:07 steodor

@steodor The eternal question of open-source and its entitled users. Instead of expecting things to be fixed, I invite you to contribute either with code or financially to ensure things that are important to you get fixed.

On a personal note, I've been clear for years that I don't use this project and have very limited bandwidth to write code for it. I review PRs and publish new versions regularly though. If you need custom work on the parser for your company needs, you can hire me.

karellm avatar Jul 18 '23 12:07 karellm