Skip to content

Language API

You can manage languages configured in the system with PHP API by using LanguageService.

Getting language information

To get a list of all languages in the system use LanguageService::loadLanguages:

1
2
3
4
5
        $languageList = $this->languageService->loadLanguages();

        foreach ($languageList as $language) {
            $output->writeln($language->languageCode . ': ' . $language->name);
        }

Creating a language

To create a new language, you need to create a LanguageCreateStruct and provide it with the language code and language name. Then, use LanguageService::createLanguage and pass the LanguageCreateStruct to it:

1
2
3
4
        $languageCreateStruct = $this->languageService->newLanguageCreateStruct();
        $languageCreateStruct->languageCode = 'pol-PL';
        $languageCreateStruct->name = 'Polish';
        $this->languageService->createLanguage($languageCreateStruct);