It is currently March 29th, 2024, 12:54 am

Localized os.date() date strings?

Discuss the use of Lua in Script measures.
Crest
Posts: 113
Joined: August 16th, 2013, 12:47 pm

Localized os.date() date strings?

Post by Crest »

Is there a way that os.date() strings like month/weekday/year names can be automatically localized depending on the language set for either the system or Rainmeter?

For example os.date("%B",os.time()) returns the current full month name (eg: May) in English but what if a user has their system and Rainmeter language set to some other language?

In my testing it seems regardless of OS/Rainmeter language output strings remain English. Also tried os.setlocale("<locale>") but couldn't get anything to work.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Localized os.date() date strings?

Post by SilverAzide »

Crest wrote: May 9th, 2023, 4:56 pm Is there a way that os.date() strings like month/weekday/year names can be automatically localized depending on the language set for either the system or Rainmeter?

For example os.date("%B",os.time()) returns the current full month name (eg: May) in English but what if a user has their system and Rainmeter language set to some other language?

In my testing it seems regardless of OS/Rainmeter language output strings remain English. Also tried os.setlocale("<locale>") but couldn't get anything to work.
The Rainmeter implementation of Lua is English only. If you want localized names, you'll need to use Rainmeter's Time measure.
Gadgets Wiki GitHub More Gadgets...
Crest
Posts: 113
Joined: August 16th, 2013, 12:47 pm

Re: Localized os.date() date strings?

Post by Crest »

SilverAzide wrote: May 9th, 2023, 5:27 pm The Rainmeter implementation of Lua is English only. If you want localized names, you'll need to use Rainmeter's Time measure.
I'm using the Lua for handling conditional date calculations so I suppose the flow would be have some Time measure in the skin then in the script change the measure's timestamp value then read back the measure's localized output for use in the script. Wouldn't be too bad to just have a measure just for this purpose I guess. Will have to test.

Edit: I notice in the Time measure's docs a TimeStampLocale option. Is that necessary to have the strings localized or will they be automatically if that is left unset, depending on the configured OS/Rainmeter language?
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Localized os.date() date strings?

Post by Yincognito »

Crest wrote: May 9th, 2023, 5:44 pmEdit: I notice in the Time measure's docs a TimeStampLocale option. Is that necessary to have the strings localized or will they be automatically if that is left unset, depending on the configured OS/Rainmeter language?
From what I know, the TimeStampLocale is used if you want to SET time to a timestamp in a different language (e.g. you're Italian and you want to set the timestamp to, say, "sabato 26 dicembre 2015"). To GET time in a different language you'll have to use FormatLocale, which can take similar values (e.g. you're English or whatever your TimeStampLocale sets your input to be, but you want to get the output time in Italian, like "sabato 26 dicembre 2015"). See the code here for reference - feel free to add TimeStampLocale to it, IF you specify the timestamp in that language. Judging from the way FormatLocale is behaving, if left unset, TimeStampLocale will default to an English format.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Localized os.date() date strings?

Post by SilverAzide »

Crest wrote: May 9th, 2023, 5:44 pm I'm using the Lua for handling conditional date calculations so I suppose the flow would be have some Time measure in the skin then in the script change the measure's timestamp value then read back the measure's localized output for use in the script. Wouldn't be too bad to just have a measure just for this purpose I guess. Will have to test.

Edit: I notice in the Time measure's docs a TimeStampLocale option. Is that necessary to have the strings localized or will they be automatically if that is left unset, depending on the configured OS/Rainmeter language?
Yincognito is correct. For the Lua, you don't need to do too much back and forth. Do whatever calcs you need in your Lua script and return the result as a numeric timestamp (a number). You should be able to do this with some inline Lua, as in:

Code: Select all

TimeStamp=([&YourLuaScriptMeasure:YourDateFunction()])
FormatLocale=Local
Just don't forget that Lua dates are Unix timestamps, while Rainmeter uses Windows timestamps. There's a snippet for converting between the two.
Gadgets Wiki GitHub More Gadgets...