/** * Run the database seeds. * * @return void */ public function run() { DB::table('languages')->delete(); $languages = get_locales(); //Config::get('translatable.locales'); foreach ($languages as $language) { $language = ['code' => $language, 'name' => PunicLanguage::getName($language, $language)]; Language::create($language); } }
/** * gets list of locales * * @param boolean $showInCodeLanguage true to show a code's name in the language the code represents * * @return array */ public static function getList($showInCodeLanguage = false) { $locales = Data::getAvailableLocales(); $languages = array(); foreach ($locales as $locale) { $key = \Xoops\Locale::normalizeLocale($locale); $languages[$key] = Language::getName($locale, $showInCodeLanguage ? $locale : null); } \XoopsLocale::asort($languages); return $languages; }
public function view() { $u = new User(); $profile = UserInfo::getByID($u->getUserID()); if (is_object($profile)) { $this->set('profile', $profile); } else { throw new Exception(t('You must be logged in to access this page.')); } $locales = array(); $languages = Localization::getAvailableInterfaceLanguages(); if (count($languages) > 0) { array_unshift($languages, 'en_US'); } if (count($languages) > 0) { foreach ($languages as $lang) { $locales[$lang] = \Punic\Language::getName($lang, $lang); } asort($locales); $locales = array_merge(array('' => tc('Default locale', '** Default')), $locales); } $this->set('locales', $locales); }
public function get_languages() { $languages = Localization::getAvailableInterfaceLanguages(); array_unshift($languages, 'en_US'); $obj = new stdClass(); $obj->text = tc('Default locale', '** Default'); $obj->value = ''; $result = array($obj); foreach ($languages as $lang) { $obj = new stdClass(); $obj->value = $lang; $obj->text = \Punic\Language::getName($lang); $result[] = $obj; } usort($result, function ($a, $b) { if ($a->value === '') { $cmp = -1; } elseif ($b->value === '') { $cmp = 1; } else { $cmp = strcasecmp($a->text, $b->text); } return $cmp; }); Loader::helper('ajax')->sendResult($result); }
public function on_start() { $config = $this->app->make('config'); $this->error = $this->app->make('helper/validation/error'); $this->set('valt', $this->app->make('helper/validation/token')); if ($config->get('concrete.user.registration.email_registration')) { $this->set('uNameLabel', t('Email Address')); } else { $this->set('uNameLabel', t('Username')); } $txt = $this->app->make('helper/text'); if (isset($_GET['uName']) && strlen($_GET['uName'])) { // pre-populate the username if supplied, if its an email address with special characters the email needs to be urlencoded first, $this->set("uName", trim($txt->email($_GET['uName']))); } $languages = array(); $locales = array(); if ($config->get('concrete.i18n.choose_language_login')) { $languages = Localization::getAvailableInterfaceLanguages(); if (count($languages) > 0) { array_unshift($languages, 'en_US'); } $locales = array(); foreach ($languages as $lang) { $locales[$lang] = \Punic\Language::getName($lang, $lang); } asort($locales); $locales = array_merge(array('' => tc('Default locale', '** Default')), $locales); } $this->locales = $locales; $this->set('locales', $locales); }
/** * Constructor for the WebController. * @param Model $model */ public function __construct($model) { parent::__construct($model); // initialize Twig templates $tmp_dir = $model->getConfig()->getTemplateCache(); // check if the cache pointed by config.inc exists, if not we create it. if (!file_exists($tmp_dir)) { mkdir($tmp_dir); } // specify where to look for templates and cache $loader = new Twig_Loader_Filesystem('view'); // initialize Twig environment $this->twig = new Twig_Environment($loader, array('cache' => $tmp_dir, 'auto_reload' => true, 'debug' => true)); $this->twig->addExtension(new Twig_Extensions_Extension_I18n()); //ENABLES DUMP() method for easy and fun debugging! $this->twig->addExtension(new Twig_Extension_Debug()); // used for setting the base href for the relative urls $this->base_href = $this->model->getConfig()->getBaseHref() !== null ? $this->model->getConfig()->getBaseHref() : $this->guessBaseHref(); $this->twig->addGlobal("BaseHref", $this->base_href); // setting the service name string from the config.inc $this->twig->addGlobal("ServiceName", $this->model->getConfig()->getServiceName()); // setting the service logo location from the config.inc if ($this->model->getConfig()->getServiceLogo() !== null) { $this->twig->addGlobal("ServiceLogo", $this->model->getConfig()->getServiceLogo()); } // setting the service custom css file from the config.inc if ($this->model->getConfig()->getCustomCss() !== null) { $this->twig->addGlobal("ServiceCustomCss", $this->model->getConfig()->getCustomCss()); } // used for displaying the ui language selection as a dropdown if ($this->model->getConfig()->getUiLanguageDropdown() !== null) { $this->twig->addGlobal("LanguageDropdown", $this->model->getConfig()->getUiLanguageDropdown()); } // setting the list of properties to be displayed in the search results $this->twig->addGlobal("PreferredProperties", array('skos:prefLabel', 'skos:narrower', 'skos:broader', 'skosmos:memberOf', 'skos:altLabel', 'skos:related')); // register a Twig filter for generating URLs for vocabulary resources (concepts and groups) $controller = $this; // for use by anonymous function below $urlFilter = new Twig_SimpleFilter('link_url', function ($uri, $vocab, $lang, $type = 'page', $clang = null, $term = null) use($controller) { // $vocab can either be null, a vocabulary id (string) or a Vocabulary object if ($vocab === null) { // target vocabulary is unknown, best bet is to link to the plain URI return $uri; } elseif (is_string($vocab)) { $vocid = $vocab; $vocab = $controller->model->getVocabulary($vocid); } else { $vocid = $vocab->getId(); } $params = array(); if (isset($clang) && $clang !== $lang) { $params['clang'] = $clang; } if (isset($term)) { $params['q'] = $term; } // case 1: URI within vocabulary namespace: use only local name $localname = $vocab->getLocalName($uri); if ($localname !== $uri && $localname === urlencode($localname)) { // check that the prefix stripping worked, and there are no problematic chars in localname $paramstr = sizeof($params) > 0 ? '?' . http_build_query($params) : ''; if ($type && $type !== '' && $type !== 'vocab') { return "{$vocid}/{$lang}/{$type}/{$localname}" . $paramstr; } return "{$vocid}/{$lang}/{$localname}" . $paramstr; } // case 2: URI outside vocabulary namespace, or has problematic chars // pass the full URI as parameter instead $params['uri'] = $uri; return "{$vocid}/{$lang}/{$type}/?" . http_build_query($params); }); $this->twig->addFilter($urlFilter); // register a Twig filter for generating strings from language codes with CLDR $langFilter = new Twig_SimpleFilter('lang_name', function ($langcode, $lang) { return Language::getName($langcode, $lang); }); $this->twig->addFilter($langFilter); }
/** * Returns an associative array with the locale code as the key and the translated language name as the value. * * @return array */ public function getLanguageList() { $languages = Language::getAll(true, true); return $languages; }
/** * Execute the console command. * * @return mixed */ public function handle() { $kritikktyper = []; foreach (KritikkType::all() as $kilde) { $kritikktyper[mb_strtolower($kilde->navn)] = $kilde->id; } $this->info(''); $this->warn(' This will re-populate the table from scratch. Any user contributed data will be lost!'); if (!$this->confirm('Are you sure you want to continue? [y|N]')) { return; } $data = $this->getData('import/litteraturkritikk.json'); $allespraak = array_flip(Language::getAll(true, true, 'nb')); $allespraak['finsk-svensk'] = 'sv'; $allespraak['bokmål'] = 'nb'; $allespraak['nynorsk'] = 'nn'; $allespraak['bokmål (innslag av nynorsk)'] = 'nb'; // Separate out 'person' columns $personColumns = ['forfatter_etternavn', 'forfatter_fornavn', 'forfatter_kjonn', 'kritiker_etternavn', 'kritiker_fornavn', 'kritiker_kjonn', 'kritiker_pseudonym']; $persons = array_map(function ($x) use($personColumns) { return array_only($x, array_merge(['id'], $personColumns)); }, $data); $records = array_map(function ($x) use($personColumns) { return array_except($x, $personColumns); }, $data); foreach ($records as &$row) { $this->processRecordRow($row, $allespraak); } $this->comment('Clearing DB'); \DB::delete('delete from litteraturkritikk_records'); $this->comment('Inserting records'); $chunks = array_chunk($records, 100); foreach ($chunks as $chunk) { \DB::table('litteraturkritikk_records')->insert($chunk); } $this->comment('Inserting persons'); $this->stats = ['forfatter' => [], 'kritiker' => []]; foreach ($persons as &$row) { $this->processCreators($row); } foreach ($this->stats['forfatter'] as $k => $v) { print "Forfatter: {$k} : {$v}\n"; } foreach ($this->stats['kritiker'] as $k => $v) { print "Kritiker: {$k} : {$v}\n"; } $this->info('Refreshing views'); \DB::unprepared('REFRESH MATERIALIZED VIEW litteraturkritikk_records_search'); $this->info('Updating sequences'); \DB::unprepared('SELECT pg_catalog.setval(pg_get_serial_sequence(\'litteraturkritikk_records\', \'id\'), MAX(id)) FROM litteraturkritikk_records'); \DB::unprepared('SELECT pg_catalog.setval(pg_get_serial_sequence(\'litteraturkritikk_personer\', \'id\'), MAX(id)) FROM litteraturkritikk_personer'); $this->info('Done'); }
public function languageNameByLanguageCode($code) { return ['name' => PunicLanguage::getName($code, $code)]; }
/** * Get the description of a locale consisting of language and region description * e.g. "French (France)" * @param string $locale Locale that should be described * @param string|null $displayLocale Language of the description. * Set to null to get each locale name in its own language, * set to '' to use the current locale, * set to a specific locale to get the names in that language * @return string Description of a language */ public static function getLanguageDescription($locale, $displayLocale = '') { return \Punic\Language::getName($locale, is_null($displayLocale) ? $locale : $displayLocale); }
public function getLanguageText($locale = null) { try { if (!$locale) { $locale = \Localization::activeLocale(); } $text = Language::getName($this->msLanguage, $locale); } catch (Exception $e) { $text = $this->msLanguage; } return $text; }
public function getNameLocalAttribute() { return PunicLanguage::getName($this->code, App::getLocale()); }