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.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Navigation

No translating for months names on forum

Last updated on 3 years ago
B
BenLMember
Posted 3 years ago
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, 3 years ago
R
Anonymous UserVeteran Member
Posted 3 years ago
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.
B
BenLMember
Posted 3 years ago
hi @RobiNN, thanks for sharing with those all details. So i assume that nothing can be done for this for this moment?
E
Ernst74Junior Member
Posted 3 years ago
Why can not use the locale for month?

English locale = array_1
locale form settings = array_2
str_replace(array_1, array_2, $output);
E
Ernst74Junior Member
Posted 3 years ago
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, 3 years ago
R
Anonymous UserVeteran Member
Posted 3 years ago
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();
E
Ernst74Junior Member
Posted 3 years ago
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.
S
SystemwebJunior Member
Posted 3 years ago
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, 3 years ago
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
You cannot set up a bounty in this discussion thread.
Moderator: Support Team
Users who participated in discussion: BenL, Systemweb, RobiNN, Ernst74