Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Footer
  • MenuNew
  • Navbar
  • On This PageNew
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Button
  • Checkbox
  • Color Picker
    • Date
    • Date Range
    • Datetime
    • Datetime Range
    • Time
    • Time Range
  • File Upload
  • NumericNew
  • Radio Button
  • RatingNew
  • Select
  • Slider
  • Switch
  • Textfield
  • Alert
  • Avatar
  • Chip
  • Icon
  • Progress
  • Skeleton
  • Spinner
  • TooltipNew
  • Data Table
  • Pagination
  • Pick List
  • BarcodeNew
  • QR CodeNew
  • CalendarNew
  • Table
  • Overview
  • Area
  • Bar
  • Box Plot
  • Bullet
  • Bump
  • Candlestick
  • Column
  • Dot Plot
  • Dumbbell
  • Funnel
  • Gantt
  • Gauge
  • Heatmap
  • Histogram
  • Icon
  • Line
  • Lollipop
  • Matrix
  • Nightingale
  • Parallel Coordinates
  • Pie
  • Quadrant
  • Radar
  • Radial Bar
  • Range
  • Scatter
  • Slope
  • Small Multiples
  • Strip Plot
  • Treemap
  • Waffle
  • Waterfall
  • Arc Diagram
  • Barcode
  • Beeswarm
  • Bump Area
  • Categorical Scatter
  • Chord Diagram
  • Circular Treemap
  • Contour
  • Convex Treemap
  • Density Plot
  • Dendrogram
  • Euler Diagram
  • Flowchart
  • Hexagonal Binning
  • Horizon
  • Marimekko
  • Network Diagram
  • Radial Histogram
  • Ridgeline
  • Sankey
  • Stream Graph
  • Sunburst
  • Venn Diagram
  • Violin Plot
  • Word Cloud
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

Configuration

Localization

Translate twblazor components and set date and time formats: built in languages, your own .resx files, and options.Localization in AddTwBlazor.

Last updated 18 October 2026

Overview

Every piece of text a twblazor component renders by itself, such as button labels, placeholders, validation messages and the names screen readers announce, comes from a resource file. English is built in and 23 more languages ship with the package, so a component follows the language of your application with nothing to set up.

Dates and times are localized the same way. Month and day names, the first day of the week, 12 or 24 hour time and the order of day, month and year all follow the culture, and each one can be set in AddTwBlazor.

Text you pass to a component yourself, such as a Label or a column title, is rendered as it is. Translating it stays in your application, with whatever you already use for that.

Supported languages

The language is chosen from CultureInfo.CurrentUICulture. A regional culture uses its language file, so es-MX and es-AR both use Spanish, ar-EG uses Arabic, and zh-HK uses Traditional Chinese. Wu Chinese is written in Simplified Chinese, so it is covered by zh-Hans. A language that is not in this table falls back to English.
Language Culture Resource file Translation
English en TwBlazorStrings.resx Written by the maintainers
Chinese (Simplified, Mandarin) zh-Hans TwBlazorStrings.zh-Hans.resx AI translated
Spanish es TwBlazorStrings.es.resx AI translated
Hindi hi TwBlazorStrings.hi.resx AI translated
Portuguese pt TwBlazorStrings.pt.resx AI translated
Bengali bn TwBlazorStrings.bn.resx AI translated
Russian ru TwBlazorStrings.ru.resx AI translated
Japanese ja TwBlazorStrings.ja.resx AI translated
Western Punjabi (Shahmukhi) pa-Arab TwBlazorStrings.pa-Arab.resx AI translated
Turkish tr TwBlazorStrings.tr.resx AI translated
Vietnamese vi TwBlazorStrings.vi.resx AI translated
Chinese (Traditional, Cantonese) zh-Hant TwBlazorStrings.zh-Hant.resx AI translated
Arabic, including Egyptian Arabic ar TwBlazorStrings.ar.resx AI translated
Marathi mr TwBlazorStrings.mr.resx AI translated
Telugu te TwBlazorStrings.te.resx AI translated
Korean ko TwBlazorStrings.ko.resx AI translated
Tamil ta TwBlazorStrings.ta.resx AI translated
Urdu ur TwBlazorStrings.ur.resx AI translated
Indonesian id TwBlazorStrings.id.resx AI translated
German de TwBlazorStrings.de.resx AI translated
French fr TwBlazorStrings.fr.resx AI translated
Javanese jv TwBlazorStrings.jv.resx AI translated
Persian fa TwBlazorStrings.fa.resx AI translated
Italian it TwBlazorStrings.it.resx AI translated
Polish pl TwBlazorStrings.pl.resx AI translated
Translations other than English were produced by AI and have not been reviewed by native speakers, so some wording may be inaccurate or unnatural. If you spot something that could read better, please contribute a correction.

