diff --git a/src/Pluf/L10n.php b/src/Pluf/L10n.php index 51edb70..daf9b6e 100644 --- a/src/Pluf/L10n.php +++ b/src/Pluf/L10n.php @@ -383,4 +383,202 @@ class Pluf_L10n return $res; } + /** + * Returns iso codes. + * + * @param bool Is the language the key in the array (false) + * @return array The key is either the language or the iso code + */ + public static function getNativeLanguages($lang=false) + { + $res = array( + 'ab' => 'Аҧсуа', + 'aa' => 'Afaraf', + 'af' => 'Afrikaans', + 'ak' => 'Akan', + 'am' => 'አማርኛ', + 'ar' => 'العربية', + 'an' => 'Aragonés', + 'as' => 'অসমীয়া', + 'av' => 'авар мацӀ', + 'ae' => 'avesta', + 'ay' => 'aymar aru', + 'az' => 'Azərbaycanca', + 'bm' => 'bamanankan', + 'ba' => 'башҡорт теле', + 'be' => 'Беларуская мова', + 'bn' => 'বাংলা', + 'bh' => 'Bihari', + 'bi' => 'Bislama', + 'bs' => 'bosanski jezik', + 'br' => 'brezhoneg', + 'bg' => 'български език', + 'ca' => 'català', + 'ch' => 'Chamoru', + 'ce' => 'нохчийн мотт', + 'ny' => 'chiCheŵa', + 'cu' => 'чӑваш чӗлхи', + 'kw' => 'Kernewek', + 'co' => 'corsu', + 'cr' => 'ᓀᐦᐃᔭᐍᐏᐣ', + 'hr' => 'hrvatski jezik', + 'cs' => 'čeština', + 'da' => 'dansk', + 'dv' => 'ދިވެހިބަސ', + 'dz' => 'རྫོང་ཁ', + 'en' => 'English', + 'eo' => 'Esperanto', + 'et' => 'eesti keel', + 'ee' => 'Ɛʋɛgbɛ', + 'fo' => 'føroyskt', + 'fj' => 'vosa Vakaviti', + 'fi' => 'suomi', + 'fr' => 'français', + 'fy' => 'frysk', + 'ff' => 'Fulfulde, Pulaar, Pular', + 'gl' => 'Galego', + 'lg' => 'Luganda', + 'ka' => 'ქართული ენა', + 'de' => 'Deutsch', + 'el' => 'Ελληνικά', + 'kl' => 'kalaallisut', + 'gn' => 'Avañe\'ẽ', + 'gu' => 'ગુજરાતી', + 'ht' => 'Kreyòl ayisyen', + 'ha' => 'Hausancī', + 'he' => 'עִבְרִית', + 'hz' => 'Otjiherero', + 'hi' => 'हिन्दी', + 'ho' => 'Hiri Motu', + 'hu' => 'magyar', + 'is' => 'íslenska', + 'io' => 'Ido', + 'ig' => 'Igbo', + 'id' => 'Bahasa Indonesia', + 'ia' => 'interlingua', + 'ie' => 'Interlingue', + 'iu' => 'ᐃᓄᒃᑎᑐᑦ', + 'ik' => 'Iñupiaq', + 'ga' => 'Gaeilge', + 'it' => 'italiano', + 'ja' => '日本語 (にほんご)', + 'jv' => 'basa Jawa', + 'kn' => 'ಕನ್ನಡ', + 'kr' => 'कॉशुर', + 'kk' => 'Қазақ тілі', + 'km' => 'Central Khmer', + 'ki' => 'Gĩkũyũ', + 'rw' => 'kinyaRwanda', + 'ky' => 'кыргыз тили', + 'kv' => 'коми кыв', + 'kg' => 'Kikongo', + 'ko' => '한국어 (韓國語)', + 'kj' => 'Kurdish', + 'lo' => 'ພາສາລາວ', + 'la' => 'latine', + 'lv' => 'latviešu valoda', + 'li' => 'Limburgs', + 'ln' => 'lingala', + 'lt' => 'lietuvių kalba', + 'lu' => 'Luxembourgish', + 'mg' => 'Malagasy fiteny', + 'ms' => 'bahasa Melayu', + 'ml' => 'മലയാളം', + 'mt' => 'Malti', + 'gv' => 'Gaelg', + 'mi' => 'te reo Māori', + 'mr' => 'मराठी', + 'mh' => 'Kajin M̧ajeļ', + 'mn' => 'монгол хэл', + 'na' => 'Ekakairũ Naoero', + 'nv' => 'Diné bizaad', + 'nd' => 'isiNdebele', + 'nr' => 'isiNdebele', + 'ng' => 'Owambo', + 'ne' => 'नेपाली', + 'se' => 'sámi', + 'no' => 'Norsk', + 'nb' => 'Norsk bokmål', + 'nn' => 'Norsk nynorsk', + 'oc' => 'Occitan', + 'oj' => 'ᐊᓂᔑᓇᐯᒧᐏᐣ (Anishinaabemowin)', + 'or' => 'ଓଡ଼ିଆ', + 'om' => 'Afaan Oromoo', + 'os' => 'ирон ӕвзаг', + 'pi' => 'पालि', + 'fa' => 'فارسی', + 'pl' => 'polski', + 'pt' => 'português', + 'pa' => 'ਪੰਜਾਬੀ', + 'ps' => 'پښتو', + 'qu' => 'Runa Simi', + 'rm' => 'rumantsch grischun', + 'rn' => 'kiRundi', + 'ru' => 'русский язык', + 'sm' => 'gagana fa\'a Samoa', + 'sg' => 'yângâ tî sängö', + 'sa' => 'संस्कृतम्', + 'sc' => 'sardu', + 'gd' => 'Gàidhlig', + 'sr' => 'српски језик', + 'sn' => 'chiShona', + 'ii' => 'ꆇꉙ', + 'sd' => 'سنڌي، سندھی', + 'si' => 'සිංහල', + 'sk' => 'slovenčina', + 'sl' => 'slovenščina', + 'so' => 'Soomaaliga', + 'st' => 'Sesotho', + 'es' => 'español', + 'su' => 'basa Sunda', + 'sw' => 'kiswahili', + 'ss' => 'siSwati', + 'sv' => 'Svenska', + 'tl' => 'Tagalog', + 'ty' => 'te reo Tahiti', + 'tg' => 'тоҷикӣ', + 'ta' => 'தமிழ்', + 'tt' => 'татарча', + 'te' => 'తెలుగు', + 'th' => 'ภาษาไทย', + 'bo' => 'བོད་ཡིག', + 'ti' => 'ትግርኛ', + 'to' => 'faka-Tonga', + 'ts' => 'Xitsonga', + 'tn' => 'Setswana', + 'tr' => 'Türkçe', + 'tk' => 'Түркмен', + 'tw' => 'Twi', + 'ug' => 'Uyƣurqə', + 'uk' => 'українська мова', + 'ur' => 'اردو', + 'uz' => 'O\'zbek', + 've' => 'Tshivenḓa', + 'vi' => 'Tiếng Việt', + 'vo' => 'Volapük', + 'wa' => 'walon', + 'cy' => 'Cymraeg', + 'wo' => 'Wolof', + 'xh' => 'isiXhosa', + 'yi' => 'ייִדיש', + 'yo' => 'Yorùbá', + 'za' => 'Saɯ cueŋƅ', + 'zu' => 'isiZulu', + ); + if ($lang) { + $res = array_flip($res); + ksort($res); //order by lang + } + return $res; + } + + public static function getInstalledLanguages() + { + $l = array(); + $nl = self::getNativeLanguages(); + foreach (Pluf::f('languages', array('en')) as $lang) { + $l[$nl[$lang]] = $lang; + } + return $l; + } } diff --git a/src/Pluf/Middleware/Session.php b/src/Pluf/Middleware/Session.php index c0337c7..b831f4c 100644 --- a/src/Pluf/Middleware/Session.php +++ b/src/Pluf/Middleware/Session.php @@ -67,6 +67,7 @@ class Pluf_Middleware_Session } return false; } + $set_lang = false; if (isset($data[$user->session_key])) { // We can get the corresponding user $found_user = new Pluf_User($data[$user->session_key]); @@ -80,6 +81,7 @@ class Pluf_Middleware_Session $request->user->last_login = gmdate('Y-m-d H:i:s'); $request->user->update(); } + $set_lang = $found_user->language; } else { $request->user = $user; } @@ -97,6 +99,9 @@ class Pluf_Middleware_Session } else { $request->session = $session; } + if ($set_lang) { + $request->session->setData('pluf_language', $set_lang); + } if (isset($request->COOKIE[$request->session->test_cookie_name])) { $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name]; }