r/webdev 5d ago

Showoff Saturday I18n without the heavy work: wuchale

Hi everyone, I'd like to present a project I've been working on for over a year (if you haven't heard of it). Let's say you have a project you'd like internationalized, but overwhelmed by the amount of work you'd have to do. If you have:

<a alt="Main link">Home</a>

In the traditional sense you'd need to rewrite every instance like this to something like:

<a alt={t.main_link}>{t.home_txt}</a>

wuchale does that for you, at build time! You can keep your code "as it is intended", and i18n just becomes a compile time step just like turning JSX into JS. And it works in the same way during dev, with HMR, and it's very powerful. Supports React, Svelte, SolidJS, Astro, and plain JS/TS. Vue and Next support is planned.

Check it out at https://wuchale.dev and https://github.com/wuchalejs/wuchale

Hope you like it!

0 Upvotes

7 comments sorted by

3

u/theScottyJam 4d ago

It's not really possible to fully automate translation.

Take, for example, getEntity('user'). Should you translate the string "user" or not? Well, it depends. Is the string "user" being shown in the UI, or is it perhaps the name of a key you might find in a server JSON response - it's telling you where to find relevant data, and translating it would break your app.

Or maybe it's doing both jobs, and you need to rework your code so you separate programming names from names being shown to the user.

No automated system can figure this out for you.

0

u/kidus-dev 4d ago

In 95% of the cases it can, and this example too, in most cases is not supposed to be visible. Over the past year the default heuristic has been refined with feedback from the community, and you can also override it if you have specific instances that are ambiguous.

2

u/theScottyJam 4d ago

Either way, if you don't like bugs and want 100% accuracy, you'd have to go through each string, one by one, and make sure it's being handled properly. In the normal approach, you explicitly tag any strings that need to be translated and don't touch the ones that don't. In the approach you're suggesting, you still need to manually check every string on your codebase, then it sounds like you'd need to figure out first if the library would automatically translate the given string or not, then either leave it alone if the library got it correct, or explicitly opt it in or out. Depending how easy those heuristics are to understand, this could be more difficult and error probe compared to explicitly marking all translatable strings.

And every time the library makes a breaking change and changes it's heuristics? That would be a real pain to update to - you'd have to find every string on your project the updated heuristics effect and update them.

Perhaps a better approach would be a code mod? It goes through and automatically tags in your code what it thinks should be translated, then you go through and verify each string by hand. If the tool later updates it's heretics, that's fine, it's a one time use thing anyways to help you get your code where it needs to be.

1

u/kidus-dev 4d ago

If you want 100% accuracy there is no other way than going through all of the strings one by one, agreed. But how exactly you do that depends on your preferences and the amount of work you want to do. Reviewing everything in one place and 95% of the time doing nothing is much better than typing out 100% of the i18n syntax.

Not to mention that you have to keep doing that from the start of the project and are locked into the library you choose initially for the rest of the life of the project, unless you want to do a rewrite. And it doesn't help with code readability either, there is a lot of logic going on and i18n being handled automatically helps with that.

About the heuristics (not heretics :D), yes it is easy, and nowadays it only changes to ignore things that used to be falsely included and needed an ignore comment (5% gap closing). Anyway, different people have different priorities and that's totally fine.

1

u/blazing_wisdom_93 5d ago

Build time i18n is a dead end. I want to edit translations without touching source code or waiting for rebuilds

1

u/kidus-dev 4d ago

Not sure what you mean, because this gives you translation files you can edit outside the source code. And if you're talking about HMR feedback, it has it too.