Update of /cvsroot/phpweather/phpweather/locales
In directory usw-pr-cvs1:/tmp/cvs-serv27785

Added Files:
        locale_common.php locale_en.php 
Log Message:
All locale-related files should now be stored here.


--- NEW FILE ---
<?php
/**
 * Provides all the function needed to generate (English) output.
 *
 * This class has the capability to do a pretty-print, if it is provided with the 
right set of strings. It's up to child-classes to provide these strings, and override 
the methods in this class, as necessary. The logic in the pretty-print is built around 
the English output, but it should still be possible to make a good translation, by 
just translating the strings.
 *
 * @author   Martin Geisler <[EMAIL PROTECTED]>
 * @version  $Id: locale_common.php,v 1.1 2001/06/27 11:27:27 gimpster Exp $
 */
class locale_common extends base_object {

  /**
   * The strings used in the translation is stored here.
   *
   * Each string is identified by it's key in the array. Some strings are used between 
the dynamic parts, and others are used as format-strings to sprintf().
   *
   * @var  array  $strings
   */
  var $strings = array();

  /**
   * Constructor.
   *
   * @param   array  The initial properties of the object. If you omit some 
properties, the defaults will kick-in.
   * @access  public
   */
  function locale_common($input) {
    /* We call the parent constructor. */
    $this->base_object($input);

  }

  /**
   * Sets the marks (the strings inserted before and after every number)
   *
   * @param   string  The mark used before numbers and other data elements, for 
example '<font color="red">'
   * @param   string  The mark used after numbers and other data elements, for example 
'</font>'. If you use HTML tags, it's your responsibility to ensure that they match 
up. If they don't, then you pages might not render properly.
   * @access  public
   * @see     get_marks()
   */
  function set_marks($new_mark_begin, $new_mark_end) {
    $this->properties['mark_begin'] = $new_mark_begin;
    $this->properties['mark_end'] = $new_mark_end;
  }
  
  /**
   * Gets the marks
   *
   * @return    array   The first element is the string is inserted before any number, 
and the second element is the string inserted after. The first element is also know as 
'mark_begin' and the second as 'mark_end'.
   * @access    public
   * @see       set_marks()
   */
  function get_marks() {
    return array($this->properties['mark_begin'], $this->properties['mark_end']);
  }
  
  /**
   * Specifies which kind of units to display.
   *
   * $new_pref_units can be one of the following strings:
   * - 'both_metric' if one wants to produce output like this '10 kilometers (16.1 
miles)'
   * - 'both_imperial' if one wants to produce output like this '16.1 miles (10 
kilometers)'
   * - 'only_metric' if one wants to produce output like this '10 kilometers'
   * - 'only_imperial' if one wants to produce output like this '16.1 miles'
   * If $new_pref_units isn't recognized, 'both_imperial' will be used instead.
   *
   * @param   string  The new kind of units one wants to use.
   * @access  public
   * @see     get_pref_units()
   */
  function set_pref_units($new_pref_units) {
    switch ($new_pref_units) {
    case 'both_metric':
    case 'both_imperial':
    case 'only_metric':
    case 'only_imperial':
      $this->properties['pref_units'] = $new_pref_units;
      break;
    default:
      $this->properties['pref_units'] = 'both_imperial';
      $this->error('argument to pref_units() not recognized: <code>' . $new_pref_units 
. '</code>, using <code>both_imperial</code> instead.');
      break;
    }
  }

  
  /**
   * Gets the preferred units.
   *
   * @return  string  The preferred kind of units. This will be one of 'both_metric', 
'both_imperial', 'only_metric' or 'only_imperial'.
   * @access  public
   * @see     set_pref_units()
   */
  function get_pref_units() {
    return $this->properties['pref_units'];
  }


  /**
   * Used to specify which elements one wants to exclude from the pretty-print.
   *
   * @param   array  The array should contain the names of the sections one doesn't 
want to have displayed, like 'wind' or 'time' if one wants to skip the wind or time 
parts of the pretty-print.
   * @access  public
   * @see     get_exclude()
   */
  function set_exclude($new_exclude) {
    if (is_array($new_exclude)) {
      $this->properties['exclude'] = $new_exclude;
    } else {
      $this->error("argument to set_exclude() is not an array: $new_exclude");
    }
  }

  /**
   * Gets the array of excluded elements of the pretty-print.
   *
   * @return  array   The excluded elements.
   * @access  public
   * @see     set_exclude()
   */
  function get_exclude() {
    return $this->properties['exclude'];
  }


  /**
   * Used to format strings with regard to the preferred units.
   *
   * If 'pref_units' isn't recognized, the function will set it to 'both_imperial', 
and try again. 
   *
   * @param   string  This string should always contain the metric value.
   * @param   string  This string should always contain the imperial value.
   * @return  string  The two arguments in the correct order with regard to the 
preferred units.
   * @see     set_pref_units()
   * @access  private
   */
  function pref_units($str1, $str2) {
    switch ($this->properties['pref_units']) {
    case 'both_metric':
      return "$str1 ($str2)";
      break;
    case 'both_imperial':
      return "$str2 ($str1)";
      break;
    case 'only_metric':
      return $str1;
      break;
      case 'only_imperial';
      return $str2;
      break;
    default:
      $this->error('<code>pref_units</code> not recognized: ' .
                   $this->properties['pref_units']);
      $this->set_pref_units('both_imperial');
      return $this->pref_units($str1, $str2);
      break;
    }
  }
  
  
  /**
   * Builds sentences from smaller bits.
   *
   * Takes an arbitrary number of strings as its arguments, and returns them with 
commas between. The strings used between the arguments, are controlled by these 
variables:
   * - $strings['list_sentences_and']
   * - $strings['list_sentences_comma']
   * - $strings['list_sentences_final_and']
   * Only non-empty arguments are used, so it's safe to call this function with empty 
strings. But if you try to call it with uninitialized variables, then PHP might warn 
you about it anyway.
   *
   * @access  private
   * @return  string  The arguments put together.
   */
  function list_sentences () {
    $num_args = func_num_args();
    
    if ($num_args == 0) {
      /* No arg, return */
      return;
    }
    
    $args      = func_get_args();
    $real_args = array();
    
    while (list($i, $val) = each($args)) {
      if (!empty($val)) {
        $real_args[] = $val;
      }
    }
    
    $num_real_args = count($real_args);
    if ($num_real_args == 0) {
      return;
    } elseif ($num_real_args == 1) {
      return $real_args[0];
    } elseif ($num_real_args == 2) {
      return $real_args[0] . $this->strings['list_sentences_and'] . $real_args[1];
    } else {
      $output = $real_args[0];
      
      for ($i = 1; $i < $num_real_args - 1; $i++) {
        $output .= $this->strings['list_sentences_comma']. $real_args[$i];
      }
      $output .= $this->strings['list_sentences_final_and'] . $real_args[$i];
      return $output;
    }
  }
  
  
  /**
   * Used to parse precipitation.
   *
   * @param   integer  The amount of precipitation measured in inches.
   * @param   integer  The amount of precipitation measured in millimeters.
   * @access  private
   * @return  string   A formatted string with information about the precipitation.
   */
  function parse_precip($in, $mm) {
    
    if (!empty($in)) {
      if ($in < 0) {
        $amount = $this->properties['mark_begin'] .
          $this->strings['precip_a_trace' ] .
          $this->properties['mark_end'];
      } else {
        $amount = $this->pref_units($this->properties['mark_begin'] . $mm .
                                    $this->properties['mark_end'] . 
$this->strings['mm'],
                                    $this->properties['mark_begin'] . $in .
                                    $this->properties['mark_end'] . 
$this->strings['inches']);
      }
      return $amount;
    }
  }
  
  
  /**
   * Function used to parse a cloud-group.
   *
   * @param    array   the cloud-group to be parsed. This should be a group as 
parse_metar() would return it.
   * @return   string  the string used in the pretty-print.
   * @access   private
   */
  function parse_cloud_group($cloud_group) {
    if (empty($cloud_group) || !is_array($cloud_group)) {
      return;
    }
    
    extract($cloud_group);
    
    if (isset($prefix) && $prefix == -1) {
      $prefix = $this->strings['less_than'];
    } else {
      $prefix = '';
    }
    
    if ($condition == 'OVC') {
      $output = sprintf($this->strings['cloud_overcast'],
                        $this->properties['mark_begin'],
                        $this->properties['mark_end']) .
        $this->pref_units($this->properties['mark_begin'] . $meter .
                          $this->properties['mark_end'] . $this->strings['meter'],
                          $this->properties['mark_begin'] . $ft .
                          $this->properties['mark_end'] . $this->strings['feet']);
    } elseif ($condition == 'VV') {
      $output = sprintf($this->strings['cloud_vertical_visibility'],
                        $this->properties['mark_begin'],
                        $this->properties['mark_end']) .
        $this->pref_units($this->properties['mark_begin'] . $meter .
                          $this->properties['mark_end'] . $this->strings['meter'],
                          $this->properties['mark_begin'] . $ft .
                          $this->properties['mark_end'] . $this->strings['feet']);
    } elseif($condition == 'CAVOK') {
      $output = sprintf($this->strings['cavok'],
                        $this->pref_units($this->properties['mark_begin'] .
                                          '1524' .
                                          $this->properties['mark_end'] .
                                          $this->strings['meter'],
                                          $this->properties['mark_begin'] .
                                          '5000' .
                                          $this->properties['mark_end'] .
                                          $this->strings['feet']));
    } else {   
      if (empty($cumulus)) {
        $cumulus = '';
      } elseif ($cumulus == 'CB') {
        $cumulus = $this->strings['cumulonimbus'];
      } elseif ($cumulus == 'TCU') {
        $cumulus = $this->strings['towering_cumulus'];
      } else {
        $cumulus = '';
        $this->error("\$cumulus not recognized: $cumulus");
      }
      
      $output = $this->properties['mark_begin'] . 
$this->strings['cloud_condition'][$condition] . 
        $cumulus . $this->properties['mark_end'] . $this->strings['cloud_height'] .
        $this->pref_units($this->properties['mark_begin'] . $meter .
                          $this->properties['mark_end'] . $this->strings['meter'],
                          $this->properties['mark_begin'] . $ft .
                          $this->properties['mark_end'] . $this->strings['feet']);
      
    }
    return $output;
  }
  
  
  
