Global labels

Change the default text of every resource's pages at once

StellarAdmin builds the default text of each resource's pages from the resource's labels, such as "Create Trip" for the create page's title, and "Search Trips..." for the search box. While you can override these on an individual resource level, you can also specify it on a global level to apply to all resources, using ConfigureResourceLabels() on the admin builder.

The example below changes the create button, the search box and the submit buttons:

builder.Services.AddStellarAdmin(admin =>
{
    admin.ConfigureResourceLabels(labels =>
    {
        labels.Index(index =>
        {
            index.CreateLabel = resource => $"New {resource.SingularLabel.ToLower()}";
            index.SearchPlaceholder = resource => $"Find {resource.PluralLabel.ToLower()}";
        });
        labels.Create(create => create.SubmitLabel = _ => "Save");
        labels.Edit(edit => edit.SubmitLabel = _ => "Save changes");
        labels.Delete(delete => delete.ConfirmLabel = _ => "Yes, delete");
    });
});

Each setting is a function that returns the text. Its parameter is a ResourceLabelContext, with the resource's SingularLabel and PluralLabel.

Text you specify on a specific resource's configuration, such as edit.Title in AllowEdit(), overrides the global default for that resource.

The view and edit pages use the record's title as the page title. Their Title label is used only when the record's title is the key or empty.

What you can change

Call the method for the part of the admin panel you want to change, and set its properties in the callback:

MethodProperties
Index()Title, CreateLabel, EditLabel, ViewLabel, DeleteLabel and SearchPlaceholder, and the inline editing texts
Create()Title, SubmitLabel and AddAnotherLabel
Edit()Title and SubmitLabel
View()Title
Delete()Title, Message, ConfirmLabel and CancelLabel of the delete confirmation
Lookup()The text of the lookups, such as ChooseLabel, CreateLabel, LoadMoreLabel and NoResultsTitle
ListEditor(), DictionaryEditor()The text of the list and dictionary editors, such as AddText and EmptyText, and their error messages
Sheet()ErrorTitle, ErrorDescription, SaveErrorDescription and RetryLabel, displayed when a sheet can't load or save

The Sheet() properties are strings, not functions, because they don't depend on the resource:

labels.Sheet(sheet => sheet.RetryLabel = "Reload");

Changing the text of lookups and editors

The functions of Lookup(), ListEditor() and DictionaryEditor() take a parameter about the field instead of the resource, with the field's label in FieldLabel:

admin.ConfigureResourceLabels(labels =>
{
    labels.Lookup(lookup => lookup.ChooseLabel = field => $"Select {field.FieldLabel.ToLower()}");
    labels.ListEditor(list => list.AddText = field => $"Add to {field.FieldLabel.ToLower()}");
});

Some list and dictionary texts contain a number or a value that StellarAdmin fills in, such as the number of items on the row with the add button. To include it in your text, put its placeholder in the text you return. The example below sets texts with placeholders for every list and dictionary editor:

admin.ConfigureResourceLabels(labels =>
{
    labels.ListEditor(list =>
    {
        list.CountText = _ => "{count} added";
        list.DuplicateText = _ => "{value} is already added";
        list.RemoveLabel = _ => "Delete item {n}";
    });
    labels.DictionaryEditor(dictionary =>
        dictionary.DuplicateText = _ => "The key {value} is taken");
});

These are the texts with placeholders:

TextPlaceholderReplaced with
CountText{count}The number of items or entries, displayed on the row with the add button when there is a maximum.
DuplicateText{value}The item that is already in the list, or the key that is already used.
ItemLabel (lists only){n}The item's number, in its label for screen readers.
MoveLabel (lists only){n}The item's number, in the drag handle's label for screen readers.
RemoveLabel{n}The item's or entry's number, in the remove button's label for screen readers.

Translating the admin panel

StellarAdmin doesn't use IStringLocalizer. To translate the admin panel's text, return your translations from the functions. StellarAdmin calls the functions for every request, so they can use the request's culture.

Field labels come from the fields' configuration or from [Display(Name = ...)]. To translate them, set ResourceType on the [Display] attribute.

On this page