Localization
PAM Desktop has no interface text fixed in one language. Every default it shows (placeholders, menu role labels, validation messages, dialog titles, the host’s own chrome) comes from a catalog with English as the base and Portuguese (pt) and Spanish (es) included. Your own copy uses the same Pam\Desktop\I18n\I18n catalogs, with namespace.key keys, {name} placeholders and plural forms.
Catalogs
Section titled “Catalogs”Register a catalog per language once at startup, before App::run(). A catalog maps namespaces to flat key => text maps:
use Pam\Desktop\I18n\I18n;
I18n::catalog('en', [ 'inbox' => [ 'title' => 'Inbox', 'unread_zero' => 'No unread messages', 'unread_one' => '{count} unread message', 'unread_other' => '{count} unread messages', 'greeting' => 'Hello, {name}!', ],]);
I18n::catalog('pt', [ 'inbox' => [ 'title' => 'Caixa de entrada', 'unread_zero' => 'Nenhuma mensagem não lida', 'unread_one' => '{count} mensagem não lida', 'unread_other' => '{count} mensagens não lidas', 'greeting' => 'Olá, {name}!', ],]);A catalog may also be a closure that returns the array, so languages you never show are never loaded. Only the active locale and the source locale (the fallback) are loaded.
Translating
Section titled “Translating”use Pam\Desktop\I18n\I18n;
final class InboxScreen extends Component{ #[State] public int $unread = 0;
public function title(): string { return I18n::t('inbox.title'); }
public function unreadLabel(): string { return I18n::t('inbox.unread', ['count' => $this->unread]); }}<Text class="title">{{ title() }}</Text><Text class="subtitle">{{ unreadLabel() }}</Text>{name}placeholders are interpolated; numbers are grouped for the locale.- A numeric
countpicks_zero(only for 0, when present), then_oneor_other.I18n::pluralRule($locale, $rule)sets the rule for a language with other plural categories. - A missing key returns the key itself, so a missing translation is visible instead of empty.
I18n::has($key)checks a key,I18n::translateIn($locale, $key, $params)translates into a specific language, andI18n::formatNumber($value, $locale, $decimals)formats a number.
Choosing the language
Section titled “Choosing the language”| Level | How |
|---|---|
| System | LC_ALL, LC_MESSAGES, then LANG; else the locale the host reported; else English. |
| Application | I18n::use('pt-BR') once at boot. I18n::use(null) follows the system again. |
| One framework text | The same key under the pam namespace of your catalog. |
| One component or call | The argument: placeholder:, label:, Menu::edit('Edição'), new Required('…'), Files::save(…, title: '…'). |
I18n::use('es'); // the application languageI18n::catalog('fr', ['pam' => ['select.placeholder' => 'Choisir']]); // override one framework textThe active locale is chosen once per run. A later I18n::use() reaches what renders next, but components already created keep the defaults they were built with, so offer a language switch that restarts the interface (for example by resetting the navigation stack).
What the framework localizes
Section titled “What the framework localizes”| Where | Texts |
|---|---|
| DesktopUI | Select, autocomplete and multi-select placeholders, labels and empty messages; date picker; toast close button; checkbox labels. |
| Desktop | MenuRole labels, Menu::edit() and Menu::window(), form rule messages, the navigation header search placeholder, the save dialog title. |
| Charts | The “No data” label. |
| Host chrome | The Linux share menu, the alert OK button and the release error screen. |
Developer messages (exceptions, the development error overlay, warnings) stay in English. The framework keys and their three catalogs live in Pam\Desktop\I18n\FrameworkText.
Testing translations
Section titled “Testing translations”Set the language in a test before checking text, so the test passes on any machine locale:
use Pam\Desktop\I18n\I18n;use function Pam\Desktop\Testing\mount;
I18n::use('pt');$inbox = mount(InboxScreen::class);assert(str_contains($inbox->text(), 'Caixa de entrada'));Next steps
Section titled “Next steps”- Forms & Input for localized validation messages.
- Testing to check copy without a window.