How to get locale and country?

Creating a macro - Writing a Script - Using the API

How to get locale and country?

Postby roland65 » Tue Feb 06, 2018 3:26 pm


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,

Code: Select all   Expand viewCollapse view
' Get application locale
' Author : Laurent Godard
' e-mail :
Function GetLocale() as string

   Dim oSet as Variant, oConfigProvider as Variant
   Dim oParm(0) As New
   Dim sProvider as String, sAccess as String
   sProvider = ""
   sAccess   = ""
   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 5.x on Ubuntu
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: How to get locale and country?

Postby RoryOF » Tue Feb 06, 2018 3:33 pm

Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
Posts: 29269
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to get locale and country?

Postby Villeroy » Tue Feb 06, 2018 3:46 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Posts: 26975
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests