how to use php_language_detect?
First of all, let me try to paraphrase the purpose of the script.
It detects the set language and then redirects to the page you want it to go, depending on the language. If that's correct, how to I call the function? get_languages(what info?); Or what do I need to do, to actually have the script redirect me to a different page? Thanx, Meddiecap Back to top |
|||||
It's a standard php library function, you call it the same way you call anything else, it says in the comment header what the parameters are.
My advice is to learn how to do basic php programming, either via learning how to implement this script, a php include with a function call on page, or whatever else catches your fancy. We write these scripts to be useful to people, but we don't teach people how to do programming, that's just not interesting or in the scope of how to spend one's time productively. Good luck, have fun. Note the text of the GPL, by the way, a lot of people skip by this, but it's quite relevant: :: Quote :: 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.I'd add to that, nor with the implicit or explicit offer to teach people how to do basic programming... The basics aren't hard to learn, takes a few months to get the core ideas down. Back to top |
|||||
I know atleast the basics. It's just that the explenation is a bit unclear to me.
I know that it sometimes is stressfull to get questions that are so easy to answer for you that you don't even want to answer the question because the answer is so obvious to you. But it may not be to someone who's not so advanced with php as you are. Can you give an example of the value of $feature? And what can I do with $spare? So, get_languages(example). Trust me, I know (the basics of) php and how to call functions. I just don't know what value to give $feature. Thanks again, Meddiecap Back to top |
|||||
You're right in this case, because language detection only has two values for $feature, forgot to put them in the top comments.
lines 85 and 91 $feature == 'data' $feature == 'header' I'd call this a valid bug report re the comments in the script top comment header, browser detection does include the possible values in the top comments. I'll add those to correct that error, thanks. Back to top |
|||||
This bug is now fixed in 0.3.6, added possible values for $feature in top comment header, and made slightly more clear what the 'data' value actually returns, an array of arrays.
Thanks for the bug report, this script is pretty stable, and rarely gets any attention, since it basically just works, unless a new language or a missing language is noted, which is another possible bug report. Also added, because the script changes so infrequently, a changes section in top header. Back to top |
|||||
newbie - php langauage script - missing the obvious?!
i too would appreciate some help - i know a little php and this may seem obvious to others , not to me or possibly other newbies who eventually give up with it - i call the array as follows:
echo get_languages('data'); and it returns the word 'Array' to my browser, how do i actually echo out a value of this array i.e [0] [1] etc.. kind regards Marcus Back to top |
|||||
You need to read a little bit more about php before trying to run some php. These use arrays, and to print arrays, if one level: echo something[string or number]... multiple: echo something[string or number][string or number];
arrays are pretty basic to any programming, so you'll need to start learning the language to use something like this, which uses arrays extensively. There are a lot of php how-tos on the internet, just google: php array how to. Then start to practice and play with the stuff until you understand it, that's how you learn to program. Back to top |
|||||
It might look strange but I put the script into class this way:
class class_language { var $http_accept_language; function class_language($http_accept_language) { return $this->__construct(); } function __construct() { $this->http_accept_language = (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE'])) ? strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']) : '';; } function get_languages($feature, $spare = '') { //shimansky add $this-> $a_languages = $this->languages(); $index = ''; $complete = ''; $found = false; $user_languages = array(); if ($this->http_accept_language) { $languages = strtolower($this->http_accept_language); $languages = str_replace(' ', '', $languages); $languages = explode(",", $languages); foreach ($languages as $language_list) { $temp_array = array(); $temp_array[0] = substr($language_list, 0, strcspn($language_list, ';')); $temp_array[1] = substr($language_list, 0, 2); $user_languages[] = $temp_array; } for ($i = 0; $i < count($user_languages); $i++) { foreach ($a_languages as $index => $complete) { if ($index == $user_languages[$i][0]) { $user_languages[$i][2] = $complete; $user_languages[$i][3] = substr($complete, 0, strcspn($complete, ' (')); } } } } else { $user_languages[0] = array('', '', '', ''); } if ($feature == 'data') { return $user_languages; //shimansky } elseif ( $feature == 'firstindex' ) { return $user_languages[0][1]; ////////////////////////////////// } elseif ($feature == 'header') { switch ($user_languages[0][1]) { case 'en' : $location = 'english.php'; $found = true; break; case 'sp' : $location = 'spanish.php'; $found = true; break; default : break; } if ($found) { header("Location: $location"); } else { header("Location: default.php"); } } } function languages() { $a_languages = array('af' => 'Afrikaans', 'ar' => 'Arabic', 'ar-ae' => 'Arabic (U.A.E.)', 'ar-bh' => 'Arabic (Bahrain)', 'ar-dz' => 'Arabic (Algeria)', 'ar-eg' => 'Arabic (Egypt)', 'ar-iq' => 'Arabic (Iraq)', 'ar-jo' => 'Arabic (Jordan)', 'ar-kw' => 'Arabic (Kuwait)', 'ar-lb' => 'Arabic (Lebanon)', 'ar-ly' => 'Arabic (libya)', 'ar-ma' => 'Arabic (Morocco)', 'ar-om' => 'Arabic (Oman)', 'ar-qa' => 'Arabic (Qatar)', 'ar-sa' => 'Arabic (Saudi Arabia)', 'ar-sy' => 'Arabic (Syria)', 'ar-tn' => 'Arabic (Tunisia)', 'ar-ye' => 'Arabic (Yemen)', 'as' => 'Assamese', 'az' => 'Azeri', 'be' => 'Belarusian', 'bg' => 'Bulgarian', 'bn' => 'Bengali', 'ca' => 'Catalan', 'cs' => 'Czech', 'da' => 'Danish', 'de' => 'German (Germany)', 'de-at' => 'German (Austria)', 'de-ch' => 'German (Switzerland)', 'de-li' => 'German (Liechtenstein)', 'de-lu' => 'German (Luxembourg)', 'div' => 'Divehi', 'el' => 'Greek', 'en' => 'English', 'en-au' => 'English (Australia)', 'en-bz' => 'English (Belize)', 'en-ca' => 'English (Canada)', 'en-gb' => 'English (United Kingdom)', 'en-ie' => 'English (Ireland)', 'en-jm' => 'English (Jamaica)', 'en-nz' => 'English (New Zealand)', 'en-ph' => 'English (Philippines)', 'en-tt' => 'English (Trinidad)', 'en-us' => 'English (United States)', 'en-za' => 'English (South Africa)', 'en-zw' => 'English (Zimbabwe)', 'es' => 'Spanish (Traditional Sort)', 'es-ar' => 'Spanish (Argentina)', 'es-bo' => 'Spanish (Bolivia)', 'es-cl' => 'Spanish (Chile)', 'es-co' => 'Spanish (Colombia)', 'es-cr' => 'Spanish (Costa Rica)', 'es-do' => 'Spanish (Dominican Republic)', 'es-ec' => 'Spanish (Ecuador)', 'es-gt' => 'Spanish (Guatemala)', 'es-hn' => 'Spanish (Honduras)', 'es-mx' => 'Spanish (Mexico)', 'es-ni' => 'Spanish (Nicaragua)', 'es-pa' => 'Spanish (Panama)', 'es-pe' => 'Spanish (Peru)', 'es-pr' => 'Spanish (Puerto Rico)', 'es-py' => 'Spanish (Paraguay)', 'es-sv' => 'Spanish (El Salvador)', 'es-us' => 'Spanish (United States)', 'es-uy' => 'Spanish (Uruguay)', 'es-ve' => 'Spanish (Venezuela)', 'et' => 'Estonian', 'eu' => 'Basque', 'fa' => 'Farsi', 'fi' => 'Finnish', 'fo' => 'Faeroese', 'fr' => 'French (France)', 'fr-be' => 'French (Belgium)', 'fr-ca' => 'French (Canada)', 'fr-ch' => 'French (Switzerland)', 'fr-lu' => 'French (Luxembourg)', 'fr-mc' => 'French (Monaco)', 'gd' => 'Gaelic', 'gu' => 'Gujarati', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hr' => 'Croatian', 'hu' => 'Hungarian', 'hy' => 'Armenian', 'id' => 'Indonesian', 'is' => 'Icelandic', 'it' => 'Italian (Italy)', 'it-ch' => 'Italian (Switzerland)', 'ja' => 'Japanese', 'ka' => 'Georgian', 'kk' => 'Kazakh', 'kn' => 'Kannada', 'ko' => 'Korean', 'kok' => 'Konkani', 'kz' => 'Kyrgyz', 'ls' => 'Slovenian', 'lt' => 'Lithuanian', 'lv' => 'Latvian', 'mk' => 'FYRO Macedonian', 'ml' => 'Malayalam', 'mn' => 'Mongolian (Cyrillic)', 'mr' => 'Marathi', 'ms' => 'Malay', 'mt' => 'Maltese', 'nb-no' => 'Norwegian (Bokmal)', 'ne' => 'Nepali (India)', 'nl' => 'Dutch (Netherlands)', 'nl-be' => 'Dutch (Belgium)', 'nn-no' => 'Norwegian (Nynorsk)', 'no' => 'Norwegian (Bokmal)', 'or' => 'Oriya', 'pa' => 'Punjabi', 'pl' => 'Polish', 'pt' => 'Portuguese (Portugal)', 'pt-br' => 'Portuguese (Brazil)', 'rm' => 'Rhaeto-Romanic', 'ro' => 'Romanian', 'ro-md' => 'Romanian (Moldova)', 'ru' => 'Russian', 'ru-md' => 'Russian (Moldova)', 'sa' => 'Sanskrit', 'sb' => 'Sorbian', 'sk' => 'Slovak', 'sq' => 'Albanian', 'sr' => 'Serbian', 'sv' => 'Swedish', 'sv-fi' => 'Swedish (Finland)', 'sw' => 'Swahili', 'sx' => 'Sutu', 'syr' => 'Syriac', 'ta' => 'Tamil', 'te' => 'Telugu', 'th' => 'Thai', 'tn' => 'Tswana', 'tr' => 'Turkish', 'ts' => 'Tsonga', 'tt' => 'Tatar', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'us' => 'English (United States)', 'uz' => 'Uzbek', 'vi' => 'Vietnamese', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'zh' => 'Chinese', 'zh-cn' => 'Chinese (China)', 'zh-hk' => 'Chinese (Hong Kong SAR)', 'zh-mo' => 'Chinese (Macau SAR)', 'zh-sg' => 'Chinese (Singapore)', 'zh-tw' => 'Chinese (Taiwan)', 'zu' => 'Zulu'); return $a_languages; } } if (!isset ($class_language)) { $class_language = new class_language(); } So I call it like this if ($visitor_language == '') { if ($class_language->get_languages('firstindex') != '') { $class_cookies->set_cookie('privateteacher[language]', $class_language->get_languages('firstindex'), (time() + 60 * 60 * 24 * 365), '/', $vars_cookie_domain, 0); } } where $visitor_language is a cookie value Back to top |
|||||
All times are GMT - 8 Hours
|