Page 1 of 1

[Basic, Python] Reporting all number format locales

Posted: Sun Nov 30, 2014 2:45 pm
by Villeroy
2019-03-27: Added an easy to use Python installer.
The following code dumps info about all number format locales into a new spreadsheet. In addition it formats the first 1024 columns of each row (until column IV) in the "General" number format of the respective locale so you can test the input patterns and default appearance of dates and times etc.

Code: Select all

Sub printAllLocalesToNewSpreadSheet()
Dim oDoc, oSheet, i18n, oInfo, a(), b(),i%, oItem, nf&, nfs&

oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc","_default",0,Array())
oSheet = oDoc.getSheets().getByIndex(0)
nfs = com.sun.star.i18n.NumberFormatIndex.NUMBER_STANDARD

i18n = createUnoService("com.sun.star.i18n.LocaleData")
a() = i18n.getAllInstalledLocaleNames()
dim r(uBound(a()) +1)

Const cCols = 7
r(0) = Array("Locale","Language","Country","Decimal","Date","Time","1000","List")
For i = 0 to uBound(a())
	oInfo = i18n.getLanguageCountryInfo(a(i))
	oItem = i18n.getLocaleItem(a(i))
	b() = Array( _
		getLocaleString(a(i)), _
		oInfo.LanguageDefaultName, _
		oInfo.CountryDefaultName, _
		oItem.decimalSeparator, _
		oItem.dateSeparator, _
		oItem.timeSeparator, _
		oItem.thousandSeparator, _
		oItem.listSeparator _
	)
	r(i +1) = b()

nf = oDoc.NumberFormats.getStandardIndex(a(i))
oSheet.getCellRangeByPosition(0, i+1, 255, i+1).NumberFormat = nf
next
oSheet.getCellRangeByPosition(0, 0, cCols, uBound(r())).setDataArray(r())
End Sub

Function getLocaleString(oL)
dim s$
s = oL.Language
if len(oL.Country) then
	s = s &"-"& oL.Country
	if len(oL.Variant) then s = s &"-"& oL.Variant
End If
getLocaleString = s
End Function
The Python version of the above StarBasic code can be viewed and installed with the attached text document.