public static function l10n_form() { if (Input::instance()->get("show_all_l10n_messages")) { $calls = array(); foreach (Database::instance()->select("key", "message")->from("incoming_translations")->where(array("locale" => 'root'))->get()->as_array() as $row) { $calls[$row->key] = array(unserialize($row->message), array()); } } else { $calls = I18n::instance()->call_log(); } $locale = I18n::instance()->locale(); if ($calls) { $translations = array(); foreach (Database::instance()->select("key", "translation")->from("incoming_translations")->where(array("locale" => $locale))->get()->as_array() as $row) { $translations[$row->key] = unserialize($row->translation); } // Override incoming with outgoing... foreach (Database::instance()->select("key", "translation")->from("outgoing_translations")->where(array("locale" => $locale))->get()->as_array() 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 ''; }
private static function _parse_plural_calls(&$tokens, &$call_list, &$cache) { $errors = array(); foreach ($call_list as $index) { $function_name = $tokens[$index++]; $parens = $tokens[$index++]; $first_param = $tokens[$index++]; $first_separator = $tokens[$index++]; $second_param = $tokens[$index++]; $next_token = $tokens[$index]; if ($parens == "(") { if ($first_separator == "," && $next_token == "," && is_array($first_param) && $first_param[0] == T_CONSTANT_ENCAPSED_STRING && is_array($second_param) && $second_param[0] == T_CONSTANT_ENCAPSED_STRING) { $singular = self::_escape_quoted_string($first_param[1]); $plural = self::_escape_quoted_string($second_param[1]); l10n_scanner::process_message(array("one" => $singular, "other" => $plural), $cache); } else { if (is_array($first_param) && $first_param[0] == T_CONSTANT_ENCAPSED_STRING) { $errors[$first_param[2]] = var_export(array($function_name, $parens, $first_param, $first_separator, $second_param, $next_token), 1); } else { // t2() found, but inside is something which is not a string literal. That's fine. } } } } return $errors; }
private static function _parse_plural_calls(&$tokens, &$call_list, &$cache) { foreach ($call_list as $index) { $function_name = $tokens[$index++]; $parens = $tokens[$index++]; $first_param = $tokens[$index++]; $first_separator = $tokens[$index++]; $second_param = $tokens[$index++]; $next_token = $tokens[$index]; if ($parens == "(") { if ($first_separator == "," && $next_token == "," && is_array($first_param) && $first_param[0] == T_CONSTANT_ENCAPSED_STRING && is_array($second_param) && $second_param[0] == T_CONSTANT_ENCAPSED_STRING) { $singular = self::_escape_quoted_string($first_param[1]); $plural = self::_escape_quoted_string($second_param[1]); l10n_scanner::process_message(array("one" => $singular, "other" => $plural), $cache); } else { // t2() found, but inside is something which is not a string literal. // @todo Call status callback with error filename/line. } } } }