This commit is contained in:
Javier Casares 2026-10-12 11:55:23 +00:00
commit 06153e387d
47 changed files with 5116 additions and 0 deletions

View file

@ -0,0 +1,148 @@
<?php
/**
* Shared weather condition keys: labels (translated), Meteocons icons,
* day/night detection and localized calendar names.
*
* Icons are Meteocons (https://github.com/basmilius/meteocons), MIT license,
* bundled under public/icons/flat/.
*
* @package FontdelboscEltemps
*/
defined( 'ABSPATH' ) || exit;
/**
* Maps condition keys to translated labels, Meteocons icons and
* localized calendar names.
*/
final class Fontdelbosc_Conditions {
/**
* Condition key to Meteocons file names, indexed [ day, night ].
*
* @var array<string,array{0:string,1:string}>
*/
private const ICONS = array(
'clear' => array( 'clear-day.svg', 'clear-night.svg' ),
'mainly_clear' => array( 'clear-day.svg', 'clear-night.svg' ),
'partly_cloudy' => array( 'partly-cloudy-day.svg', 'partly-cloudy-night.svg' ),
'cloudy' => array( 'cloudy.svg', 'cloudy.svg' ),
'overcast' => array( 'overcast.svg', 'overcast.svg' ),
'fog' => array( 'fog-day.svg', 'fog-night.svg' ),
'drizzle_light' => array( 'drizzle.svg', 'drizzle.svg' ),
'drizzle' => array( 'drizzle.svg', 'drizzle.svg' ),
'drizzle_heavy' => array( 'drizzle.svg', 'drizzle.svg' ),
'rain_light' => array( 'overcast-rain.svg', 'overcast-rain.svg' ),
'rain' => array( 'rain.svg', 'rain.svg' ),
'rain_heavy' => array( 'extreme-rain.svg', 'extreme-rain.svg' ),
'rain_showers_light' => array( 'partly-cloudy-day-rain.svg', 'partly-cloudy-night-rain.svg' ),
'rain_showers' => array( 'partly-cloudy-day-rain.svg', 'partly-cloudy-night-rain.svg' ),
'rain_showers_heavy' => array( 'rain.svg', 'rain.svg' ),
'snow_light' => array( 'snow.svg', 'snow.svg' ),
'snow' => array( 'snow.svg', 'snow.svg' ),
'snow_heavy' => array( 'extreme-snow.svg', 'extreme-snow.svg' ),
'thunderstorm' => array( 'thunderstorms-day-rain.svg', 'thunderstorms-night-rain.svg' ),
'thunderstorm_hail' => array( 'thunderstorms-day-hail.svg', 'thunderstorms-night-hail.svg' ),
);
/**
* Returns the translated label for a condition key.
*
* @param string $key Condition key.
* @return string
*/
public static function label( string $key ): string {
$labels = array(
'clear' => __( 'Clear sky', 'fontdelbosc-eltemps' ),
'mainly_clear' => __( 'Clear sky', 'fontdelbosc-eltemps' ),
'partly_cloudy' => __( 'Partly cloudy', 'fontdelbosc-eltemps' ),
'cloudy' => __( 'Cloudy', 'fontdelbosc-eltemps' ),
'overcast' => __( 'Overcast', 'fontdelbosc-eltemps' ),
'fog' => __( 'Fog', 'fontdelbosc-eltemps' ),
'drizzle_light' => __( 'Drizzle', 'fontdelbosc-eltemps' ),
'drizzle' => __( 'Drizzle', 'fontdelbosc-eltemps' ),
'drizzle_heavy' => __( 'Drizzle', 'fontdelbosc-eltemps' ),
'rain_light' => __( 'Rain', 'fontdelbosc-eltemps' ),
'rain' => __( 'Rain', 'fontdelbosc-eltemps' ),
'rain_heavy' => __( 'Rain', 'fontdelbosc-eltemps' ),
'rain_showers_light' => __( 'Rain', 'fontdelbosc-eltemps' ),
'rain_showers' => __( 'Rain', 'fontdelbosc-eltemps' ),
'rain_showers_heavy' => __( 'Rain', 'fontdelbosc-eltemps' ),
'snow_light' => __( 'Snow', 'fontdelbosc-eltemps' ),
'snow' => __( 'Snow', 'fontdelbosc-eltemps' ),
'snow_heavy' => __( 'Snow', 'fontdelbosc-eltemps' ),
'thunderstorm' => __( 'Thunderstorm', 'fontdelbosc-eltemps' ),
'thunderstorm_hail' => __( 'Thunderstorm', 'fontdelbosc-eltemps' ),
);
return $labels[ $key ] ?? $labels['cloudy'];
}
/**
* Returns the bundled Meteocons icon URL for a condition key.
*
* @param string $key Condition key.
* @param bool $night Whether the night variant should be used.
* @return string
*/
public static function icon( string $key, bool $night = false ): string {
$files = self::ICONS[ $key ] ?? self::ICONS['cloudy'];
return FONTDELBOSC_ELTEMPS_PLUGIN_URL . 'public/icons/flat/' . $files[ $night ? 1 : 0 ];
}
/**
* Rough day/night detection for icon selection.
*
* @param int $hour Local hour (0-23).
* @return bool True when night.
*/
public static function is_night( int $hour ): bool {
return $hour < 7 || $hour >= 21;
}
/**
* Returns the translated weekday name for an ISO-8601 weekday number.
*
* @param int $number Weekday number (1 = Monday, 7 = Sunday).
* @return string
*/
public static function weekday( int $number ): string {
$weekdays = array(
1 => __( 'Monday', 'fontdelbosc-eltemps' ),
2 => __( 'Tuesday', 'fontdelbosc-eltemps' ),
3 => __( 'Wednesday', 'fontdelbosc-eltemps' ),
4 => __( 'Thursday', 'fontdelbosc-eltemps' ),
5 => __( 'Friday', 'fontdelbosc-eltemps' ),
6 => __( 'Saturday', 'fontdelbosc-eltemps' ),
7 => __( 'Sunday', 'fontdelbosc-eltemps' ),
);
return $weekdays[ $number ] ?? '';
}
/**
* Returns the translated month name for a month number.
*
* @param int $number Month number (1-12).
* @return string
*/
public static function month( int $number ): string {
$months = array(
1 => __( 'January', 'fontdelbosc-eltemps' ),
2 => __( 'February', 'fontdelbosc-eltemps' ),
3 => __( 'March', 'fontdelbosc-eltemps' ),
4 => __( 'April', 'fontdelbosc-eltemps' ),
5 => __( 'May', 'fontdelbosc-eltemps' ),
6 => __( 'June', 'fontdelbosc-eltemps' ),
7 => __( 'July', 'fontdelbosc-eltemps' ),
8 => __( 'August', 'fontdelbosc-eltemps' ),
9 => __( 'September', 'fontdelbosc-eltemps' ),
10 => __( 'October', 'fontdelbosc-eltemps' ),
11 => __( 'November', 'fontdelbosc-eltemps' ),
12 => __( 'December', 'fontdelbosc-eltemps' ),
);
return $months[ $number ] ?? '';
}
}