public function setup() { $config = array('root_locale' => 'en', 'default_locale' => 'te_ST', 'locale_dir' => VARPATH . 'locale/'); $this->i18n = Gallery_I18n::instance($config); db::build()->delete("incoming_translations")->where("locale", "=", "te_ST")->execute(); $messages_te_ST = array(array('Hello world', 'Hallo Welt'), array(array('one' => 'One item has been added', 'other' => '%count elements have been added'), array('one' => 'Ein Element wurde hinzugefuegt.', 'other' => '%count Elemente wurden hinzugefuegt.')), array('Hello %name, how are you today?', 'Hallo %name, wie geht es Dir heute?')); foreach ($messages_te_ST as $data) { list($message, $translation) = $data; $entry = ORM::factory("incoming_translation"); $entry->key = Gallery_I18n::get_message_key($message); $entry->message = serialize($message); $entry->translation = serialize($translation); $entry->locale = 'te_ST'; $entry->revision = null; $entry->save(); } }
static function set_request_locale() { // 1. Check the session specific preference (cookie) $locale = locales::cookie_locale(); // 2. Check the user's preference if (!$locale) { $locale = identity::active_user()->locale; } // 3. Check the browser's / OS' preference if (!$locale) { $locale = locales::locale_from_http_request(); } // If we have any preference, override the site's default locale if ($locale) { Gallery_I18n::instance()->locale($locale); } }
public static function l10n_form() { if (Input::instance()->get("show_all_l10n_messages")) { $calls = array(); foreach (db::build()->select("key", "message")->from("incoming_translations")->where("locale", "=", "root")->execute() as $row) { $calls[$row->key] = array(unserialize($row->message), array()); } } else { $calls = Gallery_I18n::instance()->call_log(); } $locale = Gallery_I18n::instance()->locale(); if ($calls) { $translations = array(); foreach (db::build()->select("key", "translation")->from("incoming_translations")->where("locale", "=", $locale)->execute() as $row) { $translations[$row->key] = unserialize($row->translation); } // Override incoming with outgoing... foreach (db::build()->select("key", "translation")->from("outgoing_translations")->where("locale", "=", $locale)->execute() as $row) { $translations[$row->key] = unserialize($row->translation); } $string_list = array(); $cache = array(); foreach ($calls as $key => $call) { list($message, $options) = $call; // Ensure that the message is in the DB l10n_scanner::process_message($message, $cache); // Note: Not interpolating placeholders for the actual translation input field. // TODO: Might show a preview w/ interpolations (using $options) $translation = isset($translations[$key]) ? $translations[$key] : ''; $string_list[] = array('source' => $message, 'key' => $key, 'translation' => $translation); } $v = new View('l10n_client.html'); $v->string_list = $string_list; $v->l10n_search_form = self::_l10n_client_search_form(); $v->plural_forms = l10n_client::plural_forms($locale); return $v; } return ''; }
/** * Translates a localizable message with plural forms. * @param $singular String The message to be translated. E.g. "There is one album." * @param $plural String The plural message to be translated. E.g. * "There are %count albums." * @param $count Number The number which is inserted for the %count placeholder and * which is used to select the proper plural form ($singular or $plural). * @param $options array (optional) Options array for key value pairs which are used * for pluralization and interpolation. Special key: "locale" to override the * currently configured locale. * @return String The translated message string. */ function t2($singular, $plural, $count, $options = array()) { return Gallery_I18n::instance()->translate(array("one" => $singular, "other" => $plural), array_merge($options, array("count" => $count))); }