Languages
One web_page serves every language. Its l10n list gives each language a URL or a domain of its own, a request on one of them renders in that language, and the hreflang links and og:locale tags are written for you. Translations and numbers in the template follow along.
The l10n list gives each language its URL
The list is a setting on the page, next to event. Each URL is a route like event, so it can capture the same :name segments. On the canvas, press no localization under the URL on the web_page block: Add localization has a URL field per language, and you fill in the ones you want. In the Studio Code View, the only way in Studio 3.3.0 and older, it reads like this:
blueprint "Shop"
flow page = web_page with {
event: "shop/:category",
scopes: ["*public"],
l10n: [
{language: "en", url: "en/shop/:category"},
{language: "nl", url: "nl/winkel/:category"},
{language: "de", url: "de/laden/:category"}
]
} {
let {category} = page.params
web_render(page.connection,
title: category,
template = "<h1>{{t \"shop.title\"}}</h1>"
)
}The params pin holds category on all four URLs, and web_action blocks work on all of them. An action posts to the URL it was clicked on, so it runs in the same language. The page's language out-pin tells the flow which one it got.
A localized URL always renders in its own language
A request on an l10n URL forces that entry's language for the whole render and every function it calls. The URL says what the visitor asked for, so it wins over everything else.
On any other URL, the language is worked out in this order, each later step overriding the one before when it has an answer:
language_default, orenif none is set.- The browser's
Accept-Language, iflanguage_browser_enabledis on. Its first language counts, without the region. - The signed-in user's own language, if
language_user_enabledis on. - A
?language=nlin the URL or alanguagecookie, iflanguage_query_enabledis on.
These are system settings. Because an anonymous visitor's language can come from a header or a cookie, a publicly cached page varies on both.
Every entry becomes an hreflang link
With the page above, a request on /nl/winkel/tea gets these tags in its head:
<link rel="canonical" href="https://shop.example.com/nl/winkel/tea">
<link rel="alternate" hreflang="en" href="https://shop.example.com/en/shop/tea">
<link rel="alternate" hreflang="nl" href="https://shop.example.com/nl/winkel/tea">
<link rel="alternate" hreflang="de" href="https://shop.example.com/de/laden/tea">
<link rel="alternate" hreflang="x-default" href="https://shop.example.com/shop/tea">
<meta property="og:locale" content="nl_NL">
<meta property="og:locale:alternate" content="en_US">
<meta property="og:locale:alternate" content="de_DE">- The
eventURL isx-default, the page for a visitor no language matches. It gets no language of its own, so give the default language an entry of its own if you want it listed by name. That entry may have the same URL asevent, but then that URL always renders in that language. - The current request's
:namevalues are filled in, so each link points at the same product or category. An entry whose required value is missing is left out, and an optional:name?is dropped from the URL. - A page with no
l10ngets nohreflanglinks. - If your own head already has
hreflanglinks, none are written.
A route can name its own host
For a language on a domain of its own, start the route with the hostname. The link is written on that host, and the page answers there. The domain must be pointed at your cluster: see Manage Domains in RUAL Studio.
blueprint "Shop"
flow page = web_page with {
event: "shop.example.com/en/:slug",
scopes: ["*public"],
l10n: [
{language: "en", url: "shop.example.com/en/:slug"},
{language: "nl", url: "shop.example.com/nl/:slug"},
{language: "de", url: "shop.example.de/:slug"}
]
} {
web_render(page.connection, template = "<h1>{{t \"shop.title\"}}</h1>")
}A hostname on its own is that site's home page: shop.example.de and shop.example.de/ both mean https://shop.example.de/.
On a domain other than your main one, only routes that name that host answer. A bare route such as about belongs to the main domain. When a host-named route and a bare route both fit on the main domain, the host-named one wins.
How a host is told from a path
A route looks the same to the router either way, so the first part of it is read like this, in order:
- A wildcard host (
*.example.fr/x) has no single URL, so it is left out of the links. The page still answers there. - The host of the current request is always a host.
- One of your entity's own domains is always a host, however it is spelled.
- Anything else goes by its spelling: it has a dot and ends in two or more letters. With a slash after it, that makes it a host. Standing alone, it is a host unless it names a file a site serves at its root.
In l10n | On a request to shop.example.com, the link is | Because |
|---|---|---|
nl/winkel | https://shop.example.com/nl/winkel | A path. |
shop.example.com/nl | https://shop.example.com/nl | The request's own host. |
shop.example.de | https://shop.example.de/ | Spelled like a host, standing alone: that site's home page. |
shop.example.de/nl | https://shop.example.de/nl | Spelled like a host, with a slash after it. |
shop.example.md/ | https://shop.example.md/ | The slash makes it a host, though .md is a file ending too. |
winkel.example.md | https://winkel.example.md/ | One of your entity's own domains, so never a file. |
sitemap.xml, robots.txt, en.md | https://shop.example.com/sitemap.xml | A root file standing alone is a path. |
v1.2/notes | https://shop.example.com/v1.2/notes | A dot does not make a host: 2 is not two letters. |
*.example.fr | Left out | A wildcard host has no single URL. |
The file endings counted as root files are xml, txt, json, html, htm, md, js, mjs, css, ico, png, jpg, jpeg, gif, svg, webp, avif, webmanifest, rss, atom, pdf, csv, map, woff, woff2 and wasm. For a domain on such an ending that is not your entity's own, write the slash.
og:locale is written as language and territory
Facebook reads nl_NL, not a bare nl, so the page's language is spelled out:
| Page language | og:locale | Rule |
|---|---|---|
en-GB, pt_PT | en_GB, pt_PT | A language with a region keeps it. |
nl, en, pt | nl_NL, en_US, pt_BR | A bare language takes the territory it most likely means. |
| A language with no known territory | No tag | Better no tag than one that is not read. |
The page's other languages each get one og:locale:alternate, never its own language and never x-default. Set og:locale in the meta pin to override it.
Translations follow the page's language
Keep the text in Manage Translations in RUAL Studio and print it with {{t}}:
<h1>{{t "shop.title"}}</h1>
<p>{{t "cart.items" count=cart.count}}</p>
<input placeholder="{{t "shop.search"}}">- Fallback: the page's language, then the entity's default language, then the key itself.
- Keys are lower case and trimmed:
{{t "Cart.Title"}}iscart.title. - Values:
{count}in the text is filled fromcount=..., and the value is escaped. - The text itself is yours, so in page text it may hold markup:
Read our <a href="/terms">terms</a>. Inside an attribute everything is escaped. - A key read from data (
{{t key}}or{{key | t}}) is escaped if nobody translated it, as it did not come from you.
A translation's text can hold template tags
A text with {{ }} in it is rendered as a template of its own, from RUAL core 15.0.2. It reads everything the tag that asked for it can read, with that tag's values in front, so one text can print a value, format it and include another translation:
| Key | Text in Manage Translations |
|---|---|
shop.name | De <b>Theewinkel</b> |
shop.welcome | Welkom bij {{t "shop.name"}}, {{user.name}} |
cart.items | {{if count == 1}}één artikel{{else}}{{count}} artikelen{{/if}} |
cart.summary | {{t "cart.items" count=count}} voor {{total | money "EUR"}} |
<h1>{{t "shop.welcome"}}</h1>
<p>{{t "cart.summary" count=cart.count total=cart.total}}</p><h1>Welkom bij De <b>Theewinkel</b>, Ada</h1>
<p>3 artikelen voor € 12,50</p>- Everything from Template Syntax works in a text: values,
{{if}},{{for}}, filters, partials and{{t}}. - A value given to the tag can be written both ways in the text:
{count}and{{count}}. Only the second can be filtered or tested. - Values are escaped for where the text puts them, exactly as in a template:
<a href="{{url}}">in a text refuses ajavascript:URL. - Inside an attribute or a script the text is rendered first and then escaped as a whole, so markup in it shows as text there.
- Only a text is rendered, never a key. A key built from a visitor's input cannot run tags.
{{key | t}}does not render tags: a filter's result is a value. Use{{t key}}for a text that holds them.- A text that includes itself fails the render with an error naming the key.
- A text that does not compile (an
{{if}}nobody closed) is written as it stands, tags and all.
A key can name its language
Put a language in front of the key and it is read in that language, whatever the page's language is: {{t "nl:language.name"}} is always the Dutch text. A key missing in that language falls back to the default language, then to the key.
- The prefix is a language code: two or three letters, optionally with a region (
pt-br:). Anything else, such aserror:not_found, stays a key. - A key that really has a colon in it and has a translation under that whole name wins.
- The older form reads it too:
{{translate}}nl:language.name{{/translate}}, as on state pages.
web.languages lists the page's languages for a switcher
Every template can read web.languages: one entry per l10n entry of the page, in the order you wrote them, without x-default. An entry on a wildcard host has no single URL and is left out, as it is from the hreflang links. A page with no l10n has an empty list. It is there from RUAL core 15.0.2.
| Field | Holds |
|---|---|
language | The entry's language, in lower case. |
url | The absolute URL of this page in that language, with the same :name values. The same URL as its hreflang link. |
current | true for the language this render is in. |
{{if web.languages}}
<nav aria-label="{{t "language.choose"}}">
{{for l in web.languages}}
<a href="{{l.url}}" hreflang="{{l.language}}" lang="{{l.language}}"{{if l.current}} aria-current="true"{{/if}}>
{{translate}}{{l.language}}:language.name{{/translate}}
</a>
{{/for}}
</nav>
{{/if}}Give the key language.name the text Nederlands in Dutch, English in English and Deutsch in German, and each link reads in its own language on every version of the page.
Numbers and money follow it too
The same template writes each language's own way:
| Language | {{1234.5 | money "EUR"}} | {{1234.5 | number 2}} |
|---|---|---|
en | €1,234.50 | 1,234.50 |
nl | € 1.234,50 | 1.234,50 |
de | 1.234,50 € | 1.234,50 |
fr | 1 234,50 € | 1 234,50 |
A language the platform has no number style for reads as English. date writes digits in the pattern you give it and in the entity's time zone, so the pattern is yours to vary: {{if language == 'en'}}{{d | date "M/D/YYYY"}}{{else}}{{d | date "D-M-YYYY"}}{{/if}}.
The current language is {{language}} in a page or layout and {{web.language}} everywhere, which is also what to give <html lang>.
Next steps
SEO and Sharing The rest of the head tags, and how to override them. Template Syntax The forms of the translation tag and every filter. System Settings Reference The language settings that decide the language on other URLs.Frequently asked
How do I publish a RUAL web page in more than one language?
List its language versions in the page's l10n field as language and url pairs. A request on such a URL renders in that language, and web_render lists every version as an hreflang link with the main URL as x-default, and writes og:locale and og:locale:alternate.
Can a language version of a RUAL web page live on its own domain?
Yes. Name the host in the l10n URL, as in shop.example.com/nl, or give the hostname alone for that site's home page. A wildcard host has no single URL, so it is left out of the hreflang links.