Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv21567 Modified Files: index.php phpweather.php Log Message: It should now be possible to get a list of languages automatically. The translation of language codes to language names is done via PHPWEATHER_BASE_DIR/locales/languages.php. You use the function get_languages() to retrieve the list of languages. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/index.php,v retrieving revision 1.13 retrieving revision 1.14 diff -u -3 -r1.13 -r1.14 --- index.php 2001/06/29 09:43:16 1.13 +++ index.php 2001/06/29 11:51:40 1.14 @@ -61,10 +61,32 @@ } elseif ($action == 'show_weather') { /* A station has just been selected - we print the weather. */ + if (empty($language)) { + $language = 'en'; + } $obj->set_icao($icao); + $obj->set_language($language); + + echo "<p>This is the current weather in " . $obj->get_location() . ":</p>\n"; + $obj->print_pretty(); echo "<p>The raw METAR is <code>" . $obj->get_metar() . "</code></p>\n"; + echo '<form action="index.php" method="post"> +<input type="hidden" name="action" value="show_weather">'; + echo "<p>Select a new language here: \n <select name=\"language\">\n"; + $languages = $obj->get_languages(); + while (list($lc, $language) = each($languages)) { + if ($lc == $obj->get_language()) { + echo "<option value=\"$lc\" selected>$language</option>\n"; + } else { + echo "<option value=\"$lc\">$language</option>\n"; + } + } + echo '</select></p> +<p><input type="submit"></p> +</form> +'; } $time[] = array(microtime(), 'end'); Index: phpweather.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- phpweather.php 2001/06/27 11:23:39 1.7 +++ phpweather.php 2001/06/29 11:51:40 1.8 @@ -50,15 +50,9 @@ require_once(PHPWEATHER_BASE_DIR . '/locales/locale_en.php'); $this->output = new locale_en($this->properties); break; - case 'da': - $this->output = new locale_da($this->properties); + case 'hu': + $this->output = new locale_hu($this->properties); break; - case 'de': - $this->output = new locale_de($this->properties); - break; - case 'fr': - $this->output = new locale_fr($this->properties); - break; default: $this->error('language not recognized: <code>' . $new_langauge . '</code> - using <code>en</code>.'); $this->set_language('en'); @@ -74,6 +68,24 @@ */ function get_language() { return $this->properties['language']; + } + + /** + * Returns a list of languages. + * + * @return array An associative array with the language codes as the keys and the +names of the languages as the values. + * @access public + */ + function get_languages() { + require(PHPWEATHER_BASE_DIR . '/locales/languages.php'); + $dir = opendir(PHPWEATHER_BASE_DIR . '/locales'); + while($file = readdir($dir)) { + if (ereg('^locale_([a-z][a-z])\.php$', $file, $regs)) { + $output[$regs[1]] = $languages[$regs[1]]; + } + } + closedir($dir); + return $output; } _______________________________________________ PHPWeather-checkins mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/phpweather-checkins