Search Results for

    Show / Hide Table of Contents

    Localization

    If you want to create an application that supports different target languages, you may find the localization mechanism provided by XRV useful. It scans your assemblies for embedded resource files (.resx) and provides a set of Evergine components that let you choose dictionary name-entry pairs for 3D texts or buttons. Lookup assemblies must be decorated with the EvergineAssembly attribute with UserProject or Extension as the value.

    Note

    In its current state, we only support English (fallback) and Spanish as available languages for applications. We plan to add extension points in the future to allow developers to add new languages.

    You can easily change the current UI culture:

    var localization = this.xrvService.Localization;
    localization.CurrentCulture = CultureInfo.GetCultureInfo("es");
    

    When the culture changes, a CurrentCultureChangeMessage is published in PubSub, indicating the value of the new UI culture. It also changes the current thread's CurrentUICulture and CurrentCulture values.

    Built-in Components for Localization

    We provide a set of components to control localization for button texts and 3D texts:

    • Text3dLocalization: For localized text in Text3DMesh components.
    • ButtonLocalization: To localize button text for entities with the StandardButtonConfigurator component.
    • ToggleButtonLocalization: To localize toggle button text for entities with the ToggleStateManager component. You should have one component instance for each of the toggle states.

    localization 3D text sample

    For a toggle button, as we mentioned, you must add one component for each of the toggle states.

    localization toggle button sample

    Get Localized String from Code

    To retrieve a localized string, use the localization service.

    var localization = this.xrvService.Localization;
    var localizedString = this.localization.GetString(() => Resources.Strings.MyString);
    

    Hand Menu Buttons

    MenuButtonDescription provides a way to set localized text for hand menu buttons. If your button is a toggle button, you can also indicate different strings for each toggle state.

    var localization = this.xrvService.Localization;
    var description = new MenuButtonDescription()
    {
        TextOn = () => localization.GetString(() => Resources.Strings.MyString),
        TextOff = () => localization.GetString(() => Resources.Strings.MyString),
    };
    

    Tab Items

    TabItem lets you set a Func that will be invoked on the first run or when the current culture changes.

    var localization = this.xrvService.Localization;
    var item = new TabItem()
    {
        Name = () => localization.GetString(() => Resources.Strings.MyString),
        Contents = this.HelpContent,
    };
    

    Window Title

    WindowConfigurator also uses a specific Func property to provide localized text for the window title.

    var windowsSystem = this.xrvService.WindowsSystem;
    var localization = this.xrvService.Localization;
    var window = windowsSystem.CreateWindow(config => 
    {
        config.LocalizedTitle = () => localization.GetString(() => Resources.Strings.MyString),
    });
    

    Alert Dialogs

    The WindowsSystem API has overload methods for both ShowAlertDialog and ShowConfirmationDialog, where you can assign Func callbacks to provide localized dialogs.

    var windowsSystem = this.xrvService.WindowsSystem;
    var dialog = windowsSystem.ShowAlertDialog(
        () => localization.GetString(() => Resources.Strings.MyAlertTitle),
        () => localization.GetString(() => Resources.Strings.MyAlertMessage),
        () => localization.GetString(() => Resources.Strings.MyAlertOk));
    
    In this article
    Back to top
    Generated by DocFX