Jump to content

How to translate the names of months?


Recommended Posts

Posted (edited)

Maybe I am missing something, but I can't find a way to translate the names of months that are shown in invoices to my language.
Same goes for weekdays.

The only language in my shop is German, frontend and admin, but all monthnames and weekdays are shown in English

I can't find it in "Languages" in Admin and also did filesearches as well as in the database.

Please help, thanks! 

Edited by MostlyConfused
Link to comment
Share on other sites

As far as I know about PHP (whether CubeCart accurately implements this?), the code would set a locale which would then cause other PHP formatting functions to use the appropriate words and numerical syntax for that location/language.

However, since CubeCart micromanages the currency syntax (symbol, comma, period, etc), I have not really looked at how CubeCart uses PHP to show numerical syntax.

The language files do not contain those terms.

Link to comment
Share on other sites

15 hours ago, bsmither said:

As far as I know about PHP (whether CubeCart accurately implements this?), the code would set a locale which would then cause other PHP formatting functions to use the appropriate words and numerical syntax for that location/language.

I think you are right, especially since nobody else seems to have this problem.

The date used in the bills is {$order.order_date}
If I debug, the content is for instance "30 May 2021, 09:08" in plain text, not as a timestamp.

I tried brute-forcing it, by inserting a php setlocale statement into main.php and main.checkout.php, but as expected this did not work.

Do you have any idea what else I could try?
In store settings, country is set to Austria and language to German. I went through all options a couple of times, but could not find anything else to set.

Link to comment
Share on other sites

Update: I think I found it.

And I am pretty sure, this is a bug.

In classes/language.class.php there is a function to set the locale.

And it was hardcoded to 

setlocale(LC_ALL, 'en_EN.UTF-8');

I changed it to de_DE and immediately I get the month names in german.

@Al Brookbanks please check this, 6.4.2.

setlocale.png

Link to comment
Share on other sites

Hello, I just tested on my store with: fr_FR.UTF-8
And after clearing the cache no change.
After leaving the administrator, I wanted to come back and I got a blank page. I had to put the original file back. I am in Cubecart 6.4.3

Link to comment
Share on other sites

Posted (edited)

Anything in the error_log?

Please read through the comments at:

https://www.php.net/manual/en/function.setlocale

to determine if there is anything that pertains to your server environment.

Edited by bsmither
Link to comment
Share on other sites

Maybe the error got logged to CubeCart's admin, Error Log, System Error Log tab.

If possible, at a system prompt (Linux), the command:

locale -a

On my server, it returns:

en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8

So, trying to setlocale() to a different language will not work for my development server. (Whether it will crash PHP or not, I do not know.)

Link to comment
Share on other sites

14 minutes ago, bsmither said:

So, trying to setlocale() to a different language will not work for my development server. (Whether it will crash PHP or not, I do not know.)

Trying to set a "wrong" locale should not crash PHP or have any other effect than just not setting it.
By default, PHP tries to set given locale(s) until one works, and if not defaults to NULL

For example, my change above would work on the live Linux server, but not on my local WAMP.
I just added another parameter for Windows and now it works on both:
 

setlocale(LC_ALL, 'de_DE.UTF-8', 'German');

If you get a white screen or something, there's likely to be a syntax error somewere.
 

Link to comment
Share on other sites

Posted (edited)

Update to my own answer above:

I suddendly get the same effect, blank screen when I log in and resetting it back to "en_EN" instead of  "de_DE" made it work again.

If I am LOGGED IN and upload the file with changed locale, it works and month names are shown in German.
As soon as I LOG OUT I can NOT log in again, until I change the locale back.

At the same time, in cc_CubeCart_system_error_log the following error is created:

[<strong>Exception</strong>]     /home/.sites/188/site7252192/web/shop/classes/session.class.php:609 - DateTime::__construct() [<a href='http://docs.php.net/manual/en/datetime.construct.php'>datetime.construct.php</a>]: Failed to parse time string (Mo 31 Mai 2021 22:19:21 UTC) at position 0 (M): The timezone could not be found in the database

Something's really fishy here. It clearly works and shows the correct date and time before logout. Why the error ONLY when I log in again? 

Since this is clearly a bug, it would be nice if @Al Brookbanks would chime in! 

The error it shows happens during setting of cookie in session.class.php:

 

cookies.jpg

Edited by MostlyConfused
Link to comment
Share on other sites

  • 2 weeks later...

Update:

Since Al does not give a hoot about his bugs and all workarounds I tried did not work, I had to resort to a really dirty hack, but at least it works so far.

I changed the template for the printed bill like this:

At the beginning, I put:

{$datefind = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug','Sep', 'Oct', 'Nov','Dec']}
{$daterepl = ['Jan.', 'Feb.', 'März', 'Apr.', 'Mai', 'Juni','Juli', 'Aug.', 'Sep.','Okt.', 'Nov.', 'Dez.']}

And further down, where the date is actually printed, I replaced

{$order.order_date}

with

{$order.order_date|replace:$datefind:$daterepl}

@fabriceunko, maybe this will be a solution for you as well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...