-
Notifications
You must be signed in to change notification settings - Fork 114
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] plugin-inlang-json and plugin-inlang-i18next compile namespaces to invalid js #1577
Comments
Also seems like lint rules don't play good with these plugins:
Using the same setup as above. Do you want me to open separate issue for this? |
Ha. Good observation. Namespaces can't be used for paraglide as there is no need for them and namespace ids are invalid JS. I recommend installing the
That seems to be a bug. I opened #1578 |
Regarding this issue, you can't use IDs with invalid JS. That is a limitation that is outside of our control. I can improve the error message however. A suggestion on how we can explain the must be valid JS id limitation? |
What? :D I didn't really get what you mean, but.. The original problem here is that me and or any other user would like to split t10s message file somehow, for example just so it could be easier to navigate through t10s and edit them manually. Here is my thinking process:
I understand that there is a huge take about web editor and vscode extension, but I though you agreed that t10s files should still be editable by hand with no huge tradeoffs or problems.
That's just about how paraglide code generates (compiles) message files, isn't it? When I set up the project and tried to compile with namespaces, I was expecting to see something like: export const global = {
hello() {
const variants = {
"en": `world`,
"ru": `мир`,
"zh": `世界`
}
return variants[languageTag()] ?? "global.hello"
} I definitely had to put this into "Expected behavior" 🤔
Of course, this is the reason why I opened this issue :)
Not sure how is this out of control. There is a setting which allows to use namespaces, however they just don't work. I guess this was caused by breaking changes in paraglide and it's behavior or concept. How this feature worked before? I just started working on t10s for my project, and here is my WIP en.json
Here you can see double " Now it may sound like I am requesting another feature "deep keys", but honestly I would just be satisfied to be able to use namespaces, as it would reduce nesting by one level + break up one Also I am not sure, but seems like "storage plugin" is also responsible for "message format". If I understood right, in future this may cause huge tradeoffs for me making this choice now. For example in feature support like "plurals", ICU support and all that i18n logic related stuff which at first glance should not be related to the way you store your messages. Also while typing this I think that it would probably affect web editor and ide extension really much and a huge amount of work should be done in order to support deep keys or just namespaces. Now I don't understand anything even more, if I'll implement my own storage plugin, web editor won't be able to access files? Also, just for contrast, this is how we stored t10s in my previous projectWe didn't had any professional translators and whole team members were just editing messages manually, with no web UIs. But AFAIR we could even translate this amount of files through i18n-ally vscode extension, if member used vscode. Yes, this is manual implementation of namespaces and deep keys :D I mean deep keys were supported out of the box, we just wanted to store them in separate files. I described my experience and to sum up I just would love to see namespaces support (as they should work I guess? there is a setting for this). That's all for now and I don't want to take too much attention from the main work, such as first adapters for paraglide, or paraglide itself. And sorry for THAT amount of text, but I hope you can understand me. I just want to give as much useful feedback as I can. Also sorry if maybe I used some weird expressions/phrases or made mistakes, English is my secondary language yet :) Thank you for your attention ❤️ |
Maybe I am misusing or misunderstand how devs should or should not organize keys (ids) for their translations? In one team I saw t10s files each file for each language contained 1k+ lines with contents like:
And no one really cared. What do you think about all of this? |
Oh... I now got what you meant by
Could you please take a look at "reproduction" once again? I am not using any invalid js, just plain valid json. But plugin and paraglide-js generate invalid js. The issue is just about valid input, valid configuration of plugins => leads to invalid compiled So there was no sense in writing that huge texts. You just misunderstood me and/or the issue :D |
@ZerdoX-x Thanks again for the elaborate messages. I am in the moving to NYC process. Excuse my longer-than-usual reply times. It is key to understand that a) inlang is an ecosystem of products, plugins, and tools that work together but b) each product is "its own product". The inlang SDK/platform has no concept of namespaces and neither does paraglide-js (which uses the inlang SDK to compile messages). The plugin-json, which provides the messages for the SDK, however, does have the concept of namespaces, unbeknown to the SDK and Paraglide-JS. The plugin JSON resolves namespaces with In short, the way the plugin json (unbeknown to paraglide-js) resolves namespaces, breaks JS and therefore paraglide-js. We take the currently strong stance that namespacing is a redundant concept that exists for legacy manual optimization reasons. Introducing namespacing in the SDK to be used by paraglide-js would lead to a lot of additional complexity which has no benefit other than developers splitting their translation files manually. Due to tree-shaking this splitting is not required. In large projects, developers don't even touch the translation files.
All of those feature are related to how they are stored :) Without storing features like variants, pluralization, etc, those features can't be implemented. We have a discussion going to rename "storage plugin" to import and export plugin. I created an issue #1585. Your feedback is appreciated whether the proposal makes it easier to understand why the namespace exports are not working.
The moment you nest (namespace) messages in an object, you break tree-shaking and will end up with a potentially large bundle size. Hence, the following leads to unexpected behavior. export const global = {
hello() {
const variants = {
"en": `world`,
"ru": `мир`,
"zh": `世界`
}
return variants[languageTag()] ?? "global.hello"
}
Don't organize them ;) The requirement of organizing messages in different files is usually to lower the bundle sizes. A flat key-value storage schema would lead to massive bundle sizes. The opposite is true for paraglide-js. A flat file that exports JS functions is tree-shakable by a bundler, auto-optimizing the bundle size in a manner that no manual namespacing could. In short, I strongly recommend a flat snake_case storage structure, and you should be good to go. |
Hmm.. Okay. This made it clearer, thank you for the explanation. So.. why this setting even exists in plugin json if it doesn't applicable to inlang and paraglide? |
I updated the inlang message format (v2) to by human editable, hopefully resolving this issue because the need for the json and i18next plugin does not exist anymore. See https://inlang.com/m/reootnfj/plugin-inlang-messageFormat |
I can see namespaces options have been removed in both of mentioned plugins. I guess, issue can be closed. It's no longer possible to cause invalid code generation using regular settings :) |
From my perspective, this suggestion primarily aims to improve the DX. Utilizing a single .json file that contains hundreds of keys significantly deteriorates DX, especially for those who do not use Visual Studio Code along with the Inlang plugin. I wonder if it would be feasible to introduce namespacing by directories within the "plugin.inlang.messageFormat": {
"pathPattern": "./src/json/{languageTag}.json"
} the directory then becomes the namespace within the compiled message? So for example having a "title" key in this file: turns into ...
"auth_title": "Authentication setup"
... in the root |
@herr-ahman what you describe can be implemented by importer/exporter plugins with #1585. But, we won't recommend it, and likely won't implement in plugins maintained by us. Naming keys is too flaky and will break at several points, no matter how good inlang tries to mitigate the problems. We will introduce #1892 which hopefully puts an end to (excuse me haha) requests like yours that stem from naming stuff. You can read the docs about 1892 here. |
Problem
Quote from: #1464 (reply in thread)
The issue is that plugin compiles messages to invalid javascript:
Expected behavior
At least valid code generation :)
Reproduction
project.inlang.json
static/t10s/global/en.json
npx @inlang/cli machine translate
messages.js
Other information
@latest
versionplugin-inlang-i18next@latest
The text was updated successfully, but these errors were encountered: