sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.78k stars 145 forks source link

Internationalisation support #546

Open lizclipse opened 1 year ago

lizclipse commented 1 year ago

Alt tags (because searching for this is a PITA sometimes): internationalization, i18n, translation, t9n, localization, localisation, l10n, globalization, globalisation, g11n

I can't find any mention of how to do i18n within this library, and I think it's worth having a proper system that taps into the reactivity.

SolidJS has a pretty simple one that uses key-value translations and ties into the reactivity system, which might be a good example to base on.

Perseus uses Fluent, which out of the i18n crates in arewewebyet seems to be one of the best options. Making a crate based on that in the style of SolidJS's/Perseus's might work quite well, I'd be willing to make a POC if that sounds reasonable.

arctic-hen7 commented 1 year ago

This sounds great, but I think it would be optimal to try to maintain continuity with Perseus as much as possible, otherwise we'll end up with two completely different systems.

Unfortunately, the Perseus i18n system is very closely tied to the framework's internals....

I reckon you could break out the t! macro etc. though, and then have some kind of context provider that's left mostly up to the user. That way, we could take i18n from Perseus into a separate crate, which Perseus would then use. How does that sound @lizclipse?

lizclipse commented 1 year ago

That sounds ideal, it would make for a good base to build a standalone version on, and would prevent fragmentation. I'll have a look at how Perseus's i18n system works, and see what I can break out.

arctic-hen7 commented 1 year ago

Great! Let me know if you need any pointers! (Note especially that translators are managed with feature flags, not traits, due to internal constraints.)

Also maybe open a tracking issue for this in Perseus as well @lizclipse?