コード例 #1
0
ファイル: LanguageCodesTest.php プロジェクト: getgrav/grav
 public function testRtl()
 {
     $this->assertSame('ltr', LanguageCodes::getOrientation('en'));
     $this->assertSame('rtl', LanguageCodes::getOrientation('ar'));
     $this->assertSame('rtl', LanguageCodes::getOrientation('he'));
     $this->assertTrue(LanguageCodes::isRtl('ar'));
     $this->assertFalse(LanguageCodes::isRtl('fr'));
 }
コード例 #2
0
 /**
  * Set needed variables to display Langswitcher.
  */
 public function onTwigSiteVariables()
 {
     $data = new \stdClass();
     $data->page_route = $this->grav['page']->rawRoute();
     /** @var Page $page */
     $page = $this->grav['page'];
     if ($page->home()) {
         $data->page_route = '';
     }
     $data->current = $this->grav['language']->getLanguage();
     $data->languages = LanguageCodes::getNames($this->grav['language']->getLanguages());
     $this->grav['twig']->twig_vars['langswitcher'] = $data;
     if ($this->config->get('plugins.langswitcher.built_in_css')) {
         $this->grav['assets']->add('plugin://langswitcher/css/langswitcher.css');
     }
 }
コード例 #3
0
ファイル: admin.php プロジェクト: getgrav/grav-plugin-admin
 /**
  * Return the languages available in the site
  *
  * @return array
  */
 public static function siteLanguages()
 {
     $languages = [];
     $lang_data = Grav::instance()['config']->get('system.languages.supported', []);
     foreach ($lang_data as $index => $lang) {
         $languages[$lang] = LanguageCodes::getNativeName($lang);
     }
     return $languages;
 }
コード例 #4
0
 /** Add the native_name function */
 public function onTwigInitialized()
 {
     $this->grav['twig']->twig()->addFunction(new \Twig_SimpleFunction('native_name', function ($key) {
         return LanguageCodes::getNativeName($key);
     }));
 }