Convert and show day & date on Sitemap

I am almost sorry to ask this question but I just cannot work it out…
Still using openHAB 2.5.8 on PI3 / Raspbian GNU/Linux 10 (buster)

Trying to show on the sitemap date with weekday but weekday in German, similar to

using this item:

DateTime Date  		"Date: [%1$tA, %1$td.%1$tm.%1$tY]"	<calendar>	{ channel="ntp:ntp:zeit:dateTime", autoupdate="true" }

in the sitemap

Text item=Date label="Heute ist [%1$tA, %1$td.%1$tm.%1$tY]"

If I try to map the english weekdays to german via a mapping table in the sitemap:

Text item=Date label="Heute ist [MAP($tA, %1$td.%1$tm.%1$tY]"

I get empty spaces

instead, if I use 2 separate items, it works:

Text item=Date label="Datum [%1$td.%1$tm.%1$tY]"
Text item=Date label="Heute ist [MAP($tA]"

What do I miss? How can I do it in one item / one line with translated weekday?

Thanks a lot!

Have you tried setting your Java system language to German?

Hi @rossko57 ,
thanks for your fast answer.
No (do not know how to do it) but anyway, I am not a friend of setting system parameters to other languages than english, if it can be avoided …

Alright, then I think you’ll have to create your own unique transformation.

The %1$tA, %1$td.%1$tm.%1$tY stuff is carried out by the Java formatter, and if you will not change the language/locale of that then it cannot do what you want.

Performing a MAP or other transformation in the display operates on the whole Item state, it is not possible to MAP just a little part of a datetime state.

Javascript JS transform allows you to write flexible code to do whatever you want.
This will receive the raw unformatted datetime state as a string, then you can manipulate the string as you want.
It’ll be like 2021-10-13T12:07:05.004+0100 so you’ll have to work out the weekday for yourself.
The easiest way would be to parse the input string into a javascript date object, then you can format that with whatever javascript snippets you can find.

// variable "input" contains string passed by OpenHAB
(function(i) {
    var log = Java.type("org.slf4j.LoggerFactory").getLogger("org.eclipse.smarthome.automation.mytransform");"script begins with i " + i); // openhab format 2021-10-13T13:13:05.004+01:00
    var idate = new Date(Date.parse(i)) ;  // returns a Date object"parsed i " + idate.toString()); // js format Wed Oct 13 2021 13:13:05 GMT+0100 (BST)

    var options = { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }; // set up format"DE formatted i " + idate.toLocaleDateString("de-DE", options));

    return  idate.toLocaleDateString("de-DE", options) ;

The logging is just for experimenting, you can remove that when it works.

toLocaleDateString() did not work very well for me, but it depends what javascript version you have. Try it out.
If no good, you’ll have to find an old javascript snippet doing it the long way, looking up weekday strings in arrays.

Wow, that is very sophisticated.
I must confess I am not very deep into JS but I understand where this goes to.
To be honest I should now ask:
Where do I write the function (just in a .js file in the “scripts” folder?) and how do I call it from the I guess .items file?

Another idea would be to concatenate the content of the 2
Text item=Date label=“Datum [%1$td.%1$tm.%1$tY]”
Text item=Date label=“Heute ist [MAP($tA]”
into another var and then just display that on the sitemap.
But I was failing to do this …
Would be interesting anyway how to do that (put content of an item into a var and then display the var).

Javascript can be used in various places like rules, but if you want to use it as a transformation on a label, then you put it in the /transform folder just like you did your MAP file.
You can specify where to use it in the [state presentation] part of your Item label, just like you did your MAP directive.

(OH3 users have to a little differently)

You can’t.
You can only display Item states.
You can of course process some Item states in a rule, and then postUpdate the result to some other Item.
You can transform an Item state for display, but you only get the one Item state to process and cannot reference other Items in that context.
Doing it in a rule gives you access to all Items.