guigrpa / mady

An easy-to-use tool to manage and translate ICU MessageFormat messages
MIT License
90 stars 11 forks source link

Feature requests: SSR support, description support #14

Closed sullivanpt closed 6 years ago

sullivanpt commented 6 years ago

Kudos for building this. There's a lot to like, especially the seamless extract, auto-translate, edit, import cycle and the lovely UI. I think with a few enhancements it could be great!

In summary, I think you should consider teaming up with this project (https://github.com/format-message/format-message) as it has superior cli tooling for offline translation, and the mark up supports explicit IDs and description strings (quite a bit of file format work would be needed for the collaboration).

The biggest blocker for my use is the lack of a self-contained state object; something like "_t.namespace()". Or alternatively adding an option to pass the targeted locale to each invocation of _t like "_t(msg, params, locale)". The global functions like _t.setLocales don't work server side where the locale varies by the request context.

Update: actually, I can use mady pretty efficiently for SSR as is, as long as I define a wrapper function like so

function lclTranslate (message, args, locale) {
  _t.setLocales(locale)
  _t(message, args)
}
guigrpa commented 6 years ago

Thanks for the kind words, and for the suggestion to team up with format-message. I didn't know this project!

Regarding SSR, as long as SSR runs synchronously (as in React), there should be no problem isolating user requests. If you need to load some data before rendering, I'd suggest setting Mady's language after fetching the data and just before rendering, so that no other user request interferes.

Btw, you can also add all locales to Mady (_t.addLocales(lang, locale)) and then just run _t.setLocales(lang) to choose the language, e.g. depending on a cookie or query parameter.

I'm closing this issue now, but feel free to reopen if necessary. And if there's some tool you're building with Mady, please share!