Page 1 of 1

How to get locale and country?

Posted: Tue Feb 06, 2018 3:26 pm
by roland65
Hi,

I use the GetLocale() macro from Andrew Macros to get the locale name of the system (see code below).

A brazilian user of my applications (TexMaths) has a 'pt_BR' locale, but the GetLocale() macro only returns 'pt'. So, it's not possible to distinguish between portuguese and brazilian portuguese.

Is there a way to get the complete locale name or, at least, the country name?

Any help much appreciated,
RB

Code: Select all

' Get application locale
' Author : Laurent Godard
' e-mail : listes.godard@laposte.net
Function GetLocale() as string

	Dim oSet as Variant, oConfigProvider as Variant
	Dim oParm(0) As New com.sun.star.beans.PropertyValue
	Dim sProvider as String, sAccess as String
	
	sProvider = "com.sun.star.configuration.ConfigurationProvider"
	sAccess   = "com.sun.star.configuration.ConfigurationAccess"
	
	oConfigProvider = createUnoService(sProvider)
	oParm(0).Name = "nodepath"
	oParm(0).Value = "/org.openoffice.Setup/L10N"
	oSet = oConfigProvider.createInstanceWithArguments(sAccess, oParm())
	
	Dim str as String
	
	str = oSet.getbyname("ooLocale")

	print str

GetLocale() = str

End Function

Re: How to get locale and country?

Posted: Tue Feb 06, 2018 3:33 pm
by RoryOF
See
https://www.openoffice.org/api/docs/com ... ocale.html

I think you need also to get the Country

Re: How to get locale and country?

Posted: Tue Feb 06, 2018 3:46 pm
by Villeroy
These settings are named in misleading ways.
1) ooLocale is the language of the user interface, help files, names of spreadsheet functions and several other named items.
2) ooSetupSystemLocale is the item which is actually called "Locale" in the options dialog. This is the context of numeric expressions (decimal, date, time and thousands separators, month names, weekday names, currencies, boolean "true"|"false" etc.). This locale can be switched to any supported locale without installing a language pack. It reports pt-BR with LO5.
A brazilian user of my applications (TexMaths) has a 'pt_BR' locale, but the GetLocale() macro only returns 'pt'.
I would think, the missing info is an issue with the Brazilian localization.