Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Translation

How to translate the strings components generate and the text of a page, and how to keep code and names out of machine translation.

Component strings

Your content is yours to translate. A component also generates text of its own: the name of a calendar's Next month button, a rating's 4 stars, a validation message. Each of those strings has an English default and a data-label-* attribute that replaces it.

Three things to know:

  • Where the attribute goes. A component reads data-label-* from its own element. Attribute utilities such as data-hotkey read it from the nearest ancestor that has it, so one attribute on <html> covers the page.
  • Placeholders. A string can contain tokens in braces, such as {n} or {date}, which the component fills in. Keep them in the translation and move them where the grammar needs them.
  • Plurals. Where a count is involved, the attribute name ends in a plural category from Intl.PluralRules: data-label-one, data-label-few, data-label-other. Supply the categories the language has.

The attributes for each component are listed in the table on its page. Dates, month names and weekday names need no attribute. They come from Intl, in the language set by the nearest lang.

Page strings

The most reliable translated page is one the server sends already translated, with its own URL and its own lang. Do that where you can.

For an application that switches language without a reload, VbI18n swaps strings in place. Mark each element with a key and give the class your messages. Nothing runs until you create it.

The English text in the markup is the fallback. It shows before the script runs and for any key with no translation. When you change language this way, update lang and dir on <html> as well, so typography, formatting and direction follow.

Text that must not be translated

Browsers and translation services translate whatever they find. Code, commands, product names and user names should stay as written. The translate attribute says so. It is an HTML attribute and no stylesheet can set it, so it has to be in your markup.

Add it to <code>, <kbd>, <samp>, <pre> and <var> content, and to names and identifiers in running text.

Writing for translation

  • Do not build sentences from pieces. Word order differs between languages. Translate the whole sentence with a placeholder in it.
  • Leave room. German and Finnish run a third longer than English. The layout elements wrap and grow, so avoid fixed widths on anything that holds text.
  • Keep text out of images. It cannot be translated, resized or read aloud.
  • Use the elements. <q>, <time> and <data> localize themselves. Typed quotation marks and hand-formatted dates do not.
↑