diff options
-rw-r--r-- | core/controllers/admin.php | 1 | ||||
-rw-r--r-- | core/controllers/admin_languages.php | 53 | ||||
-rw-r--r-- | core/helpers/core_menu.php | 6 | ||||
-rw-r--r-- | core/helpers/locale.php | 214 | ||||
-rw-r--r-- | core/libraries/I18n.php | 6 | ||||
-rw-r--r-- | core/views/admin_languages.html.php | 6 | ||||
-rw-r--r-- | modules/user/controllers/admin_users.php | 4 | ||||
-rw-r--r-- | modules/user/controllers/users.php | 2 | ||||
-rw-r--r-- | modules/user/helpers/user.php | 12 | ||||
-rw-r--r-- | modules/user/models/user.php | 3 |
10 files changed, 304 insertions, 3 deletions
diff --git a/core/controllers/admin.php b/core/controllers/admin.php index d83a0d6f..f8314007 100644 --- a/core/controllers/admin.php +++ b/core/controllers/admin.php @@ -36,7 +36,6 @@ class Admin_Controller extends Controller { $controller_name = "dashboard"; } $controller_name = "Admin_{$controller_name}_Controller"; - if ($args) { $method = array_shift($args); } else { diff --git a/core/controllers/admin_languages.php b/core/controllers/admin_languages.php new file mode 100644 index 00000000..2ce4eb16 --- /dev/null +++ b/core/controllers/admin_languages.php @@ -0,0 +1,53 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Admin_Languages_Controller extends Admin_Controller { + public function index() { + $view = new Admin_View("admin.html"); + $view->content = new View("admin_languages.html"); + + $locales = locale::available(); + asort($locales, SORT_LOCALE_STRING); + + $form = new Forge("/admin/languages/save", "", "post", array("id" => "gLanguageSettingsForm")); + $group = $form->group("settings") + ->label(t("Please select a language")); + $group->dropdown("locale_selection") + ->options($locales) + ->selected(module::get_var('core', 'default_locale')); + $group->submit("save")->value(t("Save settings")); + + $view->content->form = $form; + + print $view; + } + + public function save() { + $locales = locale::available(); + $selected_locale = $this->input->post('locale_selection'); + if (!isset($locales[$selected_locale])) { + message::error(t("Invalid selection")); + } else { + module::set_var("core", "default_locale", $selected_locale); + message::success(t("Settings saved")); + } + url::redirect("admin/languages"); + } +} + diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php index bb87c760..54fba640 100644 --- a/core/helpers/core_menu.php +++ b/core/helpers/core_menu.php @@ -115,7 +115,11 @@ class core_menu_Core { ->append(Menu::factory("link") ->id("graphics_toolkits") ->label(t("Graphics")) - ->url(url::site("admin/graphics")))) + ->url(url::site("admin/graphics"))) + ->append(Menu::factory("link") + ->id("languages") + ->label(t("Language Settings")) + ->url(url::site("admin/languages")))) ->append(Menu::factory("link") ->id("modules") ->label(t("Modules")) diff --git a/core/helpers/locale.php b/core/helpers/locale.php new file mode 100644 index 00000000..592f73b3 --- /dev/null +++ b/core/helpers/locale.php @@ -0,0 +1,214 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** + * This is the API for handling locales. + */ +class locale_Core { + /** + * Return the list of available locales. + */ + public static function available() { + $locales = array(); + list ($supportedLanguages, $defaultCountry) = self::getLanguageData(); + foreach ($supportedLanguages as $language_tag => $country_locales) { + foreach ($country_locales as $country_tag => $entry) { + $locales[$language_tag . '_' . $country_tag] = + $entry['description']; + } + } + + return $locales; + } + + private static function getLanguageData() { + static $supportedLanguages = array(); + static $defaultCountry = array(); + + // TODO(andy_st): Might want to add a localizable language name as well. + if (empty($supportedLanguages)) { + /* English */ + $supportedLanguages['en']['US']['description'] = 'English (US)'; + $supportedLanguages['en']['GB']['description'] = 'English (UK)'; + $defaultCountry['en'] = 'US'; + + /* Afrikaans */ + $supportedLanguages['af']['ZA']['description'] = 'Afrikaans'; + $defaultCountry['af'] = 'ZA'; + + /* Catalan */ + $supportedLanguages['ca']['ES']['description'] = 'Catalan'; + $defaultCountry['ca'] = 'ES'; + + /* Czech */ + $supportedLanguages['cs']['CZ']['description'] = 'Česky'; + $defaultCountry['cs'] = 'CZ'; + + /* Danish */ + $supportedLanguages['da']['DK']['description'] = 'Dansk'; + $defaultCountry['da'] = 'DK'; + + /* German */ + $supportedLanguages['de']['DE']['description'] = 'Deutsch'; + $defaultCountry['de'] = 'DE'; + + /* Spanish */ + $supportedLanguages['es']['ES']['description'] = 'Español'; + $supportedLanguages['es']['MX']['description'] = 'Español (MX)'; + $supportedLanguages['es']['AR']['description'] = 'Español (AR)'; + $defaultCountry['es'] = 'ES'; + + /* Estonian */ + $supportedLanguages['et']['EE']['description'] = 'Eesti'; + $defaultCountry['et'] = 'EE'; + + /* Basque */ + $supportedLanguages['eu']['ES']['description'] = 'Euskara'; + $defaultCountry['eu'] = 'ES'; + + /* French */ + $supportedLanguages['fr']['FR']['description'] = 'Français'; + $defaultCountry['fr'] = 'FR'; + + /* Irish */ + $supportedLanguages['ga']['IE']['description'] = 'Gaeilge'; + $defaultCountry['ga'] = 'IE'; + + /* Greek */ + $supportedLanguages['el']['GR']['description'] = 'Greek'; + $defaultCountry['el'] = 'GR'; + + /* Icelandic */ + $supportedLanguages['is']['IS']['description'] = 'Icelandic'; + $defaultCountry['is'] = 'IS'; + + + /* Italian */ + $supportedLanguages['it']['IT']['description'] = 'Italiano'; + $defaultCountry['it'] = 'IT'; + + /* Latvian */ + $supportedLanguages['lv']['LV']['description'] = 'Latviešu'; + $defaultCountry['lv'] = 'LV'; + + /* Lithuanian */ + $supportedLanguages['lt']['LT']['description'] = 'Lietuvių'; + $defaultCountry['lt'] = 'LT'; + + /* Hungarian */ + $supportedLanguages['hu']['HU']['description'] = 'Magyar'; + $defaultCountry['hu'] = 'HU'; + + /* Dutch */ + $supportedLanguages['nl']['NL']['description'] = 'Nederlands'; + $defaultCountry['nl'] = 'NL'; + + /* Norwegian */ + $supportedLanguages['no']['NO']['description'] = 'Norsk bokmål'; + $defaultCountry['no'] = 'NO'; + + /* Polish */ + $supportedLanguages['pl']['PL']['description'] = 'Polski'; + $defaultCountry['pl'] = 'PL'; + + /* Portuguese */ + $supportedLanguages['pt']['BR']['description'] = 'Português Brasileiro'; + $supportedLanguages['pt']['PT']['description'] = 'Português'; + $defaultCountry['pt'] = 'PT'; + + /* Romanian */ + $supportedLanguages['ro']['RO']['description'] = 'Română'; + $defaultCountry['ro'] = 'RO'; + + /* Slovak */ + $supportedLanguages['sk']['SK']['description'] = 'Slovenčina'; + $defaultCountry['sk'] = 'SK'; + + /* Slovenian */ + $supportedLanguages['sl']['SI']['description'] = 'Slovenščina'; + $defaultCountry['sl'] = 'SI'; + + /* Serbian */ + $supportedLanguages['sr']['CS']['description'] = 'Srpski'; + $defaultCountry['sr'] = 'CS'; + + /* Finnish */ + $supportedLanguages['fi']['FI']['description'] = 'Suomi'; + $defaultCountry['fi'] = 'FI'; + + /* Swedish */ + $supportedLanguages['sv']['SE']['description'] = 'Svenska'; + $defaultCountry['sv'] = 'SE'; + + /* Ukrainian */ + $supportedLanguages['uk']['UA']['description'] = 'УкÑаÑнÑÑка'; + $defaultCountry['uk'] = 'UA'; + + /* Vietnamese */ + $supportedLanguages['vi']['VN']['description'] = 'Tiếng Việt'; + $defaultCountry['vi'] = 'VN'; + + /* Turkish */ + $supportedLanguages['tr']['TR']['description'] = 'Türkçe'; + $defaultCountry['tr'] = 'TR'; + + /* Bulgarian */ + $supportedLanguages['bg']['BG']['description'] = + 'Български'; + $defaultCountry['bg'] = 'BG'; + + /* Russian */ + $supportedLanguages['ru']['RU']['description'] = + 'Русский'; + $defaultCountry['ru'] = 'RU'; + + /* Chinese */ + $supportedLanguages['zh']['CN']['description'] = '简体中文'; + $supportedLanguages['zh']['TW']['description'] = '繁體中文'; + $defaultCountry['zh'] = 'CN'; + + /* Korean */ + $supportedLanguages['ko']['KR']['description'] = '한국말'; + $defaultCountry['ko'] = 'KR'; + + /* Japanese */ + $supportedLanguages['ja']['JP']['description'] = '日本語'; + $defaultCountry['ja'] = 'JP'; + + /* Arabic */ + $supportedLanguages['ar']['SA']['description'] = + 'العربية'; + $supportedLanguages['ar']['SA']['right-to-left'] = true; + $defaultCountry['ar'] = 'SA'; + + /* Hebrew */ + $supportedLanguages['he']['IL']['description'] = 'עברית'; + $supportedLanguages['he']['IL']['right-to-left'] = true; + $defaultCountry['he'] = 'IL'; + + /* Farsi */ + $supportedLanguages['fa']['IR']['description'] = 'فارسي'; + $supportedLanguages['fa']['IR']['right-to-left'] = true; + $defaultCountry['fa'] = 'IR'; + } + + return array($supportedLanguages, $defaultCountry); + } +} diff --git a/core/libraries/I18n.php b/core/libraries/I18n.php index f69aa66f..475b14b6 100644 --- a/core/libraries/I18n.php +++ b/core/libraries/I18n.php @@ -55,6 +55,7 @@ class I18n_Core { private function __construct($config) { $this->_config = $config; + $this->setLocale($config['default_locale']); } public static function instance($config=null) { @@ -71,6 +72,11 @@ class I18n_Core { public function setLocale($locale) { $this->_config['default_locale'] = $locale; + // Attempt to set PHP's locale as well (for number formatting, collation, etc.) + // TODO: See G2 for better fallack code. + $locale_prefs = array($locale); + $locale_prefs[] = 'en_US'; + setlocale(LC_ALL, $locale_prefs); } /** diff --git a/core/views/admin_languages.html.php b/core/views/admin_languages.html.php new file mode 100644 index 00000000..9ba92038 --- /dev/null +++ b/core/views/admin_languages.html.php @@ -0,0 +1,6 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<div id="gLanguages"> + <h1> <?= t("Gallery Language Settings") ?> </h1> + + <?= $form ?> +</div> diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 38e68d30..14c4c593 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -41,6 +41,8 @@ class Admin_Users_Controller extends Controller { $user = user::create( $name, $form->add_user->full_name->value, $form->add_user->password->value); $user->email = $form->add_user->email->value; + $desired_locale = $form->add_user->locale->value; + $user->locale = $desired_locale == "none" ? null : $desired_locale; $user->save(); message::success(t("Created user %user_name", array("user_name" => $user->name))); print json_encode(array("result" => "success")); @@ -111,6 +113,8 @@ class Admin_Users_Controller extends Controller { $user->full_name = $form->edit_user->full_name->value; $user->password = $form->edit_user->password->value; $user->email = $form->edit_user->email->value; + $desired_locale = $form->edit_user->locale->value; + $user->locale = $desired_locale == "none" ? null : $desired_locale; $user->save(); message::success(t("Changed user %user_name", array("user_name" => $user->name))); print json_encode(array("result" => "success")); diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index dc6b3b4c..16984edf 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -35,6 +35,8 @@ class Users_Controller extends REST_Controller { } $user->email = $form->edit_user->email->value; $user->url = $form->edit_user->url->value; + $desired_locale = $form->edit_user->locale->value; + $user->locale = $desired_locale == "none" ? null : $desired_locale; $user->save(); print json_encode( diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index 4eedae06..c923bab4 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -29,6 +29,7 @@ class user_Core { $group = $form->group("edit_user")->label(t("Edit User")); $group->input("name")->label(t("Name"))->id("gName")->value($user->name); $group->input("full_name")->label(t("Full Name"))->id("gFullName")->value($user->full_name); + self::add_locale_dropdown($group, $user); $group->password("password")->label(t("Password"))->id("gPassword"); $group->password("password2")->label(t("Confirm Password"))->id("gPassword2") ->matches($group->password); @@ -47,6 +48,7 @@ class user_Core { $group->inputs["name"]->error_messages( "in_use", t("There is already a user with that name")); $group->input("full_name")->label(t("Full Name"))->id("gFullName")->value($user->full_name); + self::add_locale_dropdown($group, $user); $group->password("password")->label(t("Password"))->id("gPassword"); $group->password("password2")->label(t("Confirm Password"))->id("gPassword2") ->matches($group->password); @@ -69,12 +71,22 @@ class user_Core { ->matches($group->password); $group->input("email")->label(t("Email"))->id("gEmail"); $group->input("url")->label(t("URL"))->id("gUrl")->value($user->url); + self::add_locale_dropdown($group); $group->submit("")->value(t("Add User")); $user = ORM::factory("user"); $form->add_rules_from($user); return $form; } + private static function add_locale_dropdown(&$form, $user=null) { + $available_locales = locale::available(); + asort($available_locales, SORT_LOCALE_STRING); + $locales['none'] = t("Language Preference"); + $locales = array_merge($locales, $available_locales); + $selected_locale = ($user && $user->locale) ? $user->locale : "none"; + $form->dropdown("locale")->options($locales)->selected($selected_locale); + } + static function get_delete_form_admin($user) { $form = new Forge("admin/users/delete_user/$user->id", "", "post", array("id" => "gDeleteUserForm")); $group = $form->group("delete_user")->label( diff --git a/modules/user/models/user.php b/modules/user/models/user.php index 85fa75bb..a2715e00 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -24,7 +24,8 @@ class User_Model extends ORM { "name" => "required|length[1,32]", "full_name" => "length[0,255]", "email" => "valid_email|length[1,255]", - "password" => "required|length[1,40]"); + "password" => "required|length[1,40]", + "locale" => "length[2,10]"); public function __set($column, $value) { switch ($column) { |