imop Posted May 6, 2009 Share Posted May 6, 2009 Greeting to you all! I`m a real newbie at php please help... :-\ I have a problem: i don`t know how to define an image (Language flag) to display insted of text so he re is the code: language.php <?php // This is a library, that by including it, // automatically determines the proper language // to use and includes the language file. // First define an array of all possible // languages: $languages = array('lv' => 'Latviešu', 'en' => 'English', 'ru' => 'По Русски'); // Look at the GET string to see if lang is // specified: if (isset($_GET['lang'])) { // It's been specified, so set the language $lang = $_GET['lang']; // While here, send a cookie to remember this // selection for 1 year. setcookie('lang', $lang, time()+(3600*24*365)); } // Ok, otherwise look for the cookie itself: elseif (isset($_COOKIE['lang'])) { // Use this $lang = $_COOKIE['lang']; } else { // Otherwise, default to English $lang = 'lv'; } // Make sure that the language string we have is // a valid one: if (!(in_array($lang, array_keys($languages)))) { die("ERROR: Bad Language String Provided!"); } // Now include the appropriate language file: require_once "languages/{$lang}.php"; // As one last step, create a function // that can be used to output language // options to the user: function switch_language_options() { // Include a few globals that we will need: global $text, $languages, $lang; // Start our string with a language specific // 'switch' statement: // $retval = $text['switch']; // Loop through all possible languages to // create our options. $get = $_GET; foreach ($languages as $abbrv => $name) { // Create the link, ignoring the current one. if ($abbrv !== $lang) { // Recreate the GET string with // this language. $get['lang'] = $abbrv; $url = $_SERVER['PHP_SELF'] . '?' . http_build_query($get); $retval .= " <a href=\"{$url}\"> {$name}</a>"; } } // Now return this string. return $retval; } ?> I know that i need to change this part: // First define an array of all possible // languages: $languages = array('lv' => 'Latviešu', 'en' => 'English', 'ru' => 'По Русски'); This is on of my language files: lv.php <?php // Visi teksti kuri nepieciešami lapas darbībai, // Latviešu valodā. $GLOBALS['text'] = array ( 'title' => 'v0.1 LV', 'lv' => 'Latviešu' ); // Define text as image $GLOBALS['imgsrc'] = array ( 'lv' => 'img/karogi/lv.gif' ); ?> How do i insert this in to - language.php to display flags instead of text? Thx! Link to comment https://forums.phpfreaks.com/topic/157053-3-language-web-language-names-as-flags/ Share on other sites More sharing options...
suncore Posted May 6, 2009 Share Posted May 6, 2009 Multidimensional arrays ( just an example ) : <?php $languages = array("lv" => array("alias" => "Latviešu", "image" => "images/flag-lv.gif")); echo "Text: " . $languages['lv']['alias'] . "<br>"; echo "Image: " . $languages['lv']['image'] . "<br>"; ?> Link to comment https://forums.phpfreaks.com/topic/157053-3-language-web-language-names-as-flags/#findComment-827341 Share on other sites More sharing options...
imop Posted May 6, 2009 Author Share Posted May 6, 2009 That means i need to define array to all languages i have? I tried do put the script, you wrote, in language.php, but this is not working also for images i`m confused I think it wont be the case... $languages = array('lv' => 'Latviešu', 'en' => 'English', 'ru' => 'Russian'); Because the $language give the language name down to next step of script who is responsable for LINK on language switcher: // As one last step, create a function // that can be used to output language // options to the user: function switch_language_options() { // Include a few globals that we will need: global $text, $languages, $lang; // Start our string with a language specific // 'switch' statement: // $retval = $text['switch']; // Loop through all possible languages to // create our options. $get = $_GET; foreach ($languages as $abbrv => $name) { // Create the link, ignoring the current one. if ($abbrv !== $lang) { // Recreate the GET string with // this language. $get['lang'] = $abbrv; $url = $_SERVER['PHP_SELF'] . '?' . http_build_query($get); $retval .= " <a href=\"{$url}\"> {$name}</a>"; } } // Now return this string. return $retval; } Link to comment https://forums.phpfreaks.com/topic/157053-3-language-web-language-names-as-flags/#findComment-827365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.