Skip to content

Messages

Declare a message once, write its translations inside it, and let the compiler check them.

A program that speaks to people in more than one language declares its messages. A message is a function whose translations are written inside its declaration, one line for each locale, so there is no catalog to keep in step: the compiler reads the translations and the parameters together. A file that declares a message needs no import for it; import locale is for the names of the module (locale.Msg, locale.Locale).

message welcome(name string) {
    en = "Welcome back, {name}!"
    fr = "Bon retour, {name} !"
}

fn main() void {
    greeting := welcome("Ada")
    println(greeting.in("fr"))
    println(greeting.in("en"))
}

welcome("Ada") is a call like any other: the arguments are checked against the parameters. It answers a locale.Msg, a message with its arguments and no language yet. It is not a string, so it cannot be joined to one: a sentence around it is a message with a placeholder. .in(tag) puts it in a language, and a locale with no line for the tag is answered by the line for its language (pt_BR asks pt), and then by the first line, which is the source locale’s.

message is a word, not a keyword: it begins a declaration only where a name and ( follow it, and is an ordinary identifier everywhere else.

Placeholders

{name} writes a parameter, in the language: a string as it is, a number with its grouping and decimal mark, a date in the order the language writes one. {n:plain} writes a number without grouping, and {{ and }} are braces. A placeholder that is not a parameter is an error where it is written, with the nearest parameter when one is near:

message welcome(name string) {
    en = "Welcome back, {nom}!"
}

A type of a program’s own is written in a language by implementing Localize, and a type with no way to be written is an error at the message.

Plurals

plural chooses a line by the CLDR plural category of an integer parameter. Each language needs the categories its rule uses: English one and other, French one, many and other, Polish one, few, many and other, Arabic all six, Japanese other alone.

message inbox(count int) {
    en = plural count { one => "You have {count} message", other => "You have {count} messages" }
    pl = plural count {
        one   => "Masz {count} wiadomość"
        few   => "Masz {count} wiadomości"
        many  => "Masz {count} wiadomości"
        other => "Masz {count} wiadomości"
    }
}

fn main() void {
    println(inbox(1).in("en"))
    println(inbox(3).in("pl"))
}

A category the language never uses is a warning, and one it needs and the plural lacks is an error, at the plural.

Selects

select chooses a line by the value of a parameter: a variant of an enum, a string, or a bool. other is the arm for the rest. An arm is a text, a plural, or another select, so a gender and a count are one line.

enum Role {
    Admin
    Member
    Guest
}

message greeting(name string, role Role) {
    en = select role {
        Admin  => "Welcome, administrator {name}."
        Member => "Welcome, {name}."
        other  => "Hello, {name}."
    }
    fr = select role {
        Admin  => "Bienvenue, administrateur {name}."
        Member => "Bienvenue, {name}."
        Guest  => "Bonjour, {name}."
    }
}

fn main() void {
    println(greeting("Ada", Role.Admin).in("fr"))
    println(greeting("Bob", Role.Guest).in("en"))
}

The arms are held to the enum like a match: a variant no arm names, with no other, is an error that names it, at the select.

enum Role {
    Admin
    Member
}

message greeting(role Role) {
    en = select role { Admin => "administrator" }
}

A string needs an other, and a bool names true and false or has an other.

Drafts

fr = draft "…" marks a translation a machine filled in or no one has reviewed. It is written in the program like any other line, and check and lint say it at the word, at the level [i18n] draft sets: a warning by default, "error" to keep a release from shipping one, "note" or "off".

message welcome(name string) {
    en = "Welcome back, {name}!"
    fr = draft "Bon retour, {name} !"
}

fn main() void {
    println(welcome("Ada").in("fr"))
}

The language in scope

A message is written in the language in scope where no one says which. println writes a Msg in it, as does a Stdout handle’s write_line, an HTTP response body, a WebSocket send and the text fs.File.write and fs.File.append put in a file, and msg.text() answers it as a string. The language is a context, a locale.Locale: every function between the one that writes and main is handed it with nothing written, and a block binds another for the rest of itself, which the functions it calls and the tasks it spawns are handed:

import locale

message welcome(name string) {
    en = "Welcome back, {name}!"
    fr = "Bon retour, {name} !"
}

fn handle(who string) void {
    println(welcome(who))
}

fn main() void {
    handle("Ada")
    {
        @context loc := locale.Locale.of("fr-CA")
        handle("Ada")
        done := spawn {
            @context loc := locale.Locale.of("en")
            handle("a child")
        }
        done.await()
        handle("Ada, still")
    }
    handle("Ada, again")
}

main and a test write in the environment’s language: LC_ALL, then LC_MESSAGES, then LANG (fr_CA.UTF-8 is fr_CA; C and POSIX name none). A program with none of them writes each message’s first line. A served operation writes in the language its request’s Accept-Language header prefers, so an operation that answers with a message answers in the request’s language. A handler written over a connection binds it, @context loc := conn.locale(), and locale.from_accept_language(header) is the same rule for a handler that reads the header itself. A Locale is plain data: a program may keep one anywhere, and bind it where it writes.

Only a function that writes text out takes a Msg for text; anywhere else it is not a string, and writing it into one with ${…}, joining it with +, or handing it to a string parameter is an error that says to put it in a language first.

Numbers and dates

Each argument is written as the language of the line writes it: a number with its grouping and decimal mark (1,234.5 in English, 1.234,5 in German, 1 234,5 in French), a date in the order the language writes one. A placeholder may name a style: {on:long} writes a Date or a DateTime with the names of the language’s months (October 26, 2025, 26. Oktober 2025, 2025年10月26日), {on:full} adds the weekday and {on:medium} abbreviates the month. The names and patterns are CLDR’s, for 39 languages; one the table lacks writes English names in its own order. A style is a variant of the value’s styles, an enum (DateStyle.Long for {on:long}), read when the program is compiled: a name no variant has is refused there, with the styles there are.

A type of a program’s own is written by its Localize, which is handed the Locale to write in (locale.speaks(...) asks its language, is the whole tag), and names its styles by LocalizeAs over an enum of its own:

import locale

struct Money {
    cents int
}

enum MoneyStyle {
    Cents
    Words
}

impl Localize for Money {
    fn localize_to(&self, out &mut string, at locale.Locale) void {
        sep := if at.speaks(locale.Locale.of("de")) { "," } else { "." }
        out.append_int(self.cents / 100)
        out.append(sep)
        out.append_int(self.cents % 100)
    }
}

impl LocalizeAs[MoneyStyle] for Money {
    fn localize_as_to(&self, out &mut string, at locale.Locale, style MoneyStyle) void {
        match style {
            MoneyStyle.Cents => self.localize_to(out, at)
            MoneyStyle.Words => {
                out.append_int(self.cents / 100)
                out.append(if at.speaks(locale.Locale.of("de")) { " Euro" } else { " euros" })
            }
        }
    }
}

message due(total Money) {
    en = "{total} ({total:words}) is due"
    de = "{total} ({total:words}) ist fällig"
}

fn main() void {
    println(due(Money { cents: 1999 }).in("de"))
}

A tag written as a literal (in("de"), Locale.of("de")) is read when the program is compiled, so the line it names is the only one left where the message is written; a tag held in a variable is read once, by Locale.of, into the two numbers a Locale is.

Writing into one string

A message is built in one string. msg.in(tag) answers a string; msg.write(&mut out, tag) appends to one you hold, and msg.write_text(&mut out) does the same in the task’s language, so a loop that writes a message a thousand times into a buffer it clears each turn carves a block for the message’s arguments and nothing for the text:

import locale
import time.{Date}

message line(count int, total float, on Date) {
    en = "{count} items, {total}, due {on:long}"
    de = "{count} Artikel, {total}, fällig am {on:long}"
}

fn main() void {
    day := Date.from_epoch_days(20000)
    mut out := ""
    out.reserve(256)
    for i in 0..3 {
        out.clear()
        line(1000 + i, 1234.5, day).write(&mut out, "de")
        println(out)
    }
}

What each form carves, counted by the runtime’s census over a loop: msg.write(&mut out, tag) and msg.write_text(&mut out) carve nothing on a string with the room (a message’s arguments are kept in the caller’s frame, and a language written as a literal is read when the program is compiled, so the call is the line of that language, spliced where it is written); msg.in(tag), msg.text() and println(msg) carve the one string they answer. A tag in a variable is read off its bytes at run time without making a string of it, including one with a dash or an empty part (pt-br, pt__BR). locale.canonical(tag) answers a tag already as a message names it as it is and writes any other into one block of its own; locale.write_canonical(&mut out, tag) appends it to a string you hold. locale.from_accept_language(header) reads the header in windows over itself and carves only its answer, and nothing when that is already canonical. A float or a bool in a "${…}" template, like an integer, is written into the string being built.

Every value a message holds has the same two forms, and each takes the Locale a tag is read as once (locale.Locale.of("de"), read when the program is compiled for a literal). std/locale writes a number onto a string with locale.write_int(&mut out, at, n) and locale.write_float(&mut out, at, x), where locale.int_text(at, n) and locale.float_text(at, x) answer one. A type that is written in a language implements Localize.localize_to, which appends to the string it is handed; localize, which answers a string, is provided on top of it, and so LocalizeAs[S].localize_as_to and localize_as for a style of S (day.localize_as(at, locale.DateStyle.Long)). A value written through localize_to carves nothing of its own on a string that has the room, which a type of a program’s own keeps by appending (out.append_int(…), out.append(…)) in its own localize_to, as the example above does.

Translators’ files

Translators work in files, and the program reads none: atoll i18n export writes every message’s source text, and a locale’s translations beside it, as PO or XLIFF 2.0, and atoll i18n import writes the translated lines back into the message declarations, in place.

atoll i18n export --locale fr -o fr.po
atoll i18n import fr.po

Each string is an entry keyed by file, message and place, with the plural forms the locale’s CLDR rule needs. An import changes a message only if its lines pass the checks atoll check makes, and leaves out an entry made for source text that has since changed; the rest of the file, comments and formatting included, is as it was. --draft marks the lines it writes.

meta.stale_translations finds the lines the source has outrun: a locale whose line is as it was at the base while the source locale’s text is not. It is the body of a project contract (@contract, --base):

// stale.at, in a package with a git base and `[comptime] allow = ["std/project", "std/git"]`
import meta

@contract
pub fn stale_translations(p meta.Project, mut out ^meta.Report) void ! meta.Error {
    meta.stale_translations(p, out)?
}

The locales of a package

atoll.toml lists the package’s locales, the source locale first:

[i18n]
locales = ["en", "fr", "pl"]
missing = "warning"        # or "error", or "off"
draft = "warning"          # a line marked `draft`: or "error", "note", "off"

With the section, a line for a locale that is not listed is an error, and a message with no line for a listed locale is what missing says. Without it a message is checked against itself alone.

atoll fmt writes a message as a table: the = of the locales line up, and a plural stays on its line when it fits and is a column when it does not.

Type to search…

↑↓ navigate↵ selectEsc close