Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

No translating for months names on forum

Asked Modified Viewed 1,230 times
B
BenL
B
BenL 12
  • Member, joined since
  • Contributed 96 posts on the community forums.
  • Started 41 threads in the forums
  • Started this discussions
asked
Member

Hello there,
Today im updated PF to latest version 9.10.20, and after posting on forum and merge post on topic i see name of month in EN not in PL.

Quote

Scalony z 07 February 2022 21:57:45:


I checked translation on crowdin and i cannot find EN name there.

Please advice where i can change this?

Update:
In global settings in Date and Time i have also months names in EN

Regards.
Edited by BenL on 07-02-2022 22:46,
0 replies

7 posts

R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

Previously for formatting time was used this function strftime() but as you can see, since PHP 8.1, this function is deprecated so I had to replace it with another one. Unfortunately, new one ignores setlocale() - this is another function that tells php which translation to use from the server. Here is the locale string that was used to control which translations are used in strftime() https://github.com/PHPFusion/PHPFusio...bal.php#L2 but now can be removed since it doesn't work and strftime() was completely removed in core.

Actually these months names was never stored in locales. Yes we have this https://github.com/PHPFusion/PHPFusio...al.php#L15 but this is something from v7 core and never used in v9.

Possible solution will be to use IntlDateFormatter::format() but not every server has installed php_intl extension.. So I added version that should works everywhere but doesn't support locales.
0 replies
B
BenL
B
BenL 12
  • Member, joined since
  • Contributed 96 posts on the community forums.
  • Started 41 threads in the forums
  • Started this discussions
answered
Member

hi @RobiNN, thanks for sharing with those all details. So i assume that nothing can be done for this for this moment?
0 replies
E
Ernst74
E
  • Junior Member, joined since
  • Contributed 32 posts on the community forums.
  • Started 14 threads in the forums
answered
Junior Member

Why can not use the locale for month?

English locale = array_1
locale form settings = array_2
str_replace(array_1, array_2, $output);
0 replies
E
Ernst74
E
  • Junior Member, joined since
  • Contributed 32 posts on the community forums.
  • Started 14 threads in the forums
answered
Junior Member

That should be work:
function format_date($format, $time) {
   global $locale, $settings;
   $format = str_replace(
      ['%a', '%A', '%d', '%e', '%u', '%w', '%W', '%b', '%h', '%B', '%m', '%y', '%Y', '%D', '%F', '%x', '%n', '%t', '%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X', '%z', '%Z', '%c', '%s', '%%'],
      ['D', 'l', 'd', 'j', 'N', 'w', 'W', 'M', 'M', 'F', 'm', 'y', 'Y', 'm/d/y', 'Y-m-d', 'm/d/y', "n", "t", 'H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s', 'O', 'T', 'D M j H:i:s Y', 'U', '%'],
      $format
   );
   
   $date = DateTimeImmutable::createFromFormat('U', $time);
   
   if ($settings['locale'] == 'English') {
      return $date->format($format);
   } else {
      $_months_en = " |January|February|March|April|May|June|July|August|September|October|November|December";
      $exp_months_en = explode("|", $_months_en );
      $exp_settings_locale = explode("|", $locale['months']);
      $date_lang = str_replace($exp_months_en, $exp_settings_locale, $date->format($format));
      
      return $date_lang;
   }
}
Edited by Ernst74 on 17-02-2022 08:12,
0 replies
R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

This might work, but there is also a short version of names of months.. So you need to add another str_replace. It was my original idea, but I didn't add it because it's not good. Better is to use intl extension and add extra check if is installed.
Another alternative is to combine all the methods and add checks then use available version.

And btw don't use global variables.. In v8/v9 define em with $locale = fusion_get_locale();
0 replies
E
Ernst74
E
  • Junior Member, joined since
  • Contributed 32 posts on the community forums.
  • Started 14 threads in the forums
answered
Junior Member

There is a $locale['shortmonths'] but where in V8 or V9 is used shortmonth?

If you will do it for all, you must do ist for days and shortdays too.

An englisch monthname on a date is bad on sites with other languages.
0 replies
— 2 months later —
S
Systemweb
S
  • Junior Member, joined since
  • Contributed 22 posts on the community forums.
  • Started 6 threads in the forums
answered
Junior Member

Based on Ernst74's proposal i changed this part to following:
function format_date($format, $time) {
   $locale = fusion_get_locale();
   $settings = fusion_get_settings();
   
   $format = str_replace(
 ['%a', '%A', '%d', '%e', '%u', '%w', '%W', '%b', '%h', '%B', '%m', '%y', '%Y', '%D', '%F', '%x', '%n', '%t', '%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X', '%z', '%Z', '%c', '%s', '%%'],
 ['D', 'l', 'd', 'j', 'N', 'w', 'W', 'M', 'M', 'F', 'm', 'y', 'Y', 'm/d/y', 'Y-m-d', 'm/d/y', "n", "t", 'H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s', 'O', 'T', 'D M j H:i:s Y', 'U', '%'],
 $format
 );

 $date = DateTimeImmutable::createFromFormat('U', $time);
   
   if ($settings['locale'] != "English") {
      // Replacer arrays
      $search_months_long = " |January|February|March|April|May|June|July|August|September|October|November|December";
      $search_months_short ="&nbps;|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sept|Oct|Nov|Dec";
      $search_weekdays_long = "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday";
      $search_weekdays_short = "Sun|Mon|Tue|Wed|Thu|Fri|Sat";
      if (IsSet($locale['shortweekdays'])) {
         $search = explode("|", ($search_months_long."|".$search_months_short."|".$search_weekdays_long."|".$search_weekdays_short));
         $replace= explode("|", ($locale['months']."|".$locale['shortmonths']."|".$locale['weekdays']."|".$locale['shortweekdays']));
      }
      else {
         $search = explode("|", ($search_months_long."|".$search_months_short."|".$search_weekdays_long));
         $replace= explode("|", ($locale['months']."|".$locale['shortmonths']."|".$locale['weekdays']));
      }
      return str_replace($search, $replace, $date->format($format));      
   }

   else {
      return $date->format($format);
   }
}

I also added 1 line to locale definitions in global.php to support short weekdays names:
$locale['shortweekdays'] = "Sun|Mon|Tue|Wed|Thu|Fri|Sat";
(used only in other languages than english)
Edited by Systemweb on 20-04-2022 16:38,
0 replies

Category Forum

Locales Forum - 9

Labels

None yet

Statistics

  • Views 0 views
  • Posts 7 posts
  • Votes 0 votes
  • Topic users 4 members

4 participants

B
B
BenL 12
  • Member, joined since
  • Contributed 96 posts on the community forums.
  • Started 41 threads in the forums
  • Started this discussions
S
S
  • Junior Member, joined since
  • Contributed 22 posts on the community forums.
  • Started 6 threads in the forums
R
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
E
E
  • Junior Member, joined since
  • Contributed 32 posts on the community forums.
  • Started 14 threads in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet