From 5833a6c8eb85d0aaeeb7374a77736a60b35d17e9 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 26 Sep 2003 08:04:48 +0000 Subject: [PATCH] The list of countries has finally been moved into the language packs so it can be translated. There is now a new function get_list_of_countries() which will return a sorted array of countries in the best current language. get_string("AU", "countries") will also work if needed --- admin/config.html | 2 +- admin/config.php | 1 - admin/register.php | 3 +- admin/user.php | 5 +- lang/en/countries.php | 243 +++++++++++++++++++++++++++++++++++++++++ lib/countries.php | 243 ----------------------------------------- lib/moodlelib.php | 17 +++ login/signup.php | 1 - login/signup_form.html | 2 +- user/edit.html | 2 +- user/edit.php | 1 - user/index.php | 9 +- user/lib.php | 6 +- user/view.php | 6 +- 14 files changed, 278 insertions(+), 263 deletions(-) create mode 100644 lang/en/countries.php delete mode 100644 lib/countries.php diff --git a/admin/config.html b/admin/config.html index cf2f53bdb3..b4ec01d17c 100644 --- a/admin/config.html +++ b/admin/config.html @@ -60,7 +60,7 @@

country: - country, get_string("selectacountry"), "") ?> + country, get_string("selectacountry"), "") ?> diff --git a/admin/config.php b/admin/config.php index 2a5c754962..d96939e953 100644 --- a/admin/config.php +++ b/admin/config.php @@ -2,7 +2,6 @@ // config.php - allows admin to edit all configuration variables require_once("../config.php"); - require_once("../lib/countries.php"); if ($site = get_site()) { // If false then this is a new installation diff --git a/admin/register.php b/admin/register.php index 535fdbcc28..46bf5181f4 100644 --- a/admin/register.php +++ b/admin/register.php @@ -2,7 +2,6 @@ // register.php - allows admin to register their site on moodle.org include("../config.php"); - require_once("../lib/countries.php"); require_login(); @@ -81,7 +80,7 @@ echo "\n"; echo "

".get_string("country").":\n"; echo "

