Override Default Text

Learn how to override default text

Overriding Default Text of the Framework

The BlazorForKids framework provides default labels and messages used across the application. However, in many cases, especially when building applications in a different language or when you want to customize the UI text to better match your application's tone, it’s important to override these default texts.

This guide will show you how to override:

  • System messages (like success, error, and warning notifications)
  • UI text labels (like "Edit", "Delete", "Yes", "No", etc.)

1. Overriding System Messages (BkCommandResult.Defaults)

The BkCommandResult class is used throughout the framework to return a result after an operation is performed (like saving, deleting, etc.). Each result includes a message that is shown to the user. By default, the messages are in English.

You can override these messages by setting new values for the following properties:

  • BkCommandResult.Defaults.ErrorMessage – shown when an operation fails
  • BkCommandResult.Defaults.SuccessMessage – shown when an operation succeeds
  • BkCommandResult.Defaults.WarningMessage – shown when an operation partially succeeds or needs attention

Here’s how to override these default messages in your Program.cs file:

publicclassProgram

{

    publicstaticvoidMain(string[]args)

    {

        varbuilder=WebApplication.CreateBuilder(args);

        BkCommandResult.Defaults.ErrorMessage="O no! An error occurred during the operation. Please try again.";

        BkCommandResult.Defaults.SuccessMessage="Hooray! The operation was completed successfully.";

        BkCommandResult.Defaults.WarningMessage="Oops! The operation was not successful.";

//... Other configurations and services    }

}

Make sure to do this immediately after CreateBuilder, before any components or services use these messages.


2. Overriding UI Text Labels (BkDefaultText)

The UI elements in the framework use a static class called BkDefaultText for displaying common labels like "Yes", "No", "Edit", "Delete", and so on.

To customize these texts (for example, to support a different language), you can create your own static class in your project where you assign new values to the properties of BkDefaultText.

This pattern is especially helpful if you're localizing the app (e.g. translating it into Romanian, Spanish, French, etc.).

Step-by-step guide

  1. Create a static class (e.g., RomanianDefaultText) in your project.
  2. Inside this class, create a method (e.g., SetDefaultText()) where you assign your preferred values.
  3. Call this method in Program.cs right after setting the system messages.

Example structure:

publicstaticclassRomanianDefaultText

{

    publicstaticvoidSetDefaultText()

    {

        BkDefaultText.Yes="Da";

        BkDefaultText.No="Nu";

        BkDefaultText.New="Nou";

        BkDefaultText.Edit="Editare";

        BkDefaultText.Delete="Ștergere";

        BkDefaultText.CreateItem="Creare";

        BkDefaultText.EditItem="Editare";

        BkDefaultText.DeleteItem="Ștergere";

        BkDefaultText.NoItems="Niciun element";

        BkDefaultText.Submit="Trimite";

        BkDefaultText.Cancel="Anulează";

        BkDefaultText.Close="Închide";

        BkDefaultText.Ok="Ok";

        BkDefaultText.Clear="Curăță";

        BkDefaultText.ClearAllFilters="Curăță toate filtrele";

        BkDefaultText.ApplyFilters="Aplică filtrele";

        BkDefaultText.SaveChanges="Salvează modificările";

        BkDefaultText.CancelChanges="Anulează modificările";

        BkDefaultText.ToolTipNew="Nou";

        BkDefaultText.ToolTipUpdate="Actualizează";

        BkDefaultText.ToolTipDelete="Șterge";

        BkDefaultText.ToolTipCancel="Anulează";

        BkDefaultText.SortTextTemplate="Sortează după {0}";

        BkDefaultText.Sort="Sortează";

        BkDefaultText.FilterTextTemplate="Filtrează după {0}";

        BkDefaultText.TotalItems="Total elemente";

        BkDefaultText.Back="Înapoi";

        BkDefaultText.Next="Următorul";

        BkDefaultText.PageSize="Mărimea paginii";

        BkDefaultText.Open="Deschide";

        BkDefaultText.Expand="Extinde";

        BkDefaultText.Collapse="Restrânge";

        BkDefaultText.Search="Caută";

        BkDefaultText.Date="Data";

        BkDefaultText.Value="Valoare";

        BkDefaultText.Checked="Verificat";

        BkDefaultText.Unchecked="Neverificat";

        BkDefaultText.SaveChangesToolTip="Salvează modificările";

        BkDefaultText.CancelChangesToolTip="Anulează modificările";

        BkDefaultText.AccessDenied="Acces refuzat";

        BkDefaultText.AccessDeniedMessage="Nu aveți permisiunea de a accesa această resursă.";

        BkDefaultText.ChangePassword="Schimbă parola";

        BkDefaultText.CurrentPasswordPlaceHolder="Parola actuală";

        BkDefaultText.CurrentPasswordToolTip="Introduceți parola actuală";

        BkDefaultText.CurrentPasswordLabel="Parola actuală";

        BkDefaultText.NewPasswordLabel="Parola nouă";

        BkDefaultText.NewPasswordPlaceHolder="Introduceți parola nouă";

        BkDefaultText.NewPasswordToolTip="Introduceți parola nouă";

        BkDefaultText.ConfirmPasswordToolTip="Confirmă noua parolă";

        BkDefaultText.ConfirmPasswordPlaceHolder="Confirmă parola nouă";

        BkDefaultText.ConfirmPasswordLabel="Confirmă parola";

        BkDefaultText.PasswordChangeConfirmationMessage="Parola a fost schimbată cu succes.";

        BkDefaultText.CheckYourEmail="Verificați e-mailul";

        BkDefaultText.SuccessMessageTitle="Succes";

        BkDefaultText.SuccessMessage="Operațiunea a fost efectuată cu succes.";

        BkDefaultText.InvalidPasswordResetTitle="Resetare parolă invalidă";

        BkDefaultText.InvalidPasswordResetMessage="Link-ul de resetare a parolei este invalid sau expirat.";

        BkDefaultText.ErrorTitle="Eroare";

        BkDefaultText.InvalidUserTitle="Utilizator invalid";

        BkDefaultText.InvalidUserMessage="Utilizatorul nu există.";

        BkDefaultText.LockoutTitle="Cont blocat";

        BkDefaultText.LockoutMessage="Contul este temporar blocat.";

        BkDefaultText.RegisterConfirmationTitle="Confirmare înregistrare";

        BkDefaultText.EmailConfirmationMessage="Vă rugăm să confirmați adresa de e-mail pentru a finaliza înregistrarea.";

        BkDefaultText.LoginButtonText="Autentificare";

        BkDefaultText.RegisterButtonText="Înregistrare";

        BkDefaultText.HomePageText="Pagina principală";

        BkDefaultText.LogoutSubmitButtonText="Deconectare";

        BkDefaultText.LogoutCancelButtonText="Anulează deconectarea";

        BkDefaultText.AuthenticationRequiredMessage="Autentificare necesară";

        BkDefaultText.ErrorMessage="A apărut o eroare.";

        BkDefaultText.WarningMessage="Nu s-a putut efectua operațiunea.";

    }

}

And in your Program.cs file:

publicclassProgram

{

    publicvoidMain()

    {

        varbuilder=WebApplication.CreateBuilder(args);

        BkCommandResult.Defaults.ErrorMessage="O no! An error occurred during the operation. Please try again.";

        BkCommandResult.Defaults.SuccessMessage="Hooray! The operation was completed successfully.";

        BkCommandResult.Defaults.WarningMessage="Oops! The operation was not successful.";

// Set the default text for Romanian        RomanianDefaultText.SetDefaultText();

    }

}

By following these steps, your application will use your customized text instead of the default one provided by the framework.

This makes your app feel native to your users and ensures consistency in the language and tone used throughout the interface.


Summary

Overriding the default text is an essential step in tailoring your application to meet specific language or branding requirements. With just a few lines of code, you can change both the system messages and the UI labels to better fit your audience.

Don’t forget to keep all overrides together in a dedicated class and call them early during application startup for better organization and maintainability.

An unhandled error has occurred. Reload 🗙