[bug-16147]dateFormat() locale

Hi,

Is there a way to display the expression :

dateFormat(now(0), "EEEE dd MMMM YYYY") )

in a given locale (french in my case) when java machine is in a different locale (english in my case)?

I also made few test on a VM with french java machine, try to set the wrapper localization in ignition.conf file with

wrapper.lang=en_US

then restart service but the date still remain in french.

any idea about this behavior?

Thanks

Where are you trying to use this expression? In a client, I bound the text of a label to the expression you have above and dropped a language selector component on the window. When I change the language selected, the display changes from
Friday 06 March 2020
to
vendredi 06 mars 2020

You should also be able to use system.util.setLocale(), although I didn’t test this.

Hi,
Thanks for your prompt,
I forgot to specify that I am in perspective and directly set the locale in the session props

self.session.props.locale = "fr-FR"
or
self.session.props.locale = "en-EN"

Create a custom session property (I used ‘session.custom.today’), then use a script transform:

	from java.text import SimpleDateFormat
	from java.util import Locale
	
	# Set locale dictionary. Using Locale.variants() doesn't always work, 
	# so we use a dictionary to force the locale.

	localeDict = {
	              'fr-FR' : Locale.FRENCH, 
	              'en-EN' : Locale.ENGLISH
	             }
	
	langFormat= SimpleDateFormat('EEEE dd MMMM YYYY', localeDict[self.props.locale]) # The format you want to convert to
	return langFormat.format(value)

English:

French:

Expression Binding:

1 Like

I’ll make the argument this is a bug; dateFormat from Perspective “should” be using the session locale prop instead of having to use @JordanCClark’s admittedly clever workaround. I filed a ticket.

1 Like

Hi,

Thank you @KathyApplebaum @JordanCClark and @PGriffith for your prompt attention to the subject.
I will use the given tip while waiting for a bug fix.

Regards,

Pierre.