#localization Region

Planned — design subject to change

This feature is designed but not yet implemented. The syntax and behavior described here represent the target specification.

Purpose

The #localization region defines translations for strings marked with @t() in #code and #view.

Marking strings

tape
#code
fn show_greeting() {
    io.println(@t("Hello, welcome back!"));
}

#view
component LoginForm {
    view {
        widgets.Label { text: @t("Username"); }
        widgets.Label { text: @t("Password"); }
        widgets.Button { label: @t("Sign in"); }
    }
}

Translation entries

tape
#localization
"Hello, welcome back!" {
    fi: "Hei, tervetuloa takaisin!";
    sv: "Hej, välkommen tillbaka!";
    de: "Hallo, willkommen zurück!";
}

"Username" {
    fi: "Käyttäjänimi";
    sv: "Användarnamn";
    de: "Benutzername";
}

"Password" {
    fi: "Salasana";
    sv: "Lösenord";
    de: "Passwort";
}

"Sign in" {
    fi: "Kirjaudu sisään";
    sv: "Logga in";
    de: "Anmelden";
}

Compile-time verification

The compiler verifies that every @t() token has a corresponding translation entry. Missing translations are compile errors.

Runtime locale switching

tape
import locale from "locale";

locale.set("fi");  // switch to Finnish
// all @t() strings now return Finnish translations

Fallback

If a translation is missing for the current locale, the source string (English) is used.

Export for translators

bash
tape build app.tape --export-translations translations.json

Generates a JSON file with all translatable strings for external translation tools.

Last modified: