本文整理汇总了PHP中locales::installed方法的典型用法代码示例。如果您正苦于以下问题:PHP locales::installed方法的具体用法?PHP locales::installed怎么用?PHP locales::installed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类locales
的用法示例。
在下文中一共展示了locales::installed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
public function setup()
{
self::$installed_locales = locales::installed();
self::$default_locale = module::get_var("gallery", "default_locale");
locales::update_installed(array_keys(locales::available()));
module::set_var("gallery", "default_locale", "no_NO");
}
示例2: head
static function head($theme)
{
$session = Session::instance();
$buf = "";
$buf .= $theme->css("gallery.css");
if ($session->get("debug")) {
$buf .= $theme->css("debug.css");
}
if (module::is_active("rss")) {
if ($item = $theme->item()) {
if ($item->is_album()) {
$buf .= rss::feed_link("gallery/album/{$item->id}");
} else {
$buf .= rss::feed_link("gallery/album/{$item->parent()->id}");
}
} else {
if ($tag = $theme->tag()) {
$buf .= rss::feed_link("tag/tag/{$tag->id}");
}
}
}
if (count(locales::installed())) {
// Needed by the languages block
$buf .= $theme->script("jquery.cookie.js");
}
if ($session->get("l10n_mode", false)) {
$buf .= $theme->css("l10n_client.css") . $theme->script("jquery.cookie.js") . $theme->script("l10n_client.js");
}
$buf .= $theme->css("uploadify/uploadify.css");
return $buf;
}
示例3: head
static function head($theme)
{
if (count(locales::installed())) {
// Needed by the languages block
$theme->script("jquery.cookie.js");
}
return "";
}
示例4: _add_locale_dropdown
private static function _add_locale_dropdown(&$form, $user = null)
{
$locales = locales::installed();
if (count($locales) > 1) {
// Put "none" at the first position in the array
$locales = array_merge(array("" => t("« none »")), $locales);
$selected_locale = $user && $user->locale ? $user->locale : "";
$form->dropdown("locale")->label(t("Language Preference"))->options($locales)->selected($selected_locale);
}
}
示例5: _add_locale_dropdown
/** @todo combine with Admin_Users_Controller::_add_locale_dropdown */
private function _add_locale_dropdown(&$form, $user = null)
{
$locales = locales::installed();
foreach ($locales as $locale => $display_name) {
$locales[$locale] = SafeString::of_safe_html($display_name);
}
if (count($locales) > 1) {
// Put "none" at the first position in the array
$locales = array_merge(array("" => t("« none »")), $locales);
$selected_locale = $user && $user->locale ? $user->locale : "";
$form->dropdown("locale")->label(t("Language Preference"))->options($locales)->selected($selected_locale);
}
}
示例6: sidebar_blocks
static function sidebar_blocks($theme)
{
$locales = locales::installed();
foreach ($locales as $locale => $display_name) {
$locales[$locale] = SafeString::of_safe_html($display_name);
}
if (count($locales) > 1) {
$block = new Block();
$block->css_id = "gUserLanguageBlock";
$block->title = t("Select Language Preference");
$block->content = new View("user_languages_block.html");
$block->content->installed_locales = array_merge(array("" => t("« none »")), $locales);
$block->content->selected = (string) user::cookie_locale();
return $block;
}
}
示例7: save
public function save()
{
access::verify_csrf();
locales::update_installed($this->input->post("installed_locales"));
$installed_locales = array_keys(locales::installed());
$new_default_locale = $this->input->post("default_locale");
if (!in_array($new_default_locale, $installed_locales)) {
if (!empty($installed_locales)) {
$new_default_locale = $installed_locales[0];
} else {
$new_default_locale = "en_US";
}
}
module::set_var("gallery", "default_locale", $new_default_locale);
print json_encode(array("result" => "success"));
}
示例8: get
static function get($block_id, $theme)
{
$block = "";
switch ($block_id) {
case "language":
$locales = locales::installed();
foreach ($locales as $locale => $display_name) {
$locales[$locale] = SafeString::of_safe_html($display_name);
}
if (count($locales) > 1) {
$block = new Block();
$block->css_id = "g-user-language-block";
$block->title = t("Language Preference");
$block->content = new View("user_languages_block.html");
$block->content->installed_locales = array_merge(array("" => t("« none »")), $locales);
$block->content->selected = (string) user::cookie_locale();
}
break;
}
return $block;
}
示例9: cookie_locale
static function cookie_locale()
{
// Can't use Input framework for client side cookies since
// they're not signed.
$cookie_data = isset($_COOKIE["g_locale"]) ? $_COOKIE["g_locale"] : null;
$locale = null;
if ($cookie_data) {
if (preg_match("/^([a-z]{2,3}(?:_[A-Z]{2})?)\$/", trim($cookie_data), $matches)) {
$requested_locale = $matches[1];
$installed_locales = locales::installed();
if (isset($installed_locales[$requested_locale])) {
$locale = $requested_locale;
}
}
}
return $locale;
}
示例10: cookie_locale
static function cookie_locale()
{
$cookie_data = Input::instance()->cookie("g_locale");
$locale = null;
if ($cookie_data) {
if (preg_match("/^([a-z]{2,3}(?:_[A-Z]{2})?)\$/", trim($cookie_data), $matches)) {
$requested_locale = $matches[1];
$installed_locales = locales::installed();
if (isset($installed_locales[$requested_locale])) {
$locale = $requested_locale;
}
}
}
return $locale;
}
示例11: fetch_updates
/**
* @return an array of messages that will be written to the task log
*/
static function fetch_updates()
{
$request->locales = array();
$request->messages = new stdClass();
$locales = locales::installed();
foreach ($locales as $locale => $locale_data) {
$request->locales[] = $locale;
}
// @todo Batch requests (max request size)
foreach (Database::instance()->select("key", "locale", "revision", "translation")->from("incoming_translations")->get()->as_array() as $row) {
if (!isset($request->messages->{$row->key})) {
$request->messages->{$row->key} = 1;
}
if (!empty($row->revision) && !empty($row->translation)) {
if (!is_object($request->messages->{$row->key})) {
$request->messages->{$row->key} = new stdClass();
}
$request->messages->{$row->key}->{$row->locale} = $row->revision;
}
}
// @todo Include messages from outgoing_translations?
$request_data = json_encode($request);
$url = self::_server_url() . "?q=translations/fetch";
list($response_data, $response_status) = remote::post($url, array("data" => $request_data));
if (!remote::success($response_status)) {
throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status);
}
if (empty($response_data)) {
return array(t("Translations fetch request resulted in an empty response"));
}
$response = json_decode($response_data);
// Response format (JSON payload):
// [{key:<key_1>, translation: <JSON encoded translation>, rev:<rev>, locale:<locale>},
// {key:<key_2>, ...}
// ]
foreach ($response as $message_data) {
// @todo Better input validation
if (empty($message_data->key) || empty($message_data->translation) || empty($message_data->locale) || empty($message_data->rev)) {
throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED: Invalid response data");
}
$key = $message_data->key;
$locale = $message_data->locale;
$revision = $message_data->rev;
$translation = json_decode($message_data->translation);
if (!is_string($translation)) {
// Normalize stdclass to array
$translation = (array) $translation;
}
$translation = serialize($translation);
// @todo Should we normalize the incoming_translations table into messages(id, key, message)
// and incoming_translations(id, translation, locale, revision)? Or just allow
// incoming_translations.message to be NULL?
$locale = $message_data->locale;
$entry = ORM::factory("incoming_translation")->where(array("key" => $key, "locale" => $locale))->find();
if (!$entry->loaded) {
// @todo Load a message key -> message (text) dict into memory outside of this loop
$root_entry = ORM::factory("incoming_translation")->where(array("key" => $key, "locale" => "root"))->find();
$entry->key = $key;
$entry->message = $root_entry->message;
$entry->locale = $locale;
}
$entry->revision = $revision;
$entry->translation = $translation;
$entry->save();
}
}
示例12: _languages_form
private function _languages_form()
{
$all_locales = locales::available();
$installed_locales = locales::installed();
$form = new Forge("admin/languages/save", "", "post", array("id" => "gLanguageSettingsForm"));
$group = $form->group("choose_language")->label(t("Language settings"));
$group->dropdown("locale")->options($installed_locales)->selected(module::get_var("gallery", "default_locale"))->label(t("Default language"))->rules('required');
$installation_options = array();
foreach ($all_locales as $code => $display_name) {
$installation_options[$code] = array($display_name, isset($installed_locales->{$code}));
}
$group->checklist("installed_locales")->label(t("Installed Languages"))->options($installation_options)->rules("required");
$group->submit("save")->value(t("Save settings"));
return $form;
}
示例13: fetch_updates
/**
* Fetches translations for l10n messages. Must be called repeatedly
* until 0 is returned (which is a countdown indicating progress).
*
* @param $num_fetched in/out parameter to specify which batch of
* messages to fetch translations for.
* @return The number of messages for which we didn't fetch
* translations for.
*/
static function fetch_updates(&$num_fetched)
{
$request = new stdClass();
$request->locales = array();
$request->messages = new stdClass();
$locales = locales::installed();
foreach ($locales as $locale => $locale_data) {
$request->locales[] = $locale;
}
// See the server side code for how we arrive at this
// number as a good limit for #locales * #messages.
$max_messages = 2000 / count($locales);
$num_messages = 0;
$rows = db::build()->select("key", "locale", "revision", "translation")->from("incoming_translations")->order_by("key")->limit(1000000)->offset($num_fetched)->execute();
$num_remaining = $rows->count();
foreach ($rows as $row) {
if (!isset($request->messages->{$row->key})) {
if ($num_messages >= $max_messages) {
break;
}
$request->messages->{$row->key} = 1;
$num_messages++;
}
if (!empty($row->revision) && !empty($row->translation) && isset($locales[$row->locale])) {
if (!is_object($request->messages->{$row->key})) {
$request->messages->{$row->key} = new stdClass();
}
$request->messages->{$row->key}->{$row->locale} = (int) $row->revision;
}
$num_fetched++;
$num_remaining--;
}
// @todo Include messages from outgoing_translations?
if (!$num_messages) {
return $num_remaining;
}
$request_data = json_encode($request);
$url = self::_server_url("fetch");
list($response_data, $response_status) = remote::post($url, array("data" => $request_data));
if (!remote::success($response_status)) {
throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status);
}
if (empty($response_data)) {
return $num_remaining;
}
$response = json_decode($response_data);
// Response format (JSON payload):
// [{key:<key_1>, translation: <JSON encoded translation>, rev:<rev>, locale:<locale>},
// {key:<key_2>, ...}
// ]
foreach ($response as $message_data) {
// @todo Better input validation
if (empty($message_data->key) || empty($message_data->translation) || empty($message_data->locale) || empty($message_data->rev)) {
throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED: Invalid response data");
}
$key = $message_data->key;
$locale = $message_data->locale;
$revision = $message_data->rev;
$translation = json_decode($message_data->translation);
if (!is_string($translation)) {
// Normalize stdclass to array
$translation = (array) $translation;
}
$translation = serialize($translation);
// @todo Should we normalize the incoming_translations table into messages(id, key, message)
// and incoming_translations(id, translation, locale, revision)? Or just allow
// incoming_translations.message to be NULL?
$locale = $message_data->locale;
$entry = ORM::factory("incoming_translation")->where("key", "=", $key)->where("locale", "=", $locale)->find();
if (!$entry->loaded()) {
// @todo Load a message key -> message (text) dict into memory outside of this loop
$root_entry = ORM::factory("incoming_translation")->where("key", "=", $key)->where("locale", "=", "root")->find();
$entry->key = $key;
$entry->message = $root_entry->message;
$entry->locale = $locale;
}
$entry->revision = $revision;
$entry->translation = $translation;
$entry->save();
}
return $num_remaining;
}
示例14: get
static function get($block_id)
{
$block = new Block();
switch ($block_id) {
case "welcome":
$block->css_id = "g-welcome";
$block->title = t("Welcome to Gallery 3");
$block->content = new View("admin_block_welcome.html");
break;
case "photo_stream":
$block->css_id = "g-photo-stream";
$block->title = t("Photo Stream");
$block->content = new View("admin_block_photo_stream.html");
$block->content->photos = ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10);
break;
case "log_entries":
$block->css_id = "g-log-entries";
$block->title = t("Log Entries");
$block->content = new View("admin_block_log_entries.html");
$block->content->entries = ORM::factory("log")->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5);
break;
case "stats":
$block->css_id = "g-stats";
$block->title = t("Gallery Stats");
$block->content = new View("admin_block_stats.html");
$block->content->album_count = ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all();
$block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all();
break;
case "platform_info":
$block->css_id = "g-platform";
$block->title = t("Platform Information");
$block->content = new View("admin_block_platform.html");
if (is_readable("/proc/loadavg")) {
$block->content->load_average = join(" ", array_slice(split(" ", array_shift(file("/proc/loadavg"))), 0, 3));
} else {
$block->content->load_average = t("Unavailable");
}
break;
case "project_news":
$block->css_id = "g-project-news";
$block->title = t("Gallery Project News");
$block->content = new View("admin_block_news.html");
$block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3);
break;
case "block_adder":
$block->css_id = "g-block-adder";
$block->title = t("Dashboard Content");
$block->content = self::get_add_block_form();
break;
case "language":
$locales = locales::installed();
if (count($locales)) {
foreach ($locales as $locale => $display_name) {
$locales[$locale] = SafeString::of_safe_html($display_name);
}
$block = new Block();
$block->css_id = "g-user-language-block";
$block->title = t("Language Preference");
$block->content = new View("user_languages_block.html");
$block->content->installed_locales = array_merge(array("" => t("« none »")), $locales);
$block->content->selected = (string) locales::cookie_locale();
} else {
$block = "";
}
break;
}
return $block;
}
示例15: get
static function get($block_id)
{
$block = new Block();
switch ($block_id) {
case "welcome":
$block->css_id = "g-welcome";
$block->title = t("Welcome to Gallery 3");
$block->content = new View("admin_block_welcome.html");
break;
case "photo_stream":
$block->css_id = "g-photo-stream";
$block->title = t("Photo stream");
$block->content = new View("admin_block_photo_stream.html");
$block->content->photos = ORM::factory("item")->where("type", "=", "photo")->order_by("created", "DESC")->find_all(10);
break;
case "log_entries":
$block->css_id = "g-log-entries";
$block->title = t("Log entries");
$block->content = new View("admin_block_log_entries.html");
$block->content->entries = ORM::factory("log")->order_by(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5);
break;
case "stats":
$block->css_id = "g-stats";
$block->title = t("Gallery stats");
$block->content = new View("admin_block_stats.html");
$block->content->album_count = ORM::factory("item")->where("type", "=", "album")->where("id", "<>", 1)->count_all();
$block->content->photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all();
break;
case "platform_info":
$block->css_id = "g-platform";
$block->title = t("Platform information");
$block->content = new View("admin_block_platform.html");
break;
case "project_news":
$block->css_id = "g-project-news";
$block->title = t("Gallery project news");
$block->content = new View("admin_block_news.html");
$block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3);
break;
case "block_adder":
$block->css_id = "g-block-adder";
$block->title = t("Dashboard content");
$block->content = gallery_block::get_add_block_form();
break;
case "language":
$locales = locales::installed();
if (count($locales) > 1) {
foreach ($locales as $locale => $display_name) {
$locales[$locale] = SafeString::of_safe_html($display_name);
}
$block = new Block();
$block->css_id = "g-user-language-block";
$block->title = t("Language preference");
$block->content = new View("user_languages_block.html");
$block->content->installed_locales = array_merge(array("" => t("« none »")), $locales);
$block->content->selected = (string) locales::cookie_locale();
} else {
$block = "";
}
break;
case "upgrade_checker":
$block = new Block();
$block->css_id = "g-upgrade-available-block";
$block->title = t("Check for Gallery upgrades");
$block->content = new View("upgrade_checker_block.html");
$block->content->version_info = upgrade_checker::version_info();
$block->content->auto_check_enabled = upgrade_checker::auto_check_enabled();
$block->content->new_version = upgrade_checker::get_upgrade_message();
}
return $block;
}