本文整理汇总了PHP中locale::installed方法的典型用法代码示例。如果您正苦于以下问题:PHP locale::installed方法的具体用法?PHP locale::installed怎么用?PHP locale::installed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类locale
的用法示例。
在下文中一共展示了locale::installed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _add_locale_dropdown
private static function _add_locale_dropdown(&$form, $user = null)
{
$locales = locale::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);
}
}
示例2: fetch_updates
static function fetch_updates()
{
$request->locales = array();
$request->messages = new stdClass();
$locales = locale::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)) {
log::info("translations", "Translations fetch request resulted in an empty response");
return;
}
$response = json_decode($response_data);
// Response format (JSON payload):
// [{key:<key_1>, translation: <JSON encoded translation>, rev:<rev>, locale:<locale>},
// {key:<key_2>, ...}
// ]
$count = count($response);
log::info("translations", "Installed {$count} new / updated translation messages");
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 = serialize(json_decode($message_data->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();
}
}
示例3: _languages_form
private function _languages_form()
{
$all_locales = locale::available();
$installed_locales = locale::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;
}