Live data from Hacker News

Show HN: Localize React apps without rewriting code

github.com

1–10 of 75 posts

Show HN: Localize React apps without rewriting code

#1
Hi HN! We've just released an open-source React bundler plugin that makes apps multilingual—at build time, without modifying the code.

React app localization typically requires implementing i18n frameworks, extracting text to JSON files, and wrapping components in translation tags - essentially rewriting your entire codebase before you can even start translating.

Our React bundler plugin eliminates this friction entirely. You add it to an existing React app, specify which languages you want, and it automatically makes your app multilingual without touching a single line of your component code.

Here's a video showing how it works: https://www.youtube.com/watch?v=sSo2ERxAvB4. The docs are at https://lingo.dev/en/compiler and, sample apps at https://github.com/lingodotdev/lingo.dev/tree/main/demo.

Last year, a dev from our Twitter community told us: "I don't want to wrap every React component with `` tags or extract strings to JSON. Can I just wrap the entire React app and make it multilingual?"

Our first reaction was "That's not how i18n works in React." But a couple hours later, we found ourselves deep in a technical rabbit hole, wondering what if that actually was possible?

That question led us to build the "localization compiler" - a middleware for React that plugs into the codebase, processes the Abstract Syntax Tree of the React code, deterministically locates translatable elements, feeds every context boundary into LLMs, and bakes the translations back into the build, making UI multilingual in seconds.

Everything happens locally during build time, keeping the React project as the source of truth. No code modifications, no extraction, and no maintenance of separate translation files are needed, however, overrides are possible via data-lingo-* attributes.

Building this was trickier than we expected. Beyond traversing React/JS abstract syntax trees, we had to solve some challenging problems. We wanted to find a way to deterministically group elements that should be translated together, so, for example, a phrase wrapped in the `` link tag wouldn't get mistranslated because it was processed in isolation. We also wanted to detect inline function calls and handle them gracefully during compile-time code generation.

For example, this entire text block that our localization compiler identifies as a single translation unit, preserving the HTML structure and context for the LLM.

``` function WelcomeMessage() { return ( Welcome to our platform! Get started today. ); } ```

The biggest challenge was making our compiler compatible with Hot Module Replacement. This allows developers to code in English while instantly seeing the UI in Spanish or Japanese, which is invaluable for catching layout issues caused by text expansion or contraction in different languages that take more/less space on the screen.

For performance, we implemented aggressive caching that stores AST analysis results between runs and only reprocesses components that have changed. Incremental builds stay fast even on large codebases, since at any point in time as a dev, you update only a limited number of components, and we heavily parallelized LLM calls.

This approach was technically possible before LLMs, but practically useless, since for precise translations you'd still need human translators familiar with the product domain. However, now, with context-aware models, we can generate decent translations automatically.

We're excited about finally making it production ready and sharing this with the HN community.

Run `npm i lingo.dev` , check out the docs at lingo.dev/compiler, try breaking it and let us know what you think about this approach to React i18n!

Show HN: Localize React apps without rewriting code
github.com

Re: Show HN: Localize React apps without rewriting code

#4
> We wanted to find a way to deterministically group elements that should be translated together, so, for example, a phrase wrapped in the `` link tag wouldn't get mistranslated because it was processed in isolation. We also wanted to detect inline function calls and handle them gracefully during compile-time code generation.

Very cool

Re: Show HN: Localize React apps without rewriting code

#5

> We wanted to find a way to deterministically group elements that should be translated together, so, for example, a phrase wrapped in the ` ` link tag wouldn't get mistranslated because it was processed in isolation. We also wanted to detect inline function calls and handle them gracefully during compile-time code generation. Very cool

Thanks! To make it work predictably, we actually tested quite a few different algorithms before landing on one that produces outputs LLMs can reliably understand.

Conceptually, we're relying on common sense assumptions about how developers structure JSX. We assume you write reasonably semantic markup where the visual hierarchy matches the code structure - no CSS tricks that make the UI render completely different from what the JSX suggests.

This let us create translation boundaries that make intuitive sense to both developers and AI models.

Re: Show HN: Localize React apps without rewriting code

#6
post #2

“Translate” has a lot of meanings in CS, I thought this was going to be able porting to a different framework or something. “Localize” would be clearer

Yep, localization is the best term here, but sometimes folks confuse it with other things, for example geo localization or localization of errors.

So we usually try to use both terms at the same time, often interchangeably, though translation is ultimately a subset of localization.

Re: Show HN: Localize React apps without rewriting code

#8
Please, please, please, do not use auto translators to localize your pages. There's nothing worse than an half-assed translation that was obviously made by a machine.

Auto-translated sentences are awkward and I feel extremely insulted every time someone chooses to impose this garbage watered-down version of their products on me.

Hire a translator or don't localize your site.

Re: Show HN: Localize React apps without rewriting code

#9
post #3
post #2

“Translate” has a lot of meanings in CS, I thought this was going to be able porting to a different framework or something. “Localize” would be clearer

Ah yes good point - I think that was my fault. Localized now :)

I would rethink this decision. Localization requires understanding intent and adjusting terminology to apply non-literal interpretations to convey meaning; this project uses an auto-translator.

Re: Show HN: Localize React apps without rewriting code

#10
Hi, early user here :) Liking the product so far. We just started using the CLI parts for our RN app, with your cloud translations.

Few things to put on your roadmap if they aren't on it yet:

- Would like it if we could set the model per language. I'm sure you do your best trying to find the best one for each language, but in our experience some of them aren't optimal yet.

- Multiple source languages would be cool. Example: It can make sense to have JA as source for KO but EN as source for FR. Or probably better, sending both (e.g. EN + JA when doing KO).

- MCP doesn't seem to be working (we posted a log on the discord)

- We seem to have spotted cases where key names were taken into account a little too much when translating, but understand this is super hard to tune and can be fixed by improving our keys.

Post reply on HN