You are here

protected function BaseMoment::getLocale in Twig Extender 8.3

Same name and namespace in other branches
  1. 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment::getLocale()
  2. 8.2 modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment::getLocale()
  3. 4.x modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment::getLocale()

Get current language.

Return value

string Return language id if exists. Default ist 'en_GB'.

1 call to BaseMoment::getLocale()
BaseMoment::getMoment in modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php
Get moment library.

File

modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php, line 19

Class

BaseMoment
Base class for moment plugins.

Namespace

Drupal\twig_extender_extras\Plugin\TwigPlugin

Code

protected function getLocale() {
  $language = \Drupal::service('language_manager')
    ->getCurrentLanguage();
  $default = 'en_GB';
  $reflector = new \ReflectionClass('\\Moment\\Moment');
  $lang = implode('_', [
    $language
      ->getId(),
    strtoupper($language
      ->getId()),
  ]);
  if (!file_exists(dirname($reflector
    ->getFileName()) . '/Locales/' . $lang . '.php')) {
    return $default;
  }
  return $lang;
}