*/ private const NAME_ALIASES = array( 'Gasóleo A habitual' => 'Gasoleo A', 'Gasóleo B' => 'Gasoleo B', 'Gasóleo C' => 'Gasoleo C', 'Gasóleo Premium' => 'Gasoleo Premium', 'Biodiésel' => 'Biodiesel', 'Hidrógeno' => 'Hidrogeno', ); /** * Resolves a catalog product name to the matching station price field. * * @param string $product_name Catalog NombreProducto. * @param array $labels Price field labels present in the payload. */ public static function station_field( string $product_name, array $labels ): ?string { $alias = self::NAME_ALIASES[ $product_name ] ?? $product_name; $want = self::norm( $alias ); foreach ( $labels as $label ) { if ( self::norm( $label ) === $want ) { return $label; } } return null; } /** * Returns a translated display label for a product name, * falling back to the raw API name for unknown products. * * @param string $product_name Catalog NombreProducto or station field label. */ public static function label( string $product_name ): string { $name = self::NAME_ALIASES[ $product_name ] ?? $product_name; return match ( self::norm( $name ) ) { 'gasolina 95 e5' => __( 'Gasoline 95 E5', 'fontdelbosc-combustible' ), 'gasolina 95 e5 premium' => __( 'Gasoline 95 E5 Premium', 'fontdelbosc-combustible' ), 'gasolina 98 e5' => __( 'Gasoline 98 E5', 'fontdelbosc-combustible' ), 'gasoleo a' => __( 'Diesel A', 'fontdelbosc-combustible' ), 'gasoleo premium' => __( 'Premium Diesel', 'fontdelbosc-combustible' ), 'gasoleo b' => __( 'Diesel B', 'fontdelbosc-combustible' ), 'gases licuados del petroleo' => __( 'LPG', 'fontdelbosc-combustible' ), 'gas natural comprimido' => __( 'CNG', 'fontdelbosc-combustible' ), 'gas natural licuado' => __( 'LNG', 'fontdelbosc-combustible' ), 'hidrogeno' => __( 'Hydrogen', 'fontdelbosc-combustible' ), 'biodiesel' => __( 'Biodiesel', 'fontdelbosc-combustible' ), 'diesel renovable' => __( 'Renewable Diesel', 'fontdelbosc-combustible' ), 'gasolina renovable' => __( 'Renewable Gasoline', 'fontdelbosc-combustible' ), 'adblue' => __( 'AdBlue', 'fontdelbosc-combustible' ), default => $product_name, }; } /** * Normalizes a name for comparison: lowercase, accents stripped. * * @param string $name Raw name. */ private static function norm( string $name ): string { $ascii = iconv( 'UTF-8', 'ASCII//TRANSLIT//IGNORE', $name ); if ( false === $ascii || '' === $ascii ) { $ascii = $name; } return trim( strtolower( $ascii ) ); } }