It is currently November 15th, 2019, 3:46 am

correct time/date format for a users locale

Tips and Tricks from the Rainmeter Community
User avatar
moshi
Posts: 1851
Joined: November 13th, 2012, 9:53 pm

correct time/date format for a users locale

moshi » July 30th, 2013, 12:32 pm

as time formats like %#c or %#x do not work for non-English users (or maybe more specifically non-US users, or maybe for nobody), one can also read those formats from the registry and use substitute to convert them to a format Rainmeter can use.

like this:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=1

[MeasureLongDate]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=sLongDate
UpdateDivider=-1
RegExpSubstitute=1
Substitute="\bM\b":"%#mk","\bMM\b":"%mk","\bMMM\b":"%bk","\bMMMM\b":"%Bk","\bd\b":"%#dk","\bdd\b":"%dk","\bddd\b":"%ak","\bdddd\b":"%Ak","\byy\b":"%yk","\byyyy\b":"%Yk","k":""

[MeasureShortDate]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=sShortDate
UpdateDivider=-1
RegExpSubstitute=1
Substitute="\bM\b":"%#mk","\bMM\b":"%mk","\bMMM\b":"%bk","\bMMMM\b":"%Bk","\bd\b":"%#dk","\bdd\b":"%dk","\bddd\b":"%ak","\bdddd\b":"%Ak","\byy\b":"%yk","\byyyy\b":"%Yk","k":""

[MeasureTimeFormat]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=sTimeFormat
UpdateDivider=-1
RegExpSubstitute=1
Substitute="\bh\b":"%#Ik","\bhh\b":"%Ik","\bH\b":"%#Hk","\bHH\b":"%Hk","\bm\b":"%#Mk","\bmm\b":"%Mk","\bs\b":"%#Sk","\bss\b":"%Sk","\bt\b":"%pk","\btt\b":"%pk","k":""

[MeasureShortTime]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=sShortTime
UpdateDivider=-1
RegExpSubstitute=1
Substitute="\bh\b":"%#Ik","\bhh\b":"%Ik","\bH\b":"%#Hk","\bHH\b":"%Hk","\bm\b":"%#Mk","\bmm\b":"%Mk","\bs\b":"%#Sk","\bss\b":"%Sk","\bt\b":"%pk","\btt\b":"%pk","k":""

[MeasureTime]
Measure=Time
Format=%#c

[MeasureTime2]
Measure=Time
Format=[MeasureLongDate] [MeasureTimeFormat]
DynamicVariables=1

[Meterb]
Meter=String
Text="Rainmeter: [MeasureTime]#CRLF#Correct: [MeasureTime2]"
X=0
Y=0
SolidColor=ffffff
DynamicVariables=1
note: this is only about the format, it does not translate. but if you use this the requests for "i want AM/PM", "i want military time", etc. should drop.
User avatar
jsmorley
Developer
Posts: 19710
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: correct time/date format for a users locale

jsmorley » July 30th, 2013, 12:42 pm

Very clever...
User avatar
moshi
Posts: 1851
Joined: November 13th, 2012, 9:53 pm

Re: correct time/date format for a users locale

moshi » August 24th, 2013, 9:55 pm

now that the webparser plugin is dynamic i took this one step further and use the MyMemory api to do the translation. as the results are encoded and i am lazy this is for Latin, Cyrillic and Greek alphabets only. maybe there will be contributors for other scripts.

warning: this api is limited to 100 calls a day, so do not abuse it.

Code: Select all

[Rainmeter]
AccurateText=1
Update=1000
DynamicWindowSize=1
OnWakeAction=[!SetOption MeasureTranslate Url "http://mymemory.translated.net/api/get?q=[MeasureTime]&langpair=en|[MeasureLanguage]"][!EnableMeasure MeasureTranslate][!CommandMeasure MeasureTranslate Update]

[MeasureLanguage]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=LocaleName
UpdateDivider=-1

[MeasureLongDate]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=sLongDate
UpdateDivider=-1
RegExpSubstitute=1
Substitute="\bM\b":"%#mk","\bMM\b":"%mk","\bMMM\b":"%bk","\bMMMM\b":"%Bk","\bd\b":"%#dk","\bdd\b":"%dk","\bddd\b":"%ak","\bdddd\b":"%Ak","\byy\b":"%yk","\byyyy\b":"%Yk","k":""

[MeasureTimeFormat]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\International
RegValue=sTimeFormat
UpdateDivider=-1
RegExpSubstitute=1
Substitute="\bh\b":"%#Ik","\bhh\b":"%Ik","\bH\b":"%#Hk","\bHH\b":"%Hk","\bm\b":"%#Mk","\bmm\b":"%Mk","\bs\b":"%#Sk","\bss\b":"%Sk","\bt\b":"%pk","\btt\b":"%pk","k":""

[MeasureTime]
Measure=Time
Format=[MeasureLongDate]
DynamicVariables=1

[MeasureTime2]
Measure=Time
Format=[MeasureTimeFormat]
DynamicVariables=1

[MeasureFirstLaunch]
Measure=Time
OnChangeAction=[!DisableMeasure MeasureFirstLaunch][!SetOption MeasureTranslate Url "http://mymemory.translated.net/api/get?q=[MeasureTime]&langpair=en|[MeasureLanguage]"][!EnableMeasure MeasureTranslate][!CommandMeasure MeasureTranslate Update]
Disabled=0
DynamicVariables=1

[MeasureDayChange]
Measure=Time
Format=1%H%M%S
IfEqualValue=1000001
IfEqualAction=[!SetOption MeasureTranslate Url "http://mymemory.translated.net/api/get?q=[MeasureTime]&langpair=en|[MeasureLanguage]"][!EnableMeasure MeasureTranslate][!CommandMeasure MeasureTranslate Update]
DynamicVariables=1