Choose the language

twblazor does not pick a language itself. It reads the culture your application is running under, which is what Blazor's own localization sets, so if your application already switches culture the components switch with it.

In Blazor WebAssembly set the culture before the application runs. In a server application use request localization, so each user gets the culture of their request.

CSHARP
// Blazor WebAssembly: Program.cs
var culture = new CultureInfo("es");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

// Blazor Server: Program.cs
app.UseRequestLocalization(new RequestLocalizationOptions()
    .SetDefaultCulture("en-GB")
    .AddSupportedCultures("en-GB", "es", "ja")
    .AddSupportedUICultures("en-GB", "es", "ja"));

To pin every component to one culture whatever the application is running under, set Culture on the options. It applies to both the text and the formatting.

CSHARP
builder.Services.AddTwBlazor(options =>
{
    options.Localization.Culture = new CultureInfo("ja");
}, Theme.CreateTheme);

Blazor WebAssembly only downloads the language files for the culture the application starts with. Changing the language while it runs needs a page reload, and BlazorWebAssemblyLoadAllGlobalizationData has to be on for cultures outside the default set. This is how Blazor localization works in general and is not specific to twblazor.

Right to left languages

Arabic, Persian, Urdu and Western Punjabi are read right to left, and so is any other culture .NET reports as right to left, such as Hebrew. Components mirror their layout and swap the Left and Right arrow keys for those cultures. The page has to carry the matching dir attribute: wrap your layout in a TwDirectionProvider, or set dir on the html element yourself.
RAZOR
@* MainLayout.razor *@
<TwDirectionProvider>
    @Body
    <TwToastProvider />
    <TwDialogProvider />
</TwDirectionProvider>

To set the direction whatever the culture, use options.Localization.Direction.

CSHARP
builder.Services.AddTwBlazor(options =>
{
    options.Localization.Direction = TextDirection.RightToLeft;
}, Theme.CreateTheme);

Change or add text with your own resource files

To reword a string, or to add a language twblazor does not ship, add .resx files to your own project: one neutral file, and one more for each language. The name of each entry is a key from TwStrings, such as Pagination_NextPage.
TEXT
MyApp/
  Resources/
    TwBlazorStrings.resx        the neutral file, used when no language file matches
    TwBlazorStrings.nl.resx     Dutch
    TwBlazorStrings.sv.resx     Swedish

Then register the file family. Only the keys you want to change need to be there. Anything missing falls back to twblazor's own file for that language, then to English.

CSHARP
using System.Resources;

builder.Services.AddTwBlazor(options =>
{
    options.Localization.AddResource(
        new ResourceManager("MyApp.Resources.TwBlazorStrings", typeof(Program).Assembly));
}, Theme.CreateTheme);

A value with placeholders keeps them, so Page {0} of {1} becomes Pagina {0} van {1}. Text that counts something has a singular and a plural key, such as Sidebar_ResultsOne and Sidebar_ResultsOther.

XML
<!-- Resources/TwBlazorStrings.nl.resx -->
<data name="Common_Close" xml:space="preserve">
  <value>Sluiten</value>
</data>
<data name="Pagination_PageStatus" xml:space="preserve">
  <value>Pagina {0} van {1}</value>
</data>

Several file families can be registered. They are searched last added first. The full list of keys, with the English text of each, is the TwStrings class and TwBlazorStrings.resx.

Change text on one component

A component parameter always wins over the resource files, so a single component can say something different from the rest of the application.

RAZOR
<TwSelect T="string" Values="@countries" Placeholder="Choose a country" />

<TwDatePicker @bind-SelectedDate="date" Format="yyyy-MM-dd" />

<TwTimePicker @bind-SelectedTime="time" Is12HourFormat="true" />

Date and time formats

Calendars, pickers and charts take their formats from options.Localization.Formats. Every value is optional and is a .NET date and time format string. Anything you leave out comes from the culture, so most applications set nothing here.

When the application has no culture of its own (the invariant culture), twblazor uses British formats: a 24 hour clock, day before month, and weeks that start on Monday.

CSHARP
builder.Services.AddTwBlazor(options =>
{
    options.Localization.Formats.FirstDayOfWeek = DayOfWeek.Sunday;
    options.Localization.Formats.Use12HourClock = true;
    options.Localization.Formats.LongDate = "dddd, d MMMM yyyy";
    options.Localization.Formats.DateInput = "dd.MM.yyyy";
}, Theme.CreateTheme);
Option Used for Default
FirstDayOfWeek The first column of calendars and date pickers The culture's first day of the week
Use12HourClock Whether times show AM and PM The culture for displayed times, 24 hour for picker inputs
ShortTime Event times and time slots The culture's short time pattern
Hour Hour labels beside the calendar's time grid h tt or HH:mm, from the clock style
LongDate The full date screen readers announce for a day The culture's long date pattern
MediumDate Date ranges in the calendar header and event summaries d MMM yyyy
MonthYear Month headings The culture's year month pattern
MonthDay The days a multi day event covers d MMM
Month, ShortMonth, Year Month and year buttons in the date pickers MMMM, MMM, yyyy
WeekdayDay Column headings in the calendar's week view ddd d
DateInput The format date pickers type and parse The theme's DefaultFormat
TimeInput The format time pickers type and parse HH:mm, or hh:mm tt on a 12 hour clock
DateTimeInput The format date time pickers type and parse The theme's DefaultDateTimeFormat

The picker input formats are the ones users type, so they stay fixed unless you change them: the date pickers use the theme's dd/MM/yyyy and the time pickers use a 24 hour clock, whatever the culture. To make the pickers type and parse the way a culture writes dates, copy its patterns in one call.

CSHARP
// For en-US this sets M/d/yyyy, h:mm tt and a 12 hour clock.
options.Localization.Formats.UseCultureInputFormats(new CultureInfo("en-US"));

A format can also live in a resource file, so each language carries its own. Add an entry named Format_ShortTime, Format_LongDate and so on to the language's file. A value set on the options wins over the resource file, which wins over the culture. A component parameter such as Format or Is12HourFormat wins over all three.

Use your own localizer

Components read their text through the ITwLocalizer service. If your strings live somewhere other than .resx files, such as a database or an IStringLocalizer, register your own implementation and AddTwBlazor will leave it in place.
CSHARP
public class MyLocalizer(TwBlazorOptions options, IStringLocalizer<SharedResource> strings)
    : TwLocalizer(options)
{
    protected override string? GetString(string key, CultureInfo culture)
    {
        var text = strings[key];
        return text.ResourceNotFound ? base.GetString(key, culture) : text.Value;
    }
}

builder.Services.AddScoped<ITwLocalizer, MyLocalizer>();
builder.Services.AddTwBlazor(_ => { }, Theme.CreateTheme);

The same service is available to your own components, with the same keys and formats.

RAZOR
@inject ITwLocalizer Localizer

<button aria-label="@Localizer[TwStrings.Common_Close]">×</button>
<span>@Localizer.Formats.Format(DateTime.Today, Localizer.Formats.LongDate)</span>

Improve a translation

Each language is one file in src/TwBlazor/Resources. To correct a translation, edit the value of the entry and open a pull request. To add a language, copy TwBlazorStrings.resx to TwBlazorStrings.<culture>.resx and translate the values.

Keep the entry names and the {0} placeholders unchanged. The test suite checks every language file for unknown keys and missing placeholders, so a mistake there is caught before it ships.

On this page

  • Overview
  • Supported languages
  • Choose the language
  • Right to left languages
  • Change or add text with your own resource files
  • Change text on one component
  • Date and time formats
  • Use your own localizer
  • Improve a translation
Discord (opens in a new tab) • GitHub (opens in a new tab) • Documentation (opens in a new tab) • MIT License (opens in a new tab) • llms.txt (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload