1<?php 2 3declare(strict_types=1); 4 5namespace phpweb\I18n; 6 7use function array_key_exists; 8 9final class Languages 10{ 11 /** 12 * This is a list of all manual languages hosted 13 * within PHP Git repositories (https://github.com/php/doc-{lang}) 14 */ 15 public const LANGUAGES = [ 16 'en' => 'English', 17 'de' => 'German', 18 'es' => 'Spanish', 19 'fr' => 'French', 20 'it' => 'Italian', 21 'ja' => 'Japanese', 22 'pl' => 'Polish', 23 'pt_BR' => 'Brazilian Portuguese', 24 'ro' => 'Romanian', 25 'ru' => 'Russian', 26 'tr' => 'Turkish', 27 'uk' => 'Ukrainian', 28 'zh' => 'Chinese (Simplified)', 29 ]; 30 31 /** 32 * The following languages are inactive, which means they will not: 33 * - Show up via the language select box at php.net 34 * - Be selectable via my.php 35 * - Accept redirections to the translation, despite ACCEPT_LANGUAGE 36 * - Be listed at php.net/docs or php.net/download-docs 37 * However, translation status for these languages is available at: 38 * - https://doc.php.net/ 39 */ 40 public const INACTIVE_ONLINE_LANGUAGES = [ 41 'pl' => 'Polish', 42 'ro' => 'Romanian', 43 ]; 44 45 public const ACTIVE_ONLINE_LANGUAGES = [ 46 'en' => 'English', 47 'de' => 'German', 48 'es' => 'Spanish', 49 'fr' => 'French', 50 'it' => 'Italian', 51 'ja' => 'Japanese', 52 'pt_BR' => 'Brazilian Portuguese', 53 'ru' => 'Russian', 54 'tr' => 'Turkish', 55 'uk' => 'Ukrainian', 56 'zh' => 'Chinese (Simplified)', 57 ]; 58 59 /** 60 * Convert between language codes back and forth 61 * 62 * Uses non-standard languages codes and so conversion is needed when communicating with the outside world. 63 * 64 * Fall back to English if the language is not available. 65 */ 66 public function convert(string $languageCode): string 67 { 68 return match ($languageCode) { 69 'zh_cn', 'zh_CN' => 'zh', 70 'pt_br', 'pt_BR' => 'pt_BR', 71 default => array_key_exists($languageCode, self::LANGUAGES) ? $languageCode : 'en', 72 }; 73 } 74} 75