You are here

protected function ThemeService::formatCondition in Weather 2.0.x

Same name and namespace in other branches
  1. 8 src/Service/ThemeService.php \Drupal\weather\Service\ThemeService::formatCondition()

Returns weather condition as translated text from yr.no symbol number.

Parameters

mixed $condition_no: The weather condition number from yr.no.

Return value

string Translated text with corresponding weather condition

1 call to ThemeService::formatCondition()
ThemeService::setForecastsVariables in src/Service/ThemeService.php
Adds variables related to weather forecast.

File

src/Service/ThemeService.php, line 375

Class

ThemeService
Prepare forecast data for displaying.

Namespace

Drupal\weather\Service

Code

protected function formatCondition($condition_no) {

  // Strip the suffix "d", "n", and "m".
  // (day, night, mørketid -> polar night)
  $condition_no = substr($condition_no, 0, 2);
  switch ($condition_no) {
    case 1:
      $txt = $this
        ->t('Clear sky');
      break;
    case 2:
      $txt = $this
        ->t('Fair');
      break;
    case 3:
      $txt = $this
        ->t('Partly cloudy');
      break;
    case 4:
      $txt = $this
        ->t('Cloudy');
      break;
    case 5:
      $txt = $this
        ->t('Rain showers');
      break;
    case 6:
      $txt = $this
        ->t('Rain showers and thunder');
      break;
    case 7:
      $txt = $this
        ->t('Sleet showers');
      break;
    case 8:
      $txt = $this
        ->t('Snow showers');
      break;
    case 9:
      $txt = $this
        ->t('Rain');
      break;
    case 10:
      $txt = $this
        ->t('Heavy rain');
      break;
    case 11:
      $txt = $this
        ->t('Heavy rain and thunder');
      break;
    case 12:
      $txt = $this
        ->t('Sleet');
      break;
    case 13:
      $txt = $this
        ->t('Snow');
      break;
    case 14:
      $txt = $this
        ->t('Snow and thunder');
      break;
    case 15:
      $txt = $this
        ->t('Fog');
      break;
    case 20:
      $txt = $this
        ->t('Sleet showers and thunder');
      break;
    case 21:
      $txt = $this
        ->t('Snow showers and thunder');
      break;
    case 22:
      $txt = $this
        ->t('Rain and thunder');
      break;
    case 23:
      $txt = $this
        ->t('Sleet and thunder');
      break;
    case 24:
      $txt = $this
        ->t('Light rain showers and thunder');
      break;
    case 25:
      $txt = $this
        ->t('Heavy rain showers and thunder');
      break;
    case 26:
      $txt = $this
        ->t('Light sleet showers and thunder');
      break;
    case 27:
      $txt = $this
        ->t('Heavy sleet showers and thunder');
      break;
    case 28:
      $txt = $this
        ->t('Light snow showers and thunder');
      break;
    case 29:
      $txt = $this
        ->t('Heavy snow showers and thunder');
      break;
    case 30:
      $txt = $this
        ->t('Light rain and thunder');
      break;
    case 31:
      $txt = $this
        ->t('Light sleet and thunder');
      break;
    case 32:
      $txt = $this
        ->t('Heavy sleet and thunder');
      break;
    case 33:
      $txt = $this
        ->t('Light snow and thunder');
      break;
    case 34:
      $txt = $this
        ->t('Heavy snow and thunder');
      break;
    case 40:
      $txt = $this
        ->t('Light rain showers');
      break;
    case 41:
      $txt = $this
        ->t('Heavy rain showers');
      break;
    case 42:
      $txt = $this
        ->t('Light sleet showers');
      break;
    case 43:
      $txt = $this
        ->t('Heavy sleet showers');
      break;
    case 44:
      $txt = $this
        ->t('Light snow showers');
      break;
    case 45:
      $txt = $this
        ->t('Heavy snow showers');
      break;
    case 46:
      $txt = $this
        ->t('Light rain');
      break;
    case 47:
      $txt = $this
        ->t('Light sleet');
      break;
    case 48:
      $txt = $this
        ->t('Heavy sleet');
      break;
    case 49:
      $txt = $this
        ->t('Light snow');
      break;
    case 50:
      $txt = $this
        ->t('Heavy snow');
      break;
    default:
      $txt = $this
        ->t('No data');
  }
  return $txt;
}