How to get locale and country?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
roland65
Posts: 32
Joined: Tue Oct 18, 2011 6:41 pm

How to get locale and country?

Post 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
Last edited by RoryOF on Tue Feb 06, 2018 3:32 pm, edited 1 time in total.
Reason: Added [Code] tags [RoryOF, Moderator]
LibreOffice 7.5.x on Ubuntu
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to get locale and country?

Post by RoryOF »

See
https://www.openoffice.org/api/docs/com ... ocale.html

I think you need also to get the Country
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to get locale and country?

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply