class LocaleLanguages
Same name and namespace in other branches
- main core/modules/locale/src/LocaleLanguages.php \Drupal\locale\LocaleLanguages
Manages which languages are translatable and checks a specific language.
Hierarchy
- class \Drupal\locale\LocaleLanguages
Expanded class hierarchy of LocaleLanguages
11 files declare their use of LocaleLanguages
- ExportForm.php in core/
modules/ locale/ src/ Form/ ExportForm.php - ImportForm.php in core/
modules/ locale/ src/ Form/ ImportForm.php - locale.compare.inc in core/
modules/ locale/ locale.compare.inc - locale.module in core/
modules/ locale/ locale.module - LocaleCronHooks.php in core/
modules/ locale/ src/ Hook/ LocaleCronHooks.php
File
-
core/
modules/ locale/ src/ LocaleLanguages.php, line 11
Namespace
Drupal\localeView source
class LocaleLanguages {
public function __construct(protected readonly LanguageManagerInterface $languageManager, protected readonly ConfigFactoryInterface $configFactory) {
}
/**
* Returns list of translatable languages.
*
* @return array
* Array of installed languages keyed by language name. English is omitted
* unless it is marked as translatable.
*/
public function getTranslatableLanguages() : array {
$languages = $this->languageManager
->getLanguages();
if (!$this->isTranslatable('en')) {
unset($languages['en']);
}
return $languages;
}
/**
* Checks whether $langcode is a language supported as a locale target.
*
* @param string $langcode
* The language code.
*
* @return bool
* Whether $langcode can be translated to in locale.
*/
public function isTranslatable(string $langcode) : bool {
return $langcode != 'en' || $this->configFactory
->get('locale.settings')
->get('translate_english');
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| LocaleLanguages::getTranslatableLanguages | public | function | Returns list of translatable languages. |
| LocaleLanguages::isTranslatable | public | function | Checks whether $langcode is a language supported as a locale target. |
| LocaleLanguages::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.