  /**
   * Function used to parse a weather-group.
   *
   * @param   array   the weather-group to be parsed.
   * @return  string  the string used in the pretty-print.
   * @access  private
   */
  function parse_weather_group($weather_group) {
    if (empty($weather_group)) {
      return;
    }
    
    $output = '';    
    if (!empty($weather_group['intensity'])) {
      $output .= $this->strings['weather'][$weather_group['intensity']];
    }
    if (!empty($weather_group['prefix'])) {
      $output .= $this->strings['weather'][$weather_group['prefix']];
    }
    if (!empty($weather_group['weather'])) {
      $output .= $this->strings['weather'][$weather_group['weather']];
    }
    return $output;
  }
  
  
  /**
   * Function used to parse the tendency in a runway-group.
   *
   * @param   string  the tendency
   * @return  string  the string used in the pretty-print.
   * @access  private
   */
  function runway_tendency($tendency) {
    if (empty($tendency)) {
      return;
    } elseif ($tendency == 'U') {
      return sprintf($this->strings['runway_upward_tendency'],
                     $this->properties['mark_begin'],
                     $this->properties['mark_end']);
    } elseif ($tendency == 'D') {
      return sprintf($this->strings['runway_downward_tendency'],
                     $this->properties['mark_begin'],
                     $this->properties['mark_end']);
    } elseif ($tendency == 'N') {
      return sprintf($this->strings['runway_no_tendency'],
                     $this->properties['mark_begin'],
                     $this->properties['mark_end']);
    } else {
     $this->error("\$tendency is out of range: '$tendency'");
     return;
    }
  }
  
  /**
   * Function used to parse a runway-group.
   *
   * @param   array   the runway-group to be parsed.
   * @return  string  the string used in the pretty-print.
   * @access  private
   */
  function parse_runway_group($runway_group) {
    if (empty($runway_group) || !is_array($runway_group)) {
      return;
    }
    
    extract($runway_group);
    
    if (empty($approach)) {
      $approach = '';
    } elseif ($approach == 'L') {
      $approach = $this->strings['runway_left'];
    } elseif ($approach == 'C') {
      $approach = $this->strings['runway_central'];
    } elseif ($approach == 'R') {
      $approach = $this->strings['runway_right'];
    } else {
      $approach = '';
      $this->error("parse_runway_group(): \$approach not recognized: $approach"); 
    }
    
    if (!empty($min_meter)) {
      
      if (!empty($min_tendency)) {
        $min_tendency_str = $this->runway_tendency($min_tendency);
      } else {
        $min_tendency_str = '';
      }
    
      if (!empty($max_tendency)) {
        $max_tendency_str = $this->runway_tendency($max_tendency);
      } else {
        $max_tendency_str = '';
      }
      
    $output = $this->strings['runway_between'] .
      $this->pref_units($this->properties['mark_begin'] . $min_meter .
                        $this->properties['mark_end'] . $this->strings['meters'],
                        $this->properties['mark_begin'] . $min_ft .
                        $this->properties['mark_end'] . $this->strings['feet']) . 
      $min_tendency_str . $this->strings['and'] .  
      $this->pref_units($this->properties['mark_begin'] . $max_meter .
                        $this->properties['mark_end'] . $this->strings['meters'],
                        $this->properties['mark_begin'] . $max_ft .
                        $this->properties['mark_end'] . $this->strings['feet']) .
      $max_tendency_str . $this->strings['runway_for_runway'] . 
      $this->properties['mark_begin'] . $nr . $approach . 
$this->properties['mark_end'];
  } else {
    
      $tendency = $this->runway_tendency($tendency);
      
      $output = $this->pref_units($this->properties['mark_begin'] . $meter .
                                  $this->properties['mark_end'] . 
$this->strings['meters'],
                                  $this->properties['mark_begin'] . $ft .
                                  $this->properties['mark_end'] . 
$this->strings['feet']) .
        $tendency . $this->strings['runway_for_runway'] .
        $this->properties['mark_begin'] . $nr . $approach .  
$this->properties['mark_end'];
    }
    return $output;
  }
  
  
  

  /**
   * Function used to parse a visibility-group.
   *
   * @param   array    the visibility-group to be parsed.
   * @return  string   the string used in the pretty-print.
   * @access  private
   */
  function parse_visibility_group($visibility_group) {
    if (empty($visibility_group) || !is_array($visibility_group)) {
      return;
   }
    
    extract($visibility_group);
    
    if (empty($prefix)) {
      $prefix = '';
    } elseif ($prefix == -1) {
      $prefix = $this->strings['visibility_less_than'];
    } elseif ($prefix == 1) {
      $prefix = $this->strings['visibility_greater_than'];
    } else {
      $prefix = '';
      error("\$prefix is out of range: $prefix!");
    }
    
    if ($meter < 5000) {
      $metric   = $meter;
      $me_unit  = $this->strings['meter'];
      $imperial = $ft;
      $im_unit  = $this->strings['feet'];
    } else {
      $metric   = $km;
      $me_unit  = $this->strings['kilometers'];
      $imperial = $miles;
      $im_unit  = $this->strings['miles'];
    }
    
    if (empty($dir)) {
      $output = $prefix . 
        $this->pref_units($this->properties['mark_begin'] . $metric .
                          $this->properties['mark_end'] . $me_unit,
                          $this->properties['mark_begin'] . $imperial .
                          $this->properties['mark_end'] . $im_unit);
    } else {
      
      $output = $prefix .
        $this->pref_units($this->properties['mark_begin'] . $metric .
                          $this->properties['mark_end'] . $me_unit,
                          $this->properties['mark_begin'] . $imperial .
                          $this->properties['mark_end'] . $im_unit) .
        $this->strings['to'] . $this->properties['mark_begin'] .
        $this->strings[$dir] . $this->properties['mark_end'];
    }
    return $output;
  }
  
  
  
  /**
   * The pretty-print function.
   *
   * This is the function responsible for making the weather-report, also know as the 
'pretty-print'.
   *
   * @param   array   data taken from decode_metar()
   * @return  string  The pretty-printed output.
   * @access  public
   */
  function print_pretty($data) {
    
    if (empty($data['metar'])) {
      /* We don't want to display all sorts of silly things if the
         metar is empty. */
      printf($this->strings['no_data'],
             $this->properties['mark_begin'],
             $data['location'],
             $this->properties['mark_end']);
      return 1;
    }

    
    extract($data);
    
    /* Location. */
    if (!in_array('location', $this->properties['exclude'])) {
      $output['location'] = sprintf($this->strings['location'],
                                    $this->properties['mark_begin'],
                                    $location,
                                    $this->properties['mark_end']);
    }
    
    
    /*********************
     *   Time and date   *
     *********************/
    if (!in_array('time', $this->properties['exclude'])) {
      $minutes_old = round((time() - $time)/60);
      if ($minutes_old > 60) {
        $hours   = round((time() - $time)/3600);
        $minutes = $minutes_old % 60;
        if ($minutes < 1) {
          $minutes = '';
        } else {
          $minutes = sprintf($this->strings['time_minutes'],
                             $this->properties['mark_begin'],
                             $minutes,
                             $this->properties['mark_end']);
        }
        if ($hours == 1) {
        $time_ago = sprintf($this->strings['time_one_hour'],
                            $this->properties['mark_begin'],
                            $this->properties['mark_end'],
                            $minutes);
      } else {
        $time_ago = sprintf($this->strings['time_several_hours'],
                            $this->properties['mark_begin'],
                            $hours,
                            $this->properties['mark_end'],
                            $minutes);
      }
    } else {
      if ($minutes_old < 5) {
        $time_ago = $this->properties['mark_begin'] . $this->strings['time_a_moment'] 
. $this->properties['mark_end'];
      } else {
        $time_ago = $this->properties['mark_begin'] . $minutes_old .
          $this->properties['mark_end'] . $this->strings['minutes'];
      }
    }
    $gmtime = gmdate('H:i', $time);
    $output['time'] = sprintf($this->strings['time_format'],
                              $time_ago,
                              $this->properties['mark_begin'],
                              $gmtime,
                              $this->properties['mark_end']);
  }
  
  
  /*********************
   *   Wind and gust   *
   *********************/
  if (!in_array('wind', $this->properties['exclude']) && !empty($wind)) {
    extract($wind);
    if (!empty($meters_per_second)) {
      $wind_str = $this->strings['wind_blowing'] .
        $this->pref_units($this->properties['mark_begin'] .
                          $meters_per_second .
                          $this->properties['mark_end'] . 
                          $this->strings['meters_per_second'],
                          $this->properties['mark_begin'] .
                          $miles_per_hour .
                          $this->properties['mark_end'] . 
                          $this->strings['miles_per_hour']);
      if (!empty($gust_meters_per_second)) {
        $wind_str .= $this->strings['wind_with_gusts'] .
          $this->pref_units($this->properties['mark_begin'] . $gust_meters_per_second .
                            $this->properties['mark_end'] . 
$this->strings['meters_per_second'],
                            $this->properties['mark_begin'] . $gust_miles_per_hour .
                            $this->properties['mark_end'] . 
$this->strings['miles_per_hour']);
      }
      if ($deg == 'VRB') {
        $wind_str .= sprintf($this->strings['wind_variable'],
                             $this->properties['mark_begin'],
                             $this->properties['mark_end']);
      } else {

        $dir_str = $this->strings['wind_dir'][intval(round($deg/22.5))];
        
        $wind_str .= $this->strings['wind_from'] . $this->properties['mark_begin'] .
          $dir_str . $this->properties['mark_end'] . ' (' .
          $this->properties['mark_begin'] . $deg . '&deg;' .
          $this->properties['mark_end'] . ')';
        if (!empty($var_beg)) {
          
          $dir_beg_str = $this->strings['wind_dir'][intval(round($var_beg/22.5))];
          $dir_end_str = $this->strings['wind_dir'][intval(round($var_end/22.5))];
          
          $wind_str .= $this->strings['wind_varying'] .
            $this->properties['mark_begin'] . $dir_beg_str . 
$this->properties['mark_end'] .
            ' (' . $this->properties['mark_begin'] . $var_beg . '&deg;' .
            $this->properties['mark_end'] . ') ' . $this->strings['and'] .
            $this->properties['mark_begin'] . $dir_end_str . 
$this->properties['mark_end'] . 
            ' (' . $this->properties['mark_begin'] . $var_end . '&deg;' .
            $this->properties['mark_end'] . ')';
        }
      }
    } else {
      $wind_str = sprintf($this->strings['wind_calm'],
                          $this->properties['mark_begin'],
                          $this->properties['mark_end']);
    }
    $output['wind'] = $wind_str . '.';
  }


  /*********************************
   *   Temperature and dew-point   *
   *********************************/
  if (!in_array('temperature', $this->properties['exclude']) && !empty($temperature)) {
    
    extract($temperature);
    $output['temperature'] = $this->strings['temperature'] . 
      $this->pref_units($this->properties['mark_begin'] . $temp_c .
                        $this->properties['mark_end'] . ' &deg;C',
                        $this->properties['mark_begin'] . $temp_f .
                        $this->properties['mark_end'] . ' &deg;F');
    if (!empty($dew_c)) {
      $output['temperature'] .= $this->strings['dew_point'] . 
        $this->pref_units($this->properties['mark_begin'] . $dew_c .
                          $this->properties['mark_end'] . ' &deg;C',
                          $this->properties['mark_begin'] . $dew_f .
                          $this->properties['mark_end'] . ' &deg;F') . '.';
    }
  }
      

  /****************************
   *   Altimeter (pressure)   *
   ****************************/
  if (!in_array('altimeter', $this->properties['exclude']) && !empty($altimeter)) {
    extract($altimeter);
    $output['altimeter'] = $this->strings['altimeter'] . 
      $this->pref_units($this->properties['mark_begin'] . $hpa .
                        $this->properties['mark_end'] . ' hPa',
                        $this->properties['mark_begin'] . $inhg .
                        $this->properties['mark_end'] . ' inHg') . '.';
  }



  /**************************
   *   Relative humidity    *
   **************************/
  if (!in_array('rel_humidity', $this->properties['exclude']) && 
!empty($rel_humidity)) {
    $output['rel_humidity'] = $this->strings['rel_humidity']
      . $this->properties['mark_begin'] . $rel_humidity . '%' . 
$this->properties['mark_end'] . '.';
  }



  /*******************
   *   Cloudgroups   *
   *******************/
  if (!in_array('clouds', $this->properties['exclude'])) {
    if (empty($cloud_group1) ||
        $cloud_group1['condition'] == 'CLR' ||
        $cloud_group1['condition'] == 'SKC') {
      $output['clouds'] = sprintf($this->strings['cloud_clear'],
                                  $this->properties['mark_begin'],
                                  $this->properties['mark_end']);
    } else {
      
      $cloud_str1 = $this->parse_cloud_group($cloud_group1);
      if (!empty($cloud_group2)) {
        $cloud_str2 = $this->parse_cloud_group($cloud_group2);
      } else {
        $cloud_str2 = '';
      }

      if (!empty($cloud_group3)) {
        $cloud_str3 = $this->parse_cloud_group($cloud_group3);
      } else {
        $cloud_str3 = '';
      }

      $output['clouds'] = $this->strings['cloud_group'] .
        $this->list_sentences($cloud_str1,
                              $cloud_str2,
                              $cloud_str3) . '.';
    }
  }

        
  /******************
   *   Visibility   *
   ******************/
  if (!in_array('visibility', $this->properties['exclude']) && 
!empty($visibility_group1)) {
    
    $vis_str1 = $this->parse_visibility_group($visibility_group1);

    if (!empty($visibility_group2)) {
      $vis_str2 = $this->parse_visibility_group($visibility_group2);
    } else {
      $vis_str2 = '';
    }
    if (!empty($visibility_group3)) {
      $vis_str3 = $this->parse_visibility_group($visibility_group3);
    } else {
      $vis_str3 = '';
    }

    
    $output['visibility'] = $this->strings['visibility'] .
      $this->list_sentences($vis_str1, $vis_str2, $vis_str3) . '.';
  }


  /*********************
   *   Precipitation   *
   *********************/
  if (!in_array('precip', $this->properties['exclude']) && !empty($precipitation)) {
    
    extract($precipitation);
    
    $prec_str1 = $this->parse_precip($in, $mm) .
      $this->strings['precip_last_hour'];
    $prec_str2 = $this->parse_precip($in_6h, $mm_6h) .
      $this->strings['precip_last_6_hours'];
    $prec_str3 = $this->parse_precip($in_24h, $mm_24h) .
      $this->strings['precip_last_24_hours'];
    $prec_str4 = $this->parse_precip($snow_in, $snow_mm) .
      $this->strings['precip_snow'];
    
    $output['precip'] = $this->strings['precip_there_was'] .
      $this->list_sentences($prec_str1, $prec_str2, $prec_str3, $prec_str4);
  }
  
  
  /********************************
   *   Min and max temperatures   *
   ********************************/
  if (!in_array('temp_min_max', $this->properties['exclude']) &&
      !empty($temp_min_max)) {
    extract($temp_min_max);
    $temp_str = '';
    if (isset($max6h_c) && isset($min6h_c)) {
      $temp_str .= $this->strings['temp_min_max_6_hours'] .
        $this->pref_units($this->properties['mark_begin'] . $temp_max6h_c .
                       $this->properties['mark_end'] . ' and ' . 
$this->properties['mark_begin'] .
                       $temp_min6h_c . $this->properties['mark_end'] . ' &deg;C',
                       $this->properties['mark_begin'] . $temp_max6h_f .
                       $this->properties['mark_end'] . ' and ' . 
$this->properties['mark_begin'] .
                       $temp_min6h_f . $this->properties['mark_end'] . ' &deg;F') . 
'.';
    } else {
      if (isset($max6h_c)) {
        if (!empty($temp_str)) {
          $temp_str .= ' ';
        }
        $temp_str .= $this->strings['temp_max_6_hours'] . 
          $this->pref_units($this->properties['mark_begin'] . $max6h_c .
                         $this->properties['mark_end'] . ' &deg;C',
                         $this->properties['mark_begin'] . $max6h_f .
                         $this->properties['mark_end'] . ' &deg;F') . '.';
      }
      if (isset($min6h_c)) {
        if (!empty($temp_str)) {
          $temp_str .= ' ';
        }
        $temp_str .= $this->strings['temp_min_6_hours'] . 
          $this->pref_units($this->properties['mark_begin'] . $min6h_c .
                         $this->properties['mark_end'] . ' &deg;C',
                         $this->properties['mark_begin'] . $min6h_f .
                         $this->properties['mark_end'] . ' &deg;F') . '.';
      }
    }
    if (isset($max24h_c)) {
      if (!empty($temp_str)) {
        $temp_str .= ' ';
      }
      $temp_str .= $this->strings['temp_min_max_24_hours'] .
        $this->pref_units($this->properties['mark_begin'] . $max24h_c . 
$this->properties['mark_end'] .
                       $this->strings['and'] . $this->properties['mark_begin'] .
                       $min24h_c . $this->properties['mark_end'] . ' &deg;C',
                       $this->properties['mark_begin'] . $max24h_f . 
$this->properties['mark_end'] .
                       $this->strings['and'] . $this->properties['mark_begin'] .
                       $min24h_f . $this->properties['mark_end'] . ' &deg;F') . '.';
    }
    if (!empty($temp_str)) {
      $output['temp_min_max'] = $temp_str;
    }
  }
  

  /**************************
   *   Runway information   *
   **************************/
  if (!in_array('runway', $this->properties['exclude']) &&
      !empty($runway_group1)) {

    $runway_str1 = $runway_str2 = $runway_str3 = $runway_str4 = '';
    
    $runway_str1 = $this->parse_runway_group($runway_group1);
    if (!empty($runway_group2)) {
      $runway_str2 = $this->parse_runway_group($runway_group2);
      if (!empty($runway_group3)) {
        $runway_str3 = $this->parse_runway_group($runway_group3);
        if (!empty($runway_group4)) {
          $runway_str4 = $this->parse_runway_group($runway_group4);
        }
      }
    }

    
    $output['runway'] = $this->strings['runway_visibility'] .
      $this->list_sentences($runway_str1,
                            $runway_str2,
                            $runway_str3,
                            $runway_str4) . '.';
  }

  
  /***********************
   *   Present weather   *
   ***********************/
  if (!in_array('weather', $this->properties['exclude']) &&
      !empty($weather_group1)) {
    
    $weather_str = 'Currently ' . $this->parse_weather_group($weather_group1);
    if (!empty($weather_group2)) {
      $weather_str = $weather_str . $this->strings['and'] .
        $this->parse_weather_group($weather_group2);
    }
    if (!empty($weather_group3)) {
      $weather_str = $weather_str . $this->strings['and'] .
        $this->parse_weather_group($weather_group3);
    }
    
    if (!empty($weather_str)) {
      $output['weather'] = $weather_str;
    }
  }
  
  /*
   * This is where we make the output.
   */
  
  echo '<!-- Generated by PHP Weather ' . $this->version . " -->\n";
  
  if (defined('DEBUG')) {
    while (list($key, $val) = each($output)) {
      echo "<p><i>$key</i>: $val</p>";
    }
    
    echo "<pre>\n";
    print_r ($data);
    echo "</pre>\n";
  } else {
    print "<blockquote>\n";
    while (list($key, $val) = each($output)) {
      echo $val . "\n";
    }
    print "</blockquote>\n";
  }
  return 0;  
  }

