This commit is contained in:
2020-09-18 18:48:40 +02:00
committed by Stefan Rohde-Enslin
commit f05938c867
3 changed files with 705 additions and 0 deletions

138
src/inc/datesByCountry.php Normal file
View File

@ -0,0 +1,138 @@
<?PHP
/**
* This file contains a function for correctly formatting time according to the
* user's language.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Function getDateFormatByLang returns the common date format in a given
* country / language.
*
* @param string $lang Language code to check.
*
* @thanks Michael Connor (https://gist.github.com/mlconnor/1887156) for
* compiling the underlying array.
*
* @return string
*/
function getDateFormatByLang(string $lang):string {
$datesByCountry = [
'ar' => '%d/%m/%Y',
'be' => '%d.%B.%Y',
'bg' => '%Y-%B-%d',
'ca' => '%d/%m/%Y',
'cs' => '%d.%B.%Y',
'da' => '%d-%m-%Y',
'de' => '%d.%m.%Y',
'el' => '%d/%B/%Y',
'en' => '%B %d, %Y',
'es' => '%d/%m/%Y',
'et' => '%d.%m.%Y',
'fa' => '%d/%m/%Y',
'fi' => '%d.%B.%Y',
'fr' => '%d/%m/%Y',
'ga' => '%d/%m/%Y',
'hr' => '%d.%m.%Y',
'hu' => '%Y. %B %d.',
'id' => '%d %B %Y',
'in' => '%d/%m/%Y',
'is' => '%d.%B.%Y',
'it' => '%d/%m/%Y',
'iw' => '%d/%m/%Y',
'ja' => '%Y年%m月%d日',
'ka' => '%d.%m.%Y',
'ko' => '%Y년 %m월 %d일',
'lt' => '%Y.%B.%d',
'lv' => '%Y.%d.%B',
'mk' => '%d.%B.%Y',
'ms' => '%d/%m/%Y',
'mt' => '%d/%m/%Y',
'nl' => '%d-%B-%Y',
'no' => '%d.%m.%Y',
'pl' => '%d.%m.%Y',
'pt' => '%d/%m/%Y',
'ro' => '%d.%m.%Y',
'ru' => '%d.%m.%Y',
'sk' => '%d.%B.%Y',
'sl' => '%d.%B.%Y',
'sq' => '%Y-%m-%d',
'sr' => '%d.%B.%Y.',
'sv' => '%Y-%m-%d',
'ta' => '%d-%m-%Y',
'tr' => '%d.%m.%Y',
'uk' => '%d.%m.%Y',
'vi' => '%d/%m/%Y',
'zh' => '%Y年%m月%d日',
];
if (!isset($datesByCountry[$lang])) return $datesByCountry["en"];
return $datesByCountry[$lang];
}
/**
* Function getDateFormatByLang returns the common date format in a given
* country / language.
*
* @param string $lang Language code to check.
*
* @thanks Michael Connor (https://gist.github.com/mlconnor/1887156) for
* compiling the underlying array.
*
* @return string
*/
function getMonthFormatByLang(string $lang):string {
$datesByCountry = [
'ar' => '%m/%Y',
'be' => '%B %Y',
'bg' => '%Y-%B',
'ca' => '%m/%Y',
'cs' => '%B.%Y',
'da' => '%m-%Y',
'de' => '%B %Y',
'el' => '%B %Y',
'en' => '%B %Y',
'es' => '%B %Y',
'fa' => '%B %Y',
'fr' => '%B %Y',
'hu' => '%Y. %B',
'in' => '%m/%Y',
'is' => '%B %Y',
'it' => '%B %Y',
'iw' => '%m %Y',
'ja' => '%Y年%m月',
'ka' => '%B %Y',
'ko' => '%Y년 %m월',
'lt' => '%Y. %B.',
'lv' => '%Y. %B',
'mk' => '%B %Y',
'ms' => '%m %Y',
'mt' => '%m %Y',
'nl' => '%B %Y',
'no' => '%B %Y',
'pl' => '%B %Y',
'pt' => '%B %Y',
'ro' => '%B %Y',
'ru' => '%B %Y',
'sk' => '%B %Y',
'sl' => '%B %Y',
'sq' => '%B %Y',
'sr' => '%B %Y',
'sv' => '%Y-%m',
'ta' => '%B %Y',
'tr' => '%B %Y',
'tl' => '%B %Y',
'uk' => '%m %Y',
'vi' => '%m %Y',
'zh' => '%Y年%m月',
];
if (!isset($datesByCountry[$lang])) return $datesByCountry["en"];
return $datesByCountry[$lang];
}