i18n / Localization Reference
The @formosaic/core package uses a locale registry to manage all user-facing strings. All strings default to English and can be partially or fully overridden for other languages.
Usage
typescript
import {
registerLocale,
getLocaleString,
resetLocale,
getCurrentLocale,
} from "@formosaic/core";
// Register a partial locale override (unset keys fall back to English defaults)
registerLocale({
required: "Obligatoire",
save: "Sauvegarder",
cancel: "Annuler",
saving: "Enregistrement...",
thisFieldIsRequired: "Ce champ est obligatoire",
});
// Get a specific string
const label = getLocaleString("required"); // "Obligatoire"
// Reset to English defaults
resetLocale();Multiple registerLocale Calls
registerLocale() merges into the current locale. Calling it multiple times accumulates overrides:
typescript
registerLocale({ save: "Guardar" });
registerLocale({ cancel: "Cancelar" });
// Both "save" and "cancel" are now overridden; everything else is English.All Locale String Keys
Form Status
| Key | Default (English) |
|---|---|
autoSavePending | "AutoSave Pending, please check for errors..." |
savePending | "Save Pending, please check for errors..." |
saving | "Saving..." |
saveError | "Error saving form" |
Actions
| Key | Default (English) |
|---|---|
save | "Save" |
cancel | "Cancel" |
create | "Create" |
update | "Update" |
confirm | "Confirm" |
add | "Add" |
edit | "Edit" |
deleteLabel | "Delete" |
remove | "Remove" |
close | "Close" |
clear | "Clear" |
Validation Error Messages
| Key | Default (English) |
|---|---|
invalidUrl | "Invalid URL" |
invalidEmail | "Invalid email address" |
invalidPhoneNumber | "Invalid phone number" |
invalidYear | "Invalid year" |
noSpecialCharacters | "Special characters are not allowed" |
invalidCurrencyFormat | "Invalid currency format" |
mustBeANumber | "Must be a number" |
thisFieldIsRequired | "This field is required" |
Dynamic String Functions
Some locale entries are functions that accept parameters:
| Key | Signature | Default Output |
|---|---|---|
stepOf | (current, total) => string | "Step {current} of {total}" |
saveChangesTo | (title) => string | "Do you want to save your changes to {title}?" |
contentExceedsMaxSize | (maxKb) => string | "Content exceeds maximum size of {maxKb}KB" |
mustBeAtLeastChars | (min) => string | "Must be at least {min} characters" |
mustBeAtMostChars | (max) => string | "Must be at most {max} characters" |
mustBeBetween | (min, max) => string | "Must be between {min} and {max}" |
Overriding Dynamic Functions
typescript
registerLocale({
stepOf: (current: number, total: number) => `Etape ${current} sur ${total}`,
saveChangesTo: (title: string) => `Voulez-vous enregistrer vos modifications de ${title} ?`,
});Testing with Locale
Use resetLocale() in test setup/teardown to ensure clean state:
typescript
import { registerLocale, resetLocale, getLocaleString } from "@formosaic/core";
beforeEach(() => {
resetLocale();
});
test("should use registered locale strings", () => {
registerLocale({ required: "Pflichtfeld" });
expect(getLocaleString("required")).toBe("Pflichtfeld");
});