APPNETOS is under active development This website and its documentation are being prepared for public launch. Content and features may change.
Select Theme
Loading

Language Selector

A ready-to-integrate language switcher for multilingual APPNETOS applications.

APPNETOS Selectors are reusable components providing predefined selections. Language Selector supplies the language-switching functionality, allowing developers to integrate it without rebuilding language selection from scratch.

How it works

The shared CoreApp\Selector\LanguageSelector handles language loading, active-language resolution, language switching and selector rendering. Applications can extend this component to change how and where the interface is presented.

APPNETOS Core Apps requiring translations already provide translations for 81 languages. The language choices available to a particular application still depend on its own configuration and supported content.

Integration example: APPNETOS DNS Control

DNS Control extends the shared Core App and adds an application-specific Bootstrap offcanvas wrapper. The integration uses the parent's selector output rather than replacing its language-selection logic.

PHP override

public function __invoke(): string|null
{
    $this->_bootstrap->init();

    $languageSelectorTemplate = parent::__invoke();

    return $this->load(
        'appnetos-dns-control/admin/apps/selector/language-selector/templates/language-selector.html.twig',
        ['language_selector_template' => $languageSelectorTemplate],
    );
}

The application's Bootstrap service is injected using #[Autowire(Bootstrap::class)]; its constructor calls parent::__construct().

Twig wrapper

The wrapper uses offcanvas offcanvas-end, a translated heading (translations.select_language) and a Bootstrap close button. The shared selector HTML is inserted using:

<div id="appnetos-dns-control-selector-language-selector__offcanvas-body">
    
</div>

The |raw filter is intended for trusted HTML returned by the Core App, not untrusted user input.

Custom JavaScript

class AppnetosDnsControlSelectorLanguageSelector {
    constructor() {
        this.offcanvas = null;
    }

    load = () => {
        coreAppSelectorLanguageSelector.load();

        const element = document.getElementById(
            "appnetos-dns-control-selector-language-selector__offcanvas"
        );
        this.offcanvas = new bootstrap.Offcanvas(element);
        this.offcanvas.show();
    }
}

const appnetosDnsControlSelectorLanguagePicker =
    new AppnetosDnsControlSelectorLanguageSelector();

Calling the custom load() method initializes the Core App's client-side selector and opens the offcanvas. The example assumes Bootstrap JavaScript, the Core App script and the offcanvas element are available. The event that invokes this method is not shown in the supplied files.

Customization points

Extension Purpose
__invoke(): string|null Initialize the application and wrap the parent Core App output.
Application Twig template Change the layout, translated heading and selector placement.
Application JavaScript Integrate the Core App with custom UI such as Bootstrap offcanvas.
Core App templates Replace templates for your own design; Core Apps provide versioned templates for supported Bootstrap CSS versions.

The override methods listed here are confirmed by the supplied DNS Control integration. Additional methods in the shared Core App are not asserted without its source.

See Selector Core Apps for the category overview and App Content for the underlying content model.

Next Steps

Previous

Selector

Explore Selector

Next

Personalization

Explore Personalization