The locale for my installation is set to nl-NL (visible in Paper UI). However, if I format a DateTime item to show textual day of the week or month name, I get the english text, e.g. “Saturday” and “February”. It looks like the java formatter does not respect the OH setting. My Raspberry Pi uses the en_GB locale. My guess is, this is used by Java.
I don’t want to change the locale of my OS. Instead (for testing purposes) I modified the karaf launch script /usr/share/openhab2/runtime/bin/karaf and added these lines:
-Duser.country=NL \
-Duser.language=nl \
After a restart, my Java is now running with the Dutch locale.
However, I am afraid that this file will be overwritten after an update.
So the question is, is there a way (file, environment variable) to hook into the script?
Responding to an old topic as this is the top result on how to use another locale for OpenHAB than the system default.
Yes, as you write we only need to set the -D options in an enivronment variable before starting the script. How that is best done will depend on your type of installation and personal preferences. One way is to set the KARAF_OPTS shell variable as that is added to the command line by the service startup script.
For example, in Openhabian you can add these lines to the startup script /etc/default/openhab2, preferably just below the JAVA_OPTIONS section:
Then restart OpenHAB. It will now use your favourite locale (in this case Swedish). This seems to work well with Basic UI. However I see no effect on the Paper UI “Control” page. YMMV.
As usual with locales, the locale must be generated before it can be used. If using Openhabian just sudo openhabian-config then select System Settings | Set System Locale and enable your preferred country/language combo in the list, e.g. sv_SE.UTF-8. (But don’t change the system default.)