Live data from Hacker News

Web Translator API

developer.mozilla.org

31–40 of 71 posts

Re: Web Translator API

#32

Why does it need to be a JavaScript API? Why not just use the lang= attribute as it was intended, then let the user select text to translate as they wish?

If it's a HTML attribute, then you can only use it with DOM elements, with no control about when it runs.

Instead, a JS API gives more flexibility and control.

Besides, I think the "lang" attribute is supposed to signal what the language of the text inside that element is, not what it could/should be. So even if going with attributes would be the way forward, a new one would need to be created.

Re: Web Translator API

#33

Earlier quoted context omitted.

What's the easiest way to get this functionality outside of the browser, e.g. as a CLI tool? Last time I looked I wasn't able to find any easy to run models that supported more than a handful of languages.

That depends on what counts as “a handful of languages” for you. You can use llm for this fairly easily: uv tool install llm # Set up your model however you like. For instance: llm install llm-ollama ollama pull mistral-small3.2 llm --model mistral-small3.2 --system "Translate to English, no other output" --save english alias english="llm --template english" english "Bonjour" english "Hola" english "Γειά σου" english…

That's just the base/stock/instruct model for general use case. There gotta be a finetune specialized in translation, right? Any recommendations for that?

Plus, mistral-small3.2 has too many parameters. Not all devices can run it fast. That probably isn't the exact translation model being used by Chrome.

Re: Web Translator API

#34

Why does it need to be a JavaScript API? Why not just use the lang= attribute as it was intended, then let the user select text to translate as they wish?

It's only implemented in Google Chrome, so go figure.

If Chrome tried to pull this in like 2016, when Google Translate was the only-ish game in town, I’d call them out for it. But we now have multiple competing open weights translation models that are really good, making this kind of service essentially a commodity. One vendor might give users free access to their services to entice them to use their browser, another might differentiate themself by running the model locally and giving the user better privacy guarantees in exchange for performance.

I get that this is one more brick in the wall that teams like LadyBird will have to maintain, but as a web developer I do think more Web API features is generally a good thing, as it makes it easier for smaller shops to implement richer functionality.

Re: Web Translator API

#35
post #11

https://developer.chrome.com/docs/ai/translator-api const translator = await Translator.create({ sourceLanguage: 'en', targetLanguage: 'fr', }); await translator.translate('Where is the next bus stop, please?');

So, this is Google Translate built running locally in Chrome? I wonder if it is a small/degraded model or limited languages? Otherwise, how is it not a simple way around the paid Google API?

Re: Web Translator API

#36
post #35
post #11

https://developer.chrome.com/docs/ai/translator-api const translator = await Translator.create({ sourceLanguage: 'en', targetLanguage: 'fr', }); await translator.translate('Where is the next bus stop, please?');

So, this is Google Translate built running locally in Chrome? I wonder if it is a small/degraded model or limited languages? Otherwise, how is it not a simple way around the paid Google API?

[dead]

Re: Web Translator API

#37

Earlier quoted context omitted.

That depends on what counts as “a handful of languages” for you. You can use llm for this fairly easily: uv tool install llm # Set up your model however you like. For instance: llm install llm-ollama ollama pull mistral-small3.2 llm --model mistral-small3.2 --system "Translate to English, no other output" --save english alias english="llm --template english" english "Bonjour" english "Hola" english "Γειά σου" english…

That's just the base/stock/instruct model for general use case. There gotta be a finetune specialized in translation, right? Any recommendations for that? Plus, mistral-small3.2 has too many parameters. Not all devices can run it fast. That probably isn't the exact translation model being used by Chrome.

I haven’t tried it myself, but NLLB-200 has various sizes going down to 600M params:

https://github.com/facebookresearch/fairseq/tree/nllb/

If running locally is too difficult, you can use llm to access hosted models too.

Re: Web Translator API

#38
post #35
post #11

https://developer.chrome.com/docs/ai/translator-api const translator = await Translator.create({ sourceLanguage: 'en', targetLanguage: 'fr', }); await translator.translate('Where is the next bus stop, please?');

So, this is Google Translate built running locally in Chrome? I wonder if it is a small/degraded model or limited languages? Otherwise, how is it not a simple way around the paid Google API?

There's already ways to do translation locally in javascript with neural-nets running in WASM, this is just more convenient.

https://huggingface.co/Xenova/nllb-200-distilled-600M

Re: Web Translator API

#39
post #5

Earlier quoted context omitted.

Chrome embeds a small LLM (never stops being a funny thing) in the browser allowing them to do local translations. I assume every browser will do the same as on-device models start becoming more useful.

What's the easiest way to get this functionality outside of the browser, e.g. as a CLI tool? Last time I looked I wasn't able to find any easy to run models that supported more than a handful of languages.

You can use bergamot ( https://github.com/browsermt/bergamot-translator ) with Mozilla's models ( https://github.com/mozilla/firefox-translations-models ).

Not the easiest, but easy enough (requires building).

I used these two projects to build an on-device translator for Android.

Re: Web Translator API

#40
I was excited that Firefox finally exposed its local translations as API, but it's Chrome-only (still?). Will be nice for userscripts, for example to replace Twitter's translation button that hardly ever works
Post reply on HN