Locales

Hi all,

is there a chance to check if a locale exists?

GetLocale() show the current locale
GetLocaleInfo() shows addition informations to the current locale
SetLocale( "zw_CH" ) throws an exception as zw_CH is invalid

WriteDump(server.coldfusion.supportedlocales) shows a list of locales but i prefer the shortnames (e.g. “FR_CH” instead of “french (switzerland)”.).

Is there a chance to validate if “fr_CH” exists without try/catches? Is there a way to rewrite the long supportedlocales to shortnames (without looping and getLocaleInfo for each longname?)?

Don’t forget to tell us about your stack!

OS: linux / windows / docker
Java Version: 11.0.16 (Oracle Corporation) 64bit
Tomcat Version: Apache Tomcat/9.0.65
Lucee Version: Lucee 5.3.9.166

You could use Java. Something like:

<cfscript>
localesArray=createobject("java","java.text.SimpleDateFormat").getAvailableLocales();
FR_CH_exists=false;

arrayEach(localesArray,
	function(locale) {
		// List all locales
		//writeoutput("Locale=" & locale.toString() & ', ' & "Locale Display Name=" & locale.getDisplayName() & ', ' & "Locale Display Country=" & locale.getDisplayCountry() & "<br>");
		
		// Look for locale "FR_CH"
		if(locale.toString()=="FR_CH"){
				FR_CH_exists=true;		
				break;
		}
	}
);

writeoutput("FR_CH_exists: " & FR_CH_exists);
</cfscript>

Lucee Version : Lucee 5.3.9.166