You had me at "Browser compatibility".
Web Translator API
31–40 of 71 posts
Re: Web Translator API
#32Why 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?
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
#33Earlier 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…
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
#34Why 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.
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
#35https://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?');
Re: Web Translator API
#36https://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
#37Earlier 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.
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
#38https://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
#39Earlier 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.
Not the easiest, but easy enough (requires building).
I used these two projects to build an on-device translator for Android.