Internationalization Overview
How Vanilla Breeze follows the language, script, direction and locale of a page, and what is left to you.
The approach
The web platform already knows most of what internationalization needs: the lang and dir attributes, the :lang() and :dir() selectors, logical properties, the Intl formatters and the ruby elements. Vanilla Breeze uses them throughout, so a page changes language when its markup says so and not through a setting in script.
In the demo, the buttons change two attributes on the article and swap in translated text. The typeface, line height, quotation marks, date, number and currency formats and the mirrored layout all follow from those two attributes.
What is handled and what you provide
| Area |
The library handles |
You provide |
| Languages and scripts |
A typeface stack, line height and line-breaking rules for each script; quotation marks for each language; ruby annotation display |
lang on <html> and on any passage in another language |
| Direction |
Layout written with logical properties; icons, markers and arrow keys that follow the direction |
dir="rtl" where the language is written right to left; <bdi> around text whose direction you do not know |
| Locale and formatting |
Dates, numbers, currency and file sizes formatted for the nearest lang; calendars and date pickers in the reader's locale |
Machine-readable values in <time datetime> and <data value> |
| Translation |
An attribute for every string a component generates; a small class for swapping page strings |
The translations, and translate="no" on text that must stay as written |
Where to start
One attribute does most of the work. Set the language of the page, and mark any passage in a different language.
<html lang="en"> ... <p>The French call it <span lang="fr">l'esprit de l'escalier</span>.</p></html>
Write language tags in BCP 47 form with hyphens: en-GB, pt-BR, zh-Hant. A screen reader uses the tag to choose a voice, the browser uses it for hyphenation and spell checking, and the library uses it for everything on the pages below.