Localization
builder.Services.AddLocalization();
builder.Services.AddCrudEngine(o => o
.AddPagesFrom(asm)
.UseLocalization<SharedResource>()); // any IStringLocalizer source, e.g. SharedResource.ar.resx
app.UseRequestLocalization(o => o.SetDefaultCulture("en").AddSupportedCultures("en", "ar-SA").AddSupportedUICultures("en", "ar-SA"));
- Texts are keys with a fallback: titles, labels, placeholders, row-action labels and every engine message (
"{0} is required.","{0} '{1}' is already used.", …) are looked up in your resources; when a key is missing the English text is used. So you translate only what you need. - The schema carries the culture:
culture(e.g.ar-SA),direction(rtl/ltr) andcalendar, taken from the request culture. UIs use them; the pro Blazor UI switches to right-to-left and Hijri dates by itself. - Calendar:
o.DisplayCalendar = DisplayCalendar.FromCulture(default),GregorianorUmAlQura(Hijri). Values in the API stay ISO/Gregorian; only display changes. - Times: audit times are UTC (
...Z); UIs show them in the reader’s time zone.
The engine never builds HTML, so nothing it translates can inject markup.
Built-in translations
The engine ships translations of its own texts: messages, validation messages and the role pages. Arabic is the first language; more can be added as src/Core/Localization/Texts/{language}.json (English text → translation), pull requests welcome. The lookup order is: your resources first, then the built-in translation for the request’s language (ar-SA falls back to ar), then English. So you translate only your own texts, and can still override any engine text by adding the same key to your resources.
Validation messages
Rules such as [Required], [MaxLength], [Range], [RegularExpression] and [SafeText] produce the engine’s own templates, with the field’s translated label: "{0} is required." becomes “Name is required.” / “الاسم مطلوب.”. A message you set on the attribute (ErrorMessage = "...") is translated as a key and formatted the same way ({0} is the label, then the rule’s values).
Arabic-aware search
[Search(Op.Contains, Normalization = TextNormalization.Arabic)] // one property
public string Name { get; set; } = "";
builder.Services.AddCrudEngine(o => o.TextNormalization = TextNormalization.Arabic); // every text search and lookup
The alef forms (أ إ آ ٱ) match ا, ة matches ه, ى matches ي, and diacritics (tashkeel) and tatweel are ignored, so “احمد” finds “أحمد” and “محمد” finds “مُحَمَّد”. It runs in SQL (nested REPLACE on the column) with the same rules for the searched text (ArabicText.Normalize), for Eq, NotEq, Contains and StartsWith, and for lookups. Like case-insensitive search, it prevents index use for that comparison. Tested on SQL Server and SQLite.
Native digits
Numbers, dates and ids in requests (filters, ids, unique checks) accept Arabic-Indic (٠-٩) and Persian (۰-۹) digits, the Arabic decimal sign (٫) and thousands sign (٬); In lists accept the Arabic comma (،). Text values keep their digits as typed. NativeDigits.ToLatin does the same in your own code.
Which text is the key
Every key is the English text exactly as the engine shows it, so the .resx entry’s name must match it character for character:
| Text | Key |
|---|---|
| Page title, item title, group | [CrudPage(Title = ..., ItemTitle = ..., Group = ...)] as written; without Title, the page id |
| Field and column label | the first of [Field(Label = ...)], [Display(Name = ...)], [Grid(Title = ...)], else the property name as written (LengthMeters, not “Length meters”) |
| Search label | [Search(Label = ...)], else the field label above |
| Enum value | [Display(Name = ...)] on the member, else the member name as written (LowerIsBetter) |
| Placeholder, row-action label | as written in the attribute |
| Messages from page events | the text passed to e.AddError(...) or e.Cancel(...) |
| Engine messages | the English message with {0} placeholders, e.g. {0} is required. |
To show friendlier English and a translation, give the text once in the attribute ([Field(Label = "Length (m)")], [Display(Name = "Lower is better")]) and use that as the key.