"; - choose_from_menu ($COUNTRIES, "country", $admin->country, get_string("selectacountry")."...", "", ""); + choose_from_menu (get_list_of_countries(), "country", $admin->country, get_string("selectacountry")."...", "", ""); echo "\n"; echo "\n"; diff --git a/admin/user.php b/admin/user.php index e481147cb3..1bd7f0c5c8 100644 --- a/admin/user.php +++ b/admin/user.php @@ -2,7 +2,6 @@ require_once("../config.php"); require_once("../user/lib.php"); - require_once("../lib/countries.php"); $recordsperpage = 30; @@ -224,9 +223,11 @@ flush(); + $countries = get_list_of_countries(); + foreach ($users as $key => $user) { if (!empty($user->country)) { - $users[$key]->country = $COUNTRIES[$user->country]; + $users[$key]->country = $countries[$user->country]; } } if ($sort == "country") { // Need to resort by full country name, not code diff --git a/lang/en/countries.php b/lang/en/countries.php new file mode 100644 index 0000000000..dcc5503426 --- /dev/null +++ b/lang/en/countries.php @@ -0,0 +1,243 @@ + diff --git a/lib/countries.php b/lib/countries.php deleted file mode 100644 index c3d2936cd0..0000000000 --- a/lib/countries.php +++ /dev/null @@ -1,243 +0,0 @@ - "Afghanistan", -"AL" => "Albania", -"DZ" => "Algeria", -"AS" => "American Samoa", -"AD" => "Andorra", -"AO" => "Angola", -"AI" => "Anguilla", -"AQ" => "Antarctica", -"AG" => "Antigua and Barbuda", -"AR" => "Argentina", -"AM" => "Armenia", -"AW" => "Aruba", -"AU" => "Australia", -"AT" => "Austria", -"AZ" => "Azerbaijan", -"BS" => "Bahamas", -"BH" => "Bahrain", -"BD" => "Bangladesh", -"BB" => "Barbados", -"BY" => "Belarus", -"BE" => "Belgium", -"BZ" => "Belize", -"BJ" => "Benin", -"BM" => "Bermuda", -"BT" => "Bhutan", -"BO" => "Bolivia", -"BA" => "Bosnia and Herzegovina", -"BW" => "Botswana", -"BV" => "Bouvet Island", -"BR" => "Brazil", -"IO" => "British Indian Ocean Territory", -"BN" => "Brunei Darussalam", -"BG" => "Bulgaria", -"BF" => "Burkina Faso", -"BI" => "Burundi", -"KH" => "Cambodia", -"CM" => "Cameroon", -"CA" => "Canada", -"CV" => "Cape Verde", -"KY" => "Cayman Islands", -"CF" => "Central African Republic", -"TD" => "Chad", -"CL" => "Chile", -"CN" => "China", -"CX" => "Christmas Island", -"CC" => "Cocos (Keeling) Islands", -"CO" => "Colombia", -"KM" => "Comoros", -"CG" => "Congo", -"CK" => "Cook Islands", -"CR" => "Costa Rica", -"CI" => "Cote D'Ivoire", -"HR" => "Croatia (Hrvatska)", -"CU" => "Cuba", -"CY" => "Cyprus", -"CZ" => "Czech Republic", -"DK" => "Denmark", -"DJ" => "Djibouti", -"DM" => "Dominica", -"DO" => "Dominican Republic", -"TP" => "East Timor", -"EC" => "Ecuador", -"EG" => "Egypt", -"SV" => "El Salvador", -"GQ" => "Equatorial Guinea", -"ER" => "Eritrea", -"EE" => "Estonia", -"ET" => "Ethiopia", -"FK" => "Falkland Islands (Malvinas)", -"FO" => "Faroe Islands", -"FJ" => "Fiji", -"FI" => "Finland", -"FR" => "France", -"FX" => "France, Metropolitan", -"GF" => "French Guiana", -"PF" => "French Polynesia", -"TF" => "French Southern Territories", -"GA" => "Gabon", -"GM" => "Gambia", -"GE" => "Georgia", -"DE" => "Germany", -"GH" => "Ghana", -"GI" => "Gibraltar", -"GR" => "Greece", -"GL" => "Greenland", -"GD" => "Grenada", -"GP" => "Guadeloupe", -"GU" => "Guam", -"GT" => "Guatemala", -"GN" => "Guinea", -"GW" => "Guinea-Bissau", -"GY" => "Guyana", -"HT" => "Haiti", -"HM" => "Heard and Mc Donald Islands", -"HN" => "Honduras", -"HK" => "Hong Kong", -"HU" => "Hungary", -"IS" => "Iceland", -"IN" => "India", -"ID" => "Indonesia", -"IR" => "Iran (Islamic Republic of)", -"IQ" => "Iraq", -"IE" => "Ireland", -"IL" => "Israel", -"IT" => "Italy", -"JM" => "Jamaica", -"JP" => "Japan", -"JO" => "Jordan", -"KZ" => "Kazakhstan", -"KE" => "Kenya", -"KI" => "Kiribati", -"KP" => "Korea, Democratic People's Republic of", -"KR" => "Korea, Republic of", -"KO" => "Kosovo", -"KW" => "Kuwait", -"KG" => "Kyrgyzstan", -"LA" => "Lao People's Democratic Republic", -"LV" => "Latvia", -"LB" => "Lebanon", -"LS" => "Lesotho", -"LR" => "Liberia", -"LY" => "Libyan Arab Jamahiriya", -"LI" => "Liechtenstein", -"LT" => "Lithuania", -"LU" => "Luxembourg", -"MO" => "Macau", -"MK" => "Macedonia, Former Yugoslav Republic of", -"MG" => "Madagascar", -"MW" => "Malawi", -"MY" => "Malaysia", -"MV" => "Maldives", -"ML" => "Mali", -"MT" => "Malta", -"MH" => "Marshall Islands", -"MQ" => "Martinique", -"MR" => "Mauritania", -"MU" => "Mauritius", -"YT" => "Mayotte", -"MX" => "Mexico", -"FM" => "Micronesia, Federated States of", -"MD" => "Moldova, Republic of", -"MC" => "Monaco", -"MN" => "Mongolia", -"MS" => "Montserrat", -"MA" => "Morocco", -"MZ" => "Mozambique", -"MM" => "Myanmar", -"NA" => "Namibia", -"NR" => "Nauru", -"NP" => "Nepal", -"NL" => "Netherlands", -"AN" => "Netherlands Antilles", -"NC" => "New Caledonia", -"NZ" => "New Zealand", -"NI" => "Nicaragua", -"NE" => "Niger", -"NG" => "Nigeria", -"NU" => "Niue", -"NF" => "Norfolk Island", -"MP" => "Northern Mariana Islands", -"NO" => "Norway", -"OM" => "Oman", -"PK" => "Pakistan", -"PW" => "Palau", -"PA" => "Panama", -"PG" => "Papua New Guinea", -"PY" => "Paraguay", -"PE" => "Peru", -"PH" => "Philippines", -"PN" => "Pitcairn", -"PL" => "Poland", -"PT" => "Portugal", -"PR" => "Puerto Rico", -"QA" => "Qatar", -"RE" => "Reunion", -"RO" => "Romania", -"RU" => "Russian Federation", -"RW" => "Rwanda", -"KN" => "Saint Kitts and Nevis", -"LC" => "Saint Lucia", -"VC" => "Saint Vincent and the Grenadines", -"WS" => "Samoa", -"SM" => "San Marino", -"ST" => "Sao Tome and Principe", -"SA" => "Saudi Arabia", -"SN" => "Senegal", -"CS" => "Serbia and Montenegro", -"SC" => "Seychelles", -"SL" => "Sierra Leone", -"SG" => "Singapore", -"SK" => "Slovakia (Slovak Republic)", -"SI" => "Slovenia", -"SB" => "Solomon Islands", -"SO" => "Somalia", -"ZA" => "South Africa", -"ES" => "Spain", -"LK" => "Sri Lanka", -"SH" => "St. Helena", -"PM" => "St. Pierre and Miquelon", -"SD" => "Sudan", -"SR" => "Suriname", -"SJ" => "Svalbard and Jan Mayen Islands", -"SZ" => "Swaziland", -"SE" => "Sweden", -"CH" => "Switzerland", -"SY" => "Syrian Arab Republic", -"TW" => "Taiwan", -"TJ" => "Tajikistan", -"TZ" => "Tanzania, United Republic of", -"TH" => "Thailand", -"TG" => "Togo", -"TK" => "Tokelau", -"TO" => "Tonga", -"TT" => "Trinidad and Tobago", -"TN" => "Tunisia", -"TR" => "Turkey", -"TM" => "Turkmenistan", -"TC" => "Turks and Caicos Islands", -"TV" => "Tuvalu", -"UG" => "Uganda", -"UA" => "Ukraine", -"AE" => "United Arab Emirates", -"GB" => "United Kingdom", -"US" => "United States of America", -"UY" => "Uruguay", -"UZ" => "Uzbekistan", -"VU" => "Vanuatu", -"VA" => "Vatican City State (Holy See)", -"VE" => "Venezuela", -"VN" => "Vietnam", -"VG" => "Virgin Islands (British)", -"VI" => "Virgin Islands (U.S.)", -"WA" => "Wales", -"WF" => "Wallis And Futuna Islands", -"EH" => "Western Sahara", -"YE" => "Yemen", -"ZR" => "Zaire", -"ZM" => "Zambia", -"ZW" => "Zimbabwe"); - diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 66e65c2e79..e5d29bb988 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1284,6 +1284,23 @@ function get_list_of_languages() { return $languages; } +function get_list_of_countries() { +/// Returns a list of country names in the current language + global $CFG, $USER; + + $lang = current_language(); + + if (!file_exists("$CFG->dirroot/lang/$lang/countries.php")) { + $lang = "en"; // countries.php must exist in this pack + } + + include("$CFG->dirroot/lang/$lang/countries.php"); + + asort($string); + + return $string; +} + function document_file($file, $include=true) { /// Can include a given document file (depends on second /// parameter) or just return info about it diff --git a/login/signup.php b/login/signup.php index 26a15d486b..3721c8b3dd 100644 --- a/login/signup.php +++ b/login/signup.php @@ -1,7 +1,6 @@ auth/lib.php"); if ($user = data_submitted()) { diff --git a/login/signup_form.html b/login/signup_form.html index b5f3da563a..53e7f446ef 100644 --- a/login/signup_form.html +++ b/login/signup_form.html @@ -73,7 +73,7 @@

:

- country, get_string("selectacountry"), "", "") ?> + country, get_string("selectacountry"), "", "") ?> country)) { formerr($err->country);} ?> diff --git a/user/edit.html b/user/edit.html index 44c65750a3..9fb983489a 100644 --- a/user/edit.html +++ b/user/edit.html @@ -118,7 +118,7 @@ if (isadmin()) { $user->country = $CFG->country; } - choose_from_menu ($COUNTRIES, "country", $user->country, get_string("selectacountry")."...", "", "") ?> + choose_from_menu (get_list_of_countries(), "country", $user->country, get_string("selectacountry")."...", "", "") ?> diff --git a/user/edit.php b/user/edit.php index 0bda8b761f..b9c7fbc263 100644 --- a/user/edit.php +++ b/user/edit.php @@ -1,7 +1,6 @@ sec = get_string("sec"); $string->secs = get_string("secs"); + $countries = get_list_of_countries(); + $loggedinas = "

".user_login_string($course, $USER)."

"; $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc"); @@ -65,7 +66,7 @@ echo "

$course->teachers

"; foreach ($teachers as $teacher) { if ($teacher->authority > 0) { // Don't print teachers with no authority - print_user($teacher, $course, $string); + print_user($teacher, $course, $string, $countries); } } } @@ -87,7 +88,7 @@ if ($students = get_course_students($course->id, $dsort, $dir)) { foreach ($students as $student) { - print_user($student, $course, $string); + print_user($student, $course, $string, $countries); } } @@ -121,7 +122,7 @@ } foreach ($students as $key => $student) { - $students[$key]->country = $COUNTRIES[$student->country]; + $students[$key]->country = $countries[$student->country]; } if ($sort == "country") { // Need to re-sort by full country name, not code foreach ($students as $student) { diff --git a/user/lib.php b/user/lib.php index 4f54d4b4af..de31c6c7d4 100644 --- a/user/lib.php +++ b/user/lib.php @@ -170,9 +170,9 @@ function save_user_image($userid, $filename) { } -function print_user($user, $course, $string) { +function print_user($user, $course, $string, $countries) { - global $USER, $COUNTRIES; + global $USER; echo "
"; echo ""; @@ -189,7 +189,7 @@ function print_user($user, $course, $string) { if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category) or isteacher($course->id)) { echo "$string->email: email\">$user->email
"; } - echo "$string->location: $user->city, ".$COUNTRIES["$user->country"]."
"; + echo "$string->location: $user->city, ".$countries["$user->country"]."
"; if ($user->lastaccess) { echo "$string->lastaccess: ".userdate($user->lastaccess); echo "  (".format_time(time() - $user->lastaccess, $string).")"; diff --git a/user/view.php b/user/view.php index 23a201136e..488b725ebe 100644 --- a/user/view.php +++ b/user/view.php @@ -3,7 +3,6 @@ // Display profile for a particular user require_once("../config.php"); - require_once("../lib/countries.php"); require_once("../mod/forum/lib.php"); require_once("lib.php"); @@ -23,6 +22,8 @@ require_login($course->id); } + $countries = get_list_of_countries(); + add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id"); $fullname = "$user->firstname $user->lastname"; @@ -86,13 +87,12 @@ echo "

".text_to_html($user->description)."


"; } - // Print all the little details in a list echo "
city or $user->country) { - print_row(get_string("location").":", "$user->city, ".$COUNTRIES["$user->country"]); + print_row(get_string("location").":", "$user->city, ".$countries["$user->country"]); } if (isteacher($course->id)) { -- 2.39.5