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

[BUG] When exporting as JSON, keys containing a dot (.) are converted it into nested objects. #1410

Closed
LocalMonero opened this issue Oct 28, 2022 · 15 comments · Fixed by #1463 or #1464

Comments

@LocalMonero
Copy link

According to the IETF JSON RFC, essentially any string of Unicode characters may be a key in a JSON. There are no rules as to the special interpretation of a key that contains a dot (.) character as a shorthand to a nested object or any other such thing.

One of the most popular web frameworks, Laravel, allows and suggests the use of translation strings as keys:

For applications with a large number of translatable strings, defining every string with a "short key" can become confusing when referencing the keys in your views and it is cumbersome to continually invent keys for every translation string supported by your application.

This results in code that's much easier to read and maintain:

    <p>
      {{__("I love programming.")}}
    </p>

Instead of:

    <p>
      {{__("programming_string")}}
    </p>

When importing a JSON file with such key:value entries into Tolgee it works fine. Take, for instance, this Spanish .json:

{
    "I love programming.": "Me encanta programar."
}

Imports correctly:

1

Now, if we export the Spanish translation through the export tool as .json, we get the following output:

{
  "I love programming" : {
    "" : "Me encanta programar."
  }
}

Why? Because Tolgee interprets the . at the end of I love programming. as a reference to a nested object.

Please either bring the JSON export functionality in line with the IETF RFC or give us the option as to how to interpret the dots in the JSON keys for those who rely on such exports.

@JanCizmar
Copy link
Contributor

Hello,

Thanks for letting us know!

First of all, the approach Laravel people suggest we consider the bad practice. This naming can lead to reusing the same keys in different contexts, which can lead to wrong translations. For example key "Close" can be translated as "Dismiss" in one context and "Near" in another.

Perfect localization is crucial for Tolgee, and similar practices can cause a lot of trouble in the future. If you don't want to invent the keys, you can generate a random UUID as a key name.

You can modify the current exporting behavior if you use the export endpoint. https://tolgee.io/api#tag/Export/operation/export_1

Using GET https://app.tolgee.io/v2/projects/export, you can provide empty splitByScopeDelimiter.

https://app.tolgee.io/v2/projects/export?splitByScopeDelimiter=

This makes it return the files you desire.

Notice that this parameter will be renamed structureDelimiter in the next major release since Tolgee will introduce namespaces.

Anyway, it's not a bug, and the JSON we return is perfectly valid. It's just how Tolgee works and what's how Tolgee expects the files to look in its native integrations.

@LocalMonero
Copy link
Author

Please add the relevant information into the docs.

@JanCizmar
Copy link
Contributor

Feel free to submit PR to docs repository . Otherwise, we will provide better docs for other than JS technologies with All format support, which is on our roadmap

@adanielyan
Copy link

This query param doesn't seem to work with this API:
https://app.tolgee.io/v2/projects/translations/es-ES

@JanCizmar
Copy link
Contributor

This query param doesn't seem to work with this API:
https://app.tolgee.io/v2/projects/translations/es-ES

Yeah, you should use https://app.tolgee.io/v2/projects/export.

@adanielyan
Copy link

The problem is that this endpoint returns a zip file. I cannot use it in my app where I need a JSON response from API.

@panther7
Copy link

panther7 commented Jan 4, 2023

still issue,

old api is ok:

/export?format=JSON&splitByScope=false&splitByScopeDelimiter=~&splitByScopeDepth=0&filterState=UNTRANSLATED&filterState=TRANSLATED&filterState=REVIEWED&zip=true

new api is "broken"

/export?format=JSON&structureDelimiter=&filterState=UNTRANSLATED&filterState=TRANSLATED&filterState=REVIEWED&zip=true

@JanCizmar
Copy link
Contributor

Are you using v3.alpha version?

@panther7
Copy link

panther7 commented Jan 4, 2023

Which is test endpoit for v3? /v3/.../export/?

I tested: https://app.tolgee.io/v2/projects/1205/export

@JanCizmar
Copy link
Contributor

V3 is isn't released yet. Will be released on 11th January.

@panther7
Copy link

panther7 commented Jan 4, 2023

And some endpoit for test? For my issue

@JanCizmar
Copy link
Contributor

There is currently no test endpoint.

@panther7
Copy link

panther7 commented Jan 4, 2023

Ok, we hope, that it will be functional. :)

In future, is good point of test endpoit for devs.

@JanCizmar
Copy link
Contributor

We should have to deprecate the old endpoint at first and remove it later. So there wasn't the need to switch immediately. Next time we will do a better job. ⛳

@cyyynthia
Copy link
Collaborator

You can easily spin up a test instance on your local machine via Docker as well. v3.0.0-alpha5 images are available for use (and do have the structureDelimiter paramerers).

https://tolgee.io/platform/self_hosting/running_with_docker

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