public function testPrefixedLocaleResolve() { $locale = loco_locale_resolve('--en_GB'); $this->assertInstanceOf('LocoLocale', $locale); $this->assertEquals('English (UK)', $locale->get_name()); $this->assertEquals('en_GB', $locale->get_code()); return $locale; }
/** * Resolve a PO file path or file name to a locale. * Note that this does not read the file and the PO header, but perhaps it should. (performance!) * @return LocoLocale */ public static function resolve_file_locale($path) { $stub = str_replace(array('.po', '.mo'), array('', ''), basename($path)); $locale = loco_locale_resolve($stub); return $locale; }
/** * Export meta data used by templates. * @return array */ public function meta() { if (!is_array($this->_meta)) { $pot = $po = array(); // get POT files for all domains, fixing incorrect PO usage foreach ($this->get_domains() as $domain) { $path = $this->get_pot($domain) and $pot[] = compact('domain', 'path'); } // get progress and locale for each PO file foreach ($this->po as $domain => $locales) { foreach ($locales as $code => $path) { try { unset($headers); $export = LocoAdmin::parse_po_with_headers($path, $headers); $po[] = array('path' => $path, 'domain' => $domain, 'name' => trim(str_replace(array('.po', '.mo', $domain), array('', '', ''), basename($path)), '-_'), 'stats' => loco_po_stats($export), 'length' => count($export), 'locale' => loco_locale_resolve($code), 'projid' => trim($headers->{'project-id-version'})); } catch (Exception $Ex) { continue; } } } $this->_meta = compact('po', 'pot') + array('name' => $this->get_name(), 'root' => $this->get_root(), 'domain' => $this->get_domain()); } return $this->_meta; }
<?php /** * Admin ajax include that returns compiled-in data * Included by loco-ajax.php during Ajax action */ DOING_AJAX or die; // default is single locale response if (isset($locale)) { loco_require('loco-locales'); $data = loco_locale_resolve($locale); return array('locales' => array($locale => $data->export())); } throw new Exception(Loco::__('Invalid data posted to server'), 422);