  /**
   * Makes a short weather-report in a table.
   *
   * @param   array   data taken from decode_metar()
   * @return  string  The table with weather-data.
   * @access  public
   */
  function print_table($data) {
    
    extract($data);
    
    $minutes = round((time() - $time)/60);
    $wind    = $this->pref_units($wind['meters_per_second'] . ' mps',
                                 $wind['miles_per_hour'] . ' mph') . '/' .
               $this->strings['wind_dir_short'][intval(round($wind['deg']/22.5))];
    $temp       = $this->pref_units($temperature['temp_c'] . '&deg;C',
                                    $temperature['temp_f'] . '&deg;F');
    $pressure   = $this->pref_units($altimeter['hpa'] . ' hPa',
                                    $altimeter['inhg'] . ' inHg');
                                    
                                    /* The table-heading ought to be
                                       translated. */

    echo "<table>
  <tr>
   <th>Station</th>
   <th>Age (minutes)</th>
   <th>Wind/Direction</th>
   <th>Temperature</th>
   <th>Pressure</th>
   <th>Humidity</th>
  </tr>
  <tr>
    <td>$location</td>
    <td>$minutes</td>
    <td>$wind</td>
    <td>$temp</td>
    <td>$pressure</td>
    <td>$rel_humidity%</td>
  </tr>
</table>
";
  }
}


