When you extend the administration interface, display the texts of your customizations in the user's preferred admin UI language. Store the texts in registered resource files and retrieve them in your back-end and client-side code, or reference them using localization expressions in texts the system displays for you, such as field labels.
Access registered resource strings using ILocalizationService (opens in a new tab). The service reads strings registered for the LocalizationTarget.Server and LocalizationTarget.Builder targets.
using CMS.Core;
public class UserButtonLabels(ILocalizationService localizationService)
{
// Gets the localized string for the current UI culture
public string GetCreateLabel() =>
localizationService.GetString("myproject.admin.users.createButton");
// Gets the localized string for a specific culture
public string GetGermanCreateLabel() =>
localizationService.GetString("myproject.admin.users.createButton", "de-DE");
}To insert values into a resource string with placeholders, such as {0}, use the GetStringFormat extension method for ILocalizationService from the CMS.Helpers namespace. The method gets the string for the current UI culture and formats it with the given arguments using the standard String.Format method.
using CMS.Core;
using CMS.Helpers;
public class UserMessageProvider(ILocalizationService localizationService)
{
/* Formats a resource string such as "User {0} was deleted."
for the current UI culture. */
public string GetDeletedMessage(string userName) =>
localizationService.GetStringFormat("myproject.admin.users.deleted", userName);
}If a translation can't be formatted with the given arguments, for example, because the translation contains a {1} placeholder but the code passes only one argument, GetStringFormat formats the English (en-US) string instead. The method also logs a warning with the LocalizedStringFormatFailed event code to the event log. If the English string can't be formatted with the given arguments either, the method throws a FormatException.
We recommend using GetStringFormat instead of calling String.Format on the result of GetString.
Client-side admin code uses the i18n library (opens in a new tab) instead of ILocalizationService. The i18n library is automatically initialized with the current user's preferred admin UI culture and provides access to client-side localization resources.
Access localized strings in React components using the useTranslation hook from react-i18next:
import { useTranslation } from 'react-i18next';
export const MyAdminComponent = () => {
const { t } = useTranslation();
return (
<div>
<h1>{t('myproject.admin.users.title')}</h1>
<button>{t('myproject.admin.users.createButton')}</button>
<p>{t('myproject.validation.emailRequired')}</p>
</div>
);
};For a full usage guide and other resources, see the i18n documentation (opens in a new tab).
Resource key consistency
Use the same resource keys in both your .resx files and client-side code. The admin UI automatically loads client-side resources (registered with LocalizationTarget.Client) and makes them available to the i18n library.
Use the useGlobalization hook to access the current admin UI culture information, including both resource string culture and datetime format culture.
The useGlobalization hook provides:
uiLanguage – The culture code used for resource string localization. For cultures with UseDefaultSystemUICulture enabled, contains the default system culture (en-US).uiLocale – The culture code used for datetime and number formatting. Contains the CultureCode of the user's admin UI language.import { useGlobalization } from '@kentico/xperience-admin-base';
export const MyAdminComponent = () => {
const { uiLanguage, uiLocale } = useGlobalization();
return (
<div>
<p>Current UI language: {uiLanguage}</p>
<p>Current UI locale: {uiLocale}</p>
</div>
);
};Use the hook to format dates, numbers, or other culture-specific content in your React components consistently with the admin UI's localization settings.
Many texts in the admin UI support localization expressions in the format {$resource.key$}. An expression resolves to the matching resource string in the user's admin UI language, according to Resource string resolution and fallbacks. You can use the expressions in:
For example, the following screenshot demonstrates the localization of field metadata via the field editor.
In the editing interface of the corresponding object, the expression resolves to the underlying string.
The following example localizes the label and explanation text of an editing component:
using Kentico.Xperience.Admin.Base.FormAnnotations;
namespace MyProject.Admin;
public class ContactFormModel
{
[TextInputComponent(
Label = "{$myproject.admin.contactform.email.label$}",
ExplanationText = "{$myproject.admin.contactform.email.explanation$}",
Order = 1)]
public string Email { get; set; }
}Store the strings in a resource file registered for LocalizationTarget.Server, or for LocalizationTarget.Builder when the texts belong to builder components. Strings registered only for LocalizationTarget.Client don't resolve in localization expressions.
For custom rich text editor configurations, use localization expressions to translate custom options and display names. Register the corresponding resource strings in a resource file for LocalizationTarget.Server.
The expressions work in any option with a custom display name. For example, the following configuration localizes the names of inline styles (opens in a new tab):
{
"toolbarButtons": [
"bold", "italic", "underline", "|", "inlineStyle", "customButton"
],
"inlineStyles": {
"{$myproject.editor.redBoldText$}": "font-size: 16px; font-weight: bold; color: red;",
"{$myproject.editor.blueItalicText$}": "font-style: italic; color: blue;",
"{$myproject.editor.highlightText$}": "background-color: yellow; padding: 2px;"
}
}The editor's own interface and Xperience's editor customizations are part of the system translation. See Translate the rich text editor.