[MeasureTranslate]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=""
RegExp="(?siU)(?(?=.*"translatedText").*"translatedText":"(.*)")"
Debug=1
StringIndex=1
DecodeCharacterReference=1
DynamicVariables=1
RegExpSubstitute=1
Substitute="^$":"[MeasureTime]","\\u00c4":"Ä","\\u00e4":"ä","\\u00d6":"Ö","\\u00f6":"ö","\\u00dc":"Ü","\\u00fc":"ü","\\u00df":"ß","\\u0401":"Ё","\\u0451":"ё","\\u0410":"А","\\u0411":"Б","\\u0412":"В","\\u0413":"Г","\\u0414":"Д","\\u0415":"Е","\\u0416":"Ж","\\u0417":"З","\\u0418":"И","\\u0419":"Й","\\u041a":"К","\\u041b":"Л","\\u041c":"М","\\u041d":"Н","\\u041e":"О","\\u041f":"П","\\u0420":"Р","\\u0421":"С","\\u0422":"Т","\\u0423":"У","\\u0424":"Ф","\\u0425":"Х","\\u0426":"Ц","\\u0427":"Ч","\\u0428":"Ш","\\u0429":"Щ","\\u042a":"Ъ","\\u042b":"Ы","\\u042c":"Ь","\\u042d":"Э","\\u042e":"Ю","\\u042f":"Я","\\u0430":"а","\\u0431":"б","\\u0432":"в","\\u0433":"г","\\u0434":"д","\\u0435":"е","\\u0436":"ж","\\u0437":"з","\\u0438":"и","\\u0439":"й","\\u043a":"к","\\u043b":"л","\\u043c":"м","\\u043d":"н","\\u043e":"о","\\u043f":"п","\\u0440":"р","\\u0441":"с","\\u0442":"т","\\u0443":"у","\\u0444":"ф","\\u0445":"х","\\u0446":"ц","\\u0447":"ч","\\u0448":"ш","\\u0449":"щ","\\u044a":"ъ","\\u044b":"ы","\\u044c":"ь","\\u044d":"э","\\u044e":"ю","\\u044f":"я","\\u00b0":"°","\\u003c":"<","\\u003e":">","\\u00ab":"«","\\u0259":"ə","\\u00e5":"å","\\u00c5":"Å","\\u00f8":"ø","\\u00d8":"Ø","\\u00e6":"æ","\\u00c6":"Æ","\\u0153":"œ","\\u0152":"Œ","\\u00e0":"à","\\u00c0":"À","\\u00e9":"é","\\u00c9":"É","\\u00e8":"è","\\u00c8":"È","\\u00e1":"á","\\u00c1":"Á","\\u00f4":"ô","\\u00d4":"Ô","\\u011b":"ě","\\u011a":"Ě","\\u0161":"š","\\u0160":"Š","\\u017e":"ž","\\u017d":"Ž","\\u0148":"ň","\\u0147":"Ň","\\u0458":"ј","\\u0408":"Ј","\\u00ed":"í","\\u00cd":"Í","\\u0159":"ř","\\u0158":"Ř","\\u015b":"ś","\\u015a":"Ś","\\u00f0":"ð","\\u00d0":"Ð","\\u00a3":"£","\\u00eb":"ë","\\u00cb":"Ë","\\u00f3":"ó","\\u00d3":"Ó","\\u0144":"ń","\\u0143":"Ń","\\u0142":"ł","\\u0141":"Ł","\\u0119":"ę","\\u0118":"Ę","\\u015f":"ş","\\u015e":"Ş","\\u011f":"ğ","\\u011e":"Ğ","\\u017c":"ż","\\u017b":"Ż","\\u0080":"€","\\u0099":"™","\\u00ae":"®","\\u0105":"ą","\\u0104":"Ą","\\u00e3":"ã","\\u00c3":"Ã","\\u010d":"č","\\u010c":"Č","\\u0111":"đ","\\u0110":"Đ","\\u045a":"њ","\\u040a":"Њ","\\u0107":"ć","\\u0106":"Ć","\\u00e7":"ç","\\u00c7":"Ç","\\u0131":"ı","\\u0130":"İ","\\u00ec":"ì","\\u00cc":"Ì","\\u00fa":"ú","\\u00da":"Ú","\\u00ea":"ê","\\u00ca":"Ê","\\u1ecd":"ọ","\\u1ecc":"Ọ","\\u00f2":"ò","\\u00d2":"Ò","\\u01b0":"ư","\\u01af":"Ư","\\u1ea7":"ầ","\\u1ea6":"Ầ","\\u01a1":"ơ","\\u01a0":"Ơ","\\u1ec1":"ề","\\u1ec0":"Ề","\\u1ea3":"ả","\\u1ea2":"Ả","\\u1ea1":"ạ","\\u1ea0":"Ạ","\\u1ee5":"ụ","\\u1ee4":"Ụ","\\u1ebf":"ế","\\u1ebe":"Ế","\\u1eb1":"ằ","\\u1eb0":"Ằ","\\u1ec3":"ể","\\u1ec2":"Ể","\\u0169":"ũ","\\u0168":"Ũ","\\u0103":"ă","\\u0102":"Ă","\\u1edd":"ờ","\\u1edc":"Ờ","\\u0129":"ĩ","\\u0128":"Ĩ","\\u1ec7":"ệ","\\u1ec6":"Ệ","\\u1eeb":"ừ","\\u1eea":"Ừ","\\u1ed1":"ố","\\u1ed0":"Ố","\\u1ee3":"ợ","\\u1ee2":"Ợ","\\u1ed9":"ộ","\\u1ed8":"Ộ","\\u1ead":"ậ","\\u1eac":"Ậ","\\u1ed3":"ồ","\\u1ed2":"Ồ","\\u00f9":"ù","\\u00d9":"Ù","\\u00e2":"â","\\u00c2":"Â","\\u1ec5":"ễ","\\u1ec4":"Ễ","\\u1ed5":"ổ","\\u1ed4":"Ổ","\\u1eed":"ử","\\u1eec":"Ử","\\u1ef7":"ỷ","\\u1ef6":"Ỷ","\\u1edf":"ở","\\u1ede":"Ở","\\u1ebb":"ẻ","\\u1eba":"Ẻ","\\u1eb7":"ặ","\\u1eb6":"Ặ","\\u1ea5":"ấ","\\u1ea4":"Ấ","\\u1ecb":"ị","\\u1eca":"Ị","\\u00f5":"õ","\\u00d5":"Õ","\\u1ecf":"ỏ","\\u1ece":"Ỏ","\\u1eb5":"ẵ","\\u1eb4":"Ẵ","\\u0151":"ő","\\u0150":"Ő","\\u1ef9":"ỹ","\\u1ef8":"Ỹ","\\u1edb":"ớ","\\u1eda":"Ớ","\\u1eaf":"ắ","\\u1eae":"Ắ","\\u1ef1":"ự","\\u1ef0":"Ự","\\u045b":"ћ","\\u040b":"Ћ","\\u0459":"љ","\\u0409":"Љ","\\u00fd":"ý","\\u00dd":"Ý","\\u1ed7":"ỗ","\\u1ed6":"Ỗ","\\u1eb3":"ẳ","\\u1eb2":"Ẳ","\\u1ee7":"ủ","\\u1ee6":"Ủ","\\u03b1":"α","\\u0391":"Α","\\u03b2":"β","\\u0392":"Β","\\u03b3":"γ","\\u0393":"Γ","\\u03b4":"δ","\\u0394":"Δ","\\u03b5":"ε","\\u0395":"Ε","\\u03b6":"ζ","\\u0396":"Ζ","\\u03b7":"η","\\u0397":"Η","\\u03b8":"θ","\\u0398":"Θ","\\u03b9":"ι","\\u0399":"Ι","\\u03ba":"κ","\\u039a":"Κ","\\u03bb":"λ","\\u039b":"Λ","\\u03bc":"μ","\\u039c":"Μ","\\u03bd":"ν","\\u039d":"Ν","\\u03be":"ξ","\\u039e":"Ξ","\\u03bf":"ο","\\u039f":"Ο","\\u03c0":"π","\\u03a0":"Π","\\u03c1":"ρ","\\u03a1":"Ρ","\\u03c2":"ς","\\u03c3":"σ","\\u03a3":"Σ","\\u03c4":"τ","\\u03a4":"Τ","\\u03c5":"υ","\\u03a5":"Υ","\\u03c6":"φ","\\u03a6":"Φ","\\u03c7":"χ","\\u03a7":"Χ","\\u03c8":"ψ","\\u03a8":"Ψ","\\u03c9":"ω","\\u03a9":"Ω","\\u03ca":"ϊ","\\u03aa":"Ϊ","\\u03cb":"ϋ","\\u03ab":"Ϋ","\\u03ac":"ά","\\u0386":"Ά","\\u03ad":"έ","\\u0388":"Έ","\\u03ae":"ή","\\u0389":"Ή","\\u03af":"ί","\\u038a":"Ί","\\u03b0":"ΰ","\\u0390":"ΐ","\\u0385":"ΐ","\\u038c":"Ό","\\u03cc":"ό","\\u03cd":"ύ","\\u038e":"Ύ","\\u03ce":"ώ","\\u038f":"Ώ"
Disabled=1
FinishAction=[!UpdateMeter *][!Redraw][!DisableMeasure MeasureTranslate]

