Polish months in date formatting

In beautiful Polish, different grammar is used to name the months when things like โ€œMarch 2013โ€ โ€‹โ€‹(without a day) versus โ€œMarch 17, 2013โ€ โ€‹โ€‹(with a day) are said.

Using PHP strftime() with %B gives the correct month name for a day without a diary. How can I write the date in the day case correctly? Do I have to code something myself or is there any kind of support for such cases?

+4
source share
4 answers

You need two arrays:

 $m_en = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); $m_pol = array("Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"); 

all you have to do is:

 $workoutSlug = str_replace($m_en, $m_pol, $input); 

An input is the input you want to translate.

+5
source

There is IntlDateFormatter , an international version of DateFormatter with PHP5.3 if you enable the internal extension.

 if (version_compare(PHP_VERSION, '5.3.0', '<')) { exit ('IntlDateFormatter is available on PHP 5.3.0 or later.'); } if (!class_exists('IntlDateFormatter')) { exit ('You need to install php_intl extension.'); } $polishDateFormatter = new IntlDateFormatter( 'pl_PL', IntlDateFormatter::LONG, IntlDateFormatter::NONE ); $now = new DateTime("2013-08-06"); echo $polishDateFormatter->format($now), "\n"; 

This code returns me

6 sierpnia 2013

which hopefully will be correct. (I do not know Polish;)

You can also check IntlDateFormatter :: SHORT, MEDIUM, and FULL to get other notation in the second constructor parameter.

+7
source

As you probably do not know all the languages โ€‹โ€‹in the world, I would suggest that any language requires such functionality, and English is an exception, where this rule does not change anything. Then I will create a format class that will contain a valid date string depending on the language.

Your own function can implement the logic as a replacement of the month from Marzec to Marca , so you store two arrays with the corresponding index and depending on the month you choose which element from the array should be replaced by which element of array2 in the output line before returning.

Sometimes the easiest option is the best you can do.

+1
source

If you are looking for date creation in php, you are here: http://php.net/manual/en/datetime.format.php

-2
source

Source: https://habr.com/ru/post/1495418/


All Articles