?>

--- NEW FILE ---
<?php
require_once(PHPWEATHER_BASE_DIR . '/locales//locale_common.php');

/**
 * Provides all the strings needed by locale_common to produce English output.
 *
 * @author   Martin Geisler <[EMAIL PROTECTED]>
 * @version  $Id: locale_en.php,v 1.1 2001/06/27 11:27:27 gimpster Exp $
 */
class locale_en extends locale_common {

  /**
   * This constructor provides all the strings used.
   *
   * @param  array  This is just passed on to locale_common()
   */
  function locale_en($input) {
    $this->strings['charset']                  = 'ISO-8859-1';
    $this->strings['no_data']                  = 'Sorry! There\'s no data available 
for %s%s%s.';
    $this->strings['list_sentences_and']       = ' and ';
    $this->strings['list_sentences_comma']     = ', ';
    $this->strings['list_sentences_final_and'] = ', and ';
    $this->strings['location']                 = 'This is a report for %s%s%s.';
    $this->strings['minutes']                  = ' minutes';
    $this->strings['time_format']              = 'The report was made %s ago, at 
%s%s%s UTC.';
    $this->strings['time_minutes']             = 'and %s%s%s minutes';
    $this->strings['time_one_hour']            = '%sone%s hour %s';
    $this->strings['time_several_hours']       = '%s%s%s hours %s';
    $this->strings['time_a_moment']            = 'a moment';
    $this->strings['meters_per_second']        = ' meters per second';
    $this->strings['miles_per_hour']           = ' miles per hour';
    $this->strings['meter']                    = ' meter';
    $this->strings['meters']                   = ' meters';
    $this->strings['feet']                     = ' feet';
    $this->strings['kilometers']               = ' kilometers';
    $this->strings['miles']                    = ' miles';
    $this->strings['and']                      = ' and ';
    $this->strings['wind_blowing']             = 'The wind was blowing at a speed of ';
    $this->strings['wind_with_gusts']          = ' with gusts up to ';
    $this->strings['wind_from']                = ' from ';
    $this->strings['wind_variable']            = ' from %svariable%s directions.';
    $this->strings['wind_varying']             = ', varying between ';
    $this->strings['wind_calm']                = 'The wind was %scalm%s';
    $this->strings['wind_dir'] = array(
      'north',
      'north/northeast',
      'northeast',
      'east/northeast',
      'east',
      'east/southeast',
      'southeast',
      'south/southeast',
      'south',
      'south/southwest',
      'southwest',
      'west/southwest',
      'west',
      'west/northwest',
      'northwest',
      'north/northwest',
      'north');
    $this->strings['wind_dir_short'] = array(
      'N',
      'NNE',
      'NE',
      'ENE',
      'E',
      'ESE',
      'SE',
      'SSE',
      'S',
      'SSW',
      'SW',
      'WSW',
      'W',
      'WNW',
      'NW',
      'NNW',
      'N');
    $this->strings['wind_dir_short_long'] = array(
      'N'  => 'north',
      'NE' => 'northeast',
      'E'  => 'east',
      'SE' => 'southeast',
      'S'  => 'south',
      'SW' => 'southwest',
      'W'  => 'west',
      'NW' => 'northwest'
      );
    $this->strings['temperature']     = 'The temperature was ';
    $this->strings['dew_point']       = ', with a dew-point at ';
    $this->strings['altimeter']       = 'The atmospheric pressure was ';
    $this->strings['rel_humidity']    = 'The relative humidity was ';
    $this->strings['cloud_group']     = 'There were ';
    $this->strings['cloud_clear']     = 'The sky was %sclear%s.';
    $this->strings['cloud_height']    = ' clouds at a height of ';
    $this->strings['cloud_overcast']  = 'the sky was %sovercast%s from a height of ';
    $this->strings['cloud_vertical_visibility'] = 'the %svertical visibility%s was ';
    $this->strings['cloud_condition'] =
      array(
            'SKC' => 'clear',
            'CLR' => 'clear',
            'FEW' => 'a few',
            'SCT' => 'scattered',
            'BKN' => 'broken',
            'OVC' => 'overcast');
    $this->strings['cumulonimbus']     = ' cumulonimbus';
    $this->strings['towering_cumulus'] = ' towering cumulus';
    $this->strings['cavok']            = ' no clouds below %s and no cumulonimbus 
clouds';
    $this->strings['weather']          = 
      array(
            '-' => 'light ',
            ' ' => 'moderate ',
            '+' => 'heavy ',
            'PR' => 'partial ',
            'BC' => 'patches of ',
            'MI' => 'shallow ',
            'DR' => 'low drifting ',
            'BL' => 'blowing ',
            'SH' => 'showers of ',
            'TS' => 'thunderstorms ',
            'FZ' => 'freezing ',
            'DZ' => 'drizzle  ',
            'RA' => 'rain ',
            'SN' => 'snow ',
            'SG' => 'snow grains ',
            'IC' => 'ice crystals ',
            'PL' => 'ice pellets ',
            'GR' => 'hail ',
            'GS' => 'small hail and/or snow pellets ',
            'UP' => 'unknown ',
            'BR' => 'mist ',
            'FG' => 'fog ',
            'FU' => 'smoke ',
            'VA' => 'volcanic ash ',
            'DU' => 'widespread dust ',
            'SA' => 'sand ',
            'HZ' => 'haze ',
            'PY' => 'spray ',
            'PO' => 'well-developed dust/sand whirls ',
            'SQ' => 'squalls ',
            'FC' => 'funnel cloud tornado waterspout ',
            'SS' => 'sandstorm/duststorm ');
    $this->strings['visibility'] = 'The overall visibility was ';
    $this->strings['visibility_greater_than']  = 'greater than ';
    $this->strings['visibility_less_than']     = 'less than ';
    $this->strings['runway_upward_tendency']   = ' with an %supward%s tendency';
    $this->strings['runway_downward_tendency'] = ' with a %sdownward%s tendency';
    $this->strings['runway_no_tendency']       = ' with %sno distinct%s tendency';
    $this->strings['runway_between']           = 'between ';
    $this->strings['runway_left']              = ' left';
    $this->strings['runway_central']           = ' central';
    $this->strings['runway_right']             = ' right';
    $this->strings['runway_visibility']        = 'The visibility was ';
    $this->strings['runway_for_runway']        = ' for runway ';

    /* We run the parent constructor */
    $this->locale_common($input);
    
  }
}

?>


_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins

Reply via email to