[MeterDate]
Meter=String
Text="[MeasureTranslate]"
X=0
Y=0
FontColor=ffffff
FontSize=20
FontFace=SegoeUI
SolidColor=00000050
DynamicVariables=1
Antialias=1
StringStyle=Bold
Padding=10,10,10,10
StringCase=Proper

[MeterTime]
Meter=String
Text="[MeasureTime2]"
X=R
Y=r
FontColor=ffffff
FontSize=20
FontFace=SegoeUI
SolidColor=00000050
DynamicVariables=1
Antialias=1
StringStyle=Bold
Padding=10,10,10,10
StringCase=Proper


(INI needs to be UTF-16 Little Endian encoded of course)
User avatar
moshi
Posts: 1851
Joined: November 13th, 2012, 9:53 pm

Re: correct time/date format for a users locale

moshi » November 4th, 2013, 11:34 am

another nice method to work around the time measure's non-working locale codes is using Brian's new RunCommand plugin.

Code: Select all

[Rainmeter]
BackgroundMode=1
DynamicWindowSize=1
OnWakeAction=[!Refresh]
OnRefreshAction=[!CommandMeasure Calendar_C1 Run][!CommandMeasure Calendar_C2 Run]
Update=1000
AccurateText=1

[MeasureCurrent]
Measure=Time
Format=%H%M%d%m%Y
OnChangeAction=[!CommandMeasure Calendar_C1 Run][!CommandMeasure Calendar_C2 Run]

[Calendar_C1]
Measure=Plugin
Plugin=RunCommand
Parameter=date /T
FinishAction=[!UpdateMeter Output1][!Redraw]

[Calendar_C2]
Measure=Plugin
Plugin=RunCommand
Parameter=time /T
FinishAction=[!UpdateMeter Output1][!Redraw]

[Output1]
MeasureName=Calendar_C1
MeasureName2=Calendar_C2
Text="%1%2"
Meter=STRING
UpdateDivider=-1