atoulme | 425b6c8 | 2008-11-24 14:00:27 +0000 | [diff] [blame] | 1 | <?php |
| 2 | /******************************************************************************* |
| 3 | * Copyright (c) 2007-2008 Eclipse Foundation and others. |
| 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Antoine Toulme, Intalio Inc. bug 248845: Refactoring generate1.php into different files with a functional approach |
kitlo | 8665119 | 2009-01-22 04:28:19 +0000 | [diff] [blame] | 11 | * Kit Lo (IBM) - patch, bug 261739, Inconsistent use of language names |
kitlo | f237f0e | 2009-03-14 02:12:56 +0000 | [diff] [blame] | 12 | * Kit Lo (IBM) - Beautify Babel Supported Languages table |
atoulme | 425b6c8 | 2008-11-24 14:00:27 +0000 | [diff] [blame] | 13 | *******************************************************************************/ |
| 14 | |
| 15 | class Language { |
| 16 | |
| 17 | public $name = ''; |
| 18 | public $iso = ''; |
| 19 | public $locale = ''; |
| 20 | public $id = ''; |
| 21 | |
| 22 | /** |
| 23 | * Default constructor |
| 24 | */ |
| 25 | function Language($name = '', $iso= '', $locale = '', $id = '') { |
| 26 | $this->name = $name; |
| 27 | $this->iso = $iso; |
| 28 | $this->locale = $locale; |
| 29 | $this->id = $id; |
| 30 | |
| 31 | if (strcmp($iso, "en") == 0) { |
| 32 | $this->iso = "en_AA"; |
| 33 | $this->name = "Pseudo Translations"; |
| 34 | } |
| 35 | |
| 36 | if ($locale != null) { |
kitlo | 8665119 | 2009-01-22 04:28:19 +0000 | [diff] [blame] | 37 | $this->name = $this->name . " (" . $this->locale . ")"; |
atoulme | 425b6c8 | 2008-11-24 14:00:27 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * A constructor expecting an associative array as its unique parameter |
| 43 | */ |
atoulme | 589b1ec | 2008-11-24 15:23:01 +0000 | [diff] [blame] | 44 | static function fromRow($row) { |
atoulme | f84e875 | 2008-11-24 15:24:59 +0000 | [diff] [blame] | 45 | return new Language($row['name'], $row['iso_code'], $row['locale'], $row['language_id']); |
atoulme | 425b6c8 | 2008-11-24 14:00:27 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static function all() { |
| 49 | $langs = array(); |
Denis Roy | 7f62f6f | 2019-11-13 15:35:26 -0500 | [diff] [blame] | 50 | global $dbh; |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 51 | $language_result = mysqli_query($dbh, "SELECT * FROM languages WHERE languages.is_active ORDER BY name, locale"); |
| 52 | while (($language_row = mysqli_fetch_assoc($language_result)) != null) { |
atoulme | f84e875 | 2008-11-24 15:24:59 +0000 | [diff] [blame] | 53 | $langs[] = Language::fromRow($language_row); |
atoulme | 425b6c8 | 2008-11-24 14:00:27 +0000 | [diff] [blame] | 54 | } |
| 55 | return $langs; |
| 56 | } |
| 57 | } |