-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
function formatter, add basic function formatter #3171
base: main
Are you sure you want to change the base?
Conversation
Hey, my idea was to include it directly into the core basically - if there is a function instead of translation, just call the function. The approach with the plugin might be more flexible, if it works, it might be better. My biggest concern was how to solve translation updates (when user updates translation in in-context dialog). As the function for formatting is generated outside Tolgee, it has no chance of knowing how to interpret the translation. And also in development mode, translations are downloaded directly from Tolgee platform as strings. |
The plugin might work, but it will be harder to make it work with your two other points (following)
That's a good one. So if a translation is updated by the in-context dialog, I guess the in-context dialog should show the function as content. But editing it won't work, since it's a function. I see two approaches: 1) prevent using the in-context dialog for functions or 2) Since we have the translation id, we could redirect to Tolgee platform for that. Which brings to the last point:
The thing is that clearly, it is not possible to manage the function from Tolgee platform, as it can only work with strings. But we can add a layer around the tolgee platform to 1) post process the strings 2) pre-process the content sent back. So in total:
Does that seem doable/sensible? |
Yep, the post process hook could basically solve this. But it must be done in a clever way, so it's only included in dev mode. As this will basically include whole icu parser, so that would bloat your bundle unecessarly. My idea was that the post processor could run as an local server and the tolgee would hit it when necessary. But then it's more complicated setup for the user ... |
Hmm, the local server might be a good idea... It would just require a webpack/vite/etc. plugin, or, put simply an unplugin. There's documentation on adding a server directly to vite's dev server and wepack's dev server (though it only works on development mode). The plugin might actually be a good idea for more than that:
However, the burden of maintaining a plugin might not be worth it, so the post processor hook should be considered, and then translating in production should be accompanied with a message like: |
Yeah, basically I think we could have a configuration option on tolgee core to postprocess a translation after is downloaded from the platform. That should be pretty universal. And then you can have a |
This is very very rough work on adding a function formatter to tolgee core. Before I dive in deeper (I haven't actually tested the code yet, just wrote a few lines), is this the right path? Or, instead of via a plugin, do you think a function formatter should be included directly in the core formatter?
Any guidance welcome before I proceed.