summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2022-02-01 17:30:01 +0100
committerJean-Pierre Ledure <jp@ledure.be>2022-02-01 19:26:49 +0100
commit50696923190add8131f8a2de63ba0ae8e9688d85 (patch)
tree859b07da77c3dbc4850855f4be1bb55c22c619fd /wizards
parent5d05abcc7cb53fd7f7d7ed700e3c65e9da3e5dea (diff)
ScriptForge - (SF_Platform) refine locales
So far, only SF_Platform.Locale was supported, returning the locale of the operating system. Now, 3 different locales may be considered: - SystemLocale: identical to Locale (still supported) - OfficeLocale: the locale associated with the LibreOffice installation - FormatLocale: the locale associated with how numbers and dates are formatted. Of course, in many cases all locales are identical. Anyway a distinction can be made. All these properties are read-only. Those properties are supported in Basic and Python evenly. Change-Id: I0792d49a052b1441a30ac231d61eda997dc4216a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129297 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_Platform.xba39
-rw-r--r--wizards/source/scriptforge/SF_Root.xba8
-rw-r--r--wizards/source/scriptforge/SF_Utils.xba56
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py7
4 files changed, 89 insertions, 21 deletions
diff --git a/wizards/source/scriptforge/SF_Platform.xba b/wizards/source/scriptforge/SF_Platform.xba
index a19ee2bc7a6c..8bd7b5cad35f 100644
--- a/wizards/source/scriptforge/SF_Platform.xba
+++ b/wizards/source/scriptforge/SF_Platform.xba
@@ -83,8 +83,16 @@ Property Get Fonts() As Variant
End Property &apos; ScriptForge.SF_Platform.Fonts (get)
REM -----------------------------------------------------------------------------
+Property Get FormatLocale() As String
+&apos;&apos;&apos; Returns the locale used for number and date formats, combining language-COUNTRY (la-CO)
+&apos;&apos;&apos; Example:
+&apos;&apos;&apos; MsgBox platform.FormatLocale
+ FormatLocale = _PropertyGet(&quot;FormatLocale&quot;)
+End Property &apos; ScriptForge.SF_Platform.FormatLocale (get)
+
+REM -----------------------------------------------------------------------------
Property Get Locale() As String
-&apos;&apos;&apos; Returns the locale combining language-COUNTRY (la-CO)
+&apos;&apos;&apos; Returns the locale of the operating system, combining language-COUNTRY (la-CO)
&apos;&apos;&apos; Example:
&apos;&apos;&apos; MsgBox platform.Locale
Locale = _PropertyGet(&quot;Locale&quot;)
@@ -105,6 +113,14 @@ Property Get ObjectType As String
End Property &apos; ScriptForge.SF_Platform.ObjectType
REM -----------------------------------------------------------------------------
+Property Get OfficeLocale() As String
+&apos;&apos;&apos; Returns the locale of the user interface, combining language-COUNTRY (la-CO)
+&apos;&apos;&apos; Example:
+&apos;&apos;&apos; MsgBox platform.OfficeLocale
+ OfficeLocale = _PropertyGet(&quot;OfficeLocale&quot;)
+End Property &apos; ScriptForge.SF_Platform.OfficeLocale (get)
+
+REM -----------------------------------------------------------------------------
Property Get OfficeVersion() As String
&apos;&apos;&apos; Returns the office software version in the form &apos;LibreOffice w.x.y.z (The Document Foundation)&apos;
&apos;&apos;&apos; Example:
@@ -175,6 +191,14 @@ Property Get ServiceName As String
ServiceName = &quot;ScriptForge.Platform&quot;
End Property &apos; ScriptForge.SF_Platform.ServiceName
+REM -----------------------------------------------------------------------------
+Property Get SystemLocale() As String
+&apos;&apos;&apos; Returns the locale of the operating system, combining language-COUNTRY (la-CO)
+&apos;&apos;&apos; Example:
+&apos;&apos;&apos; MsgBox platform.SystemLocale
+ SystemLocale = _PropertyGet(&quot;SystemLocale&quot;)
+End Property &apos; ScriptForge.SF_Platform.SystemLocale (get)
+
REM ===================================================================== METHODS
REM -----------------------------------------------------------------------------
@@ -228,8 +252,10 @@ Public Function Properties() As Variant
, &quot;CPUCount&quot; _
, &quot;CurrentUser&quot; _
, &quot;Fonts&quot; _
+ , &quot;FormatLocale&quot; _
, &quot;Locale&quot; _
, &quot;Machine&quot; _
+ , &quot;OfficeLocale&quot; _
, &quot;OfficeVersion&quot; _
, &quot;OSName&quot; _
, &quot;OSPlatform&quot; _
@@ -238,6 +264,7 @@ Public Function Properties() As Variant
, &quot;Printers&quot; _
, &quot;Processor&quot; _
, &quot;PythonVersion&quot; _
+ , &quot;SystemLocale&quot; _
)
End Function &apos; ScriptForge.SF_Platform.Properties
@@ -350,8 +377,11 @@ Const cstSubArgs = &quot;&quot;
Next i
&apos; Remove leading and trailing commas
If Len(sFonts) &gt; 1 Then _PropertyGet = Split(Mid(sFonts, 2, Len(sFonts) - 2), &quot;,&quot;) Else _PropertyGet = Array()
- Case &quot;Locale&quot;
- Set oLocale = SF_Utils._GetUNOService(&quot;SystemLocale&quot;)
+ Case &quot;FormatLocale&quot;
+ Set oLocale = SF_Utils._GetUNOService(&quot;FormatLocale&quot;)
+ _PropertyGet = oLocale.Language &amp; &quot;-&quot; &amp; oLocale.Country
+ Case &quot;OfficeLocale&quot;
+ Set oLocale = SF_Utils._GetUNOService(&quot;OfficeLocale&quot;)
_PropertyGet = oLocale.Language &amp; &quot;-&quot; &amp; oLocale.Country
Case &quot;OfficeVersion&quot;
_PropertyGet = _GetProductName()
@@ -371,6 +401,9 @@ Const cstSubArgs = &quot;&quot;
_PropertyGet = sOSName
Case &quot;Printers&quot;
_PropertyGet = _GetPrinters()
+ Case &quot;SystemLocale&quot;, &quot;Locale&quot;
+ Set oLocale = SF_Utils._GetUNOService(&quot;SystemLocale&quot;)
+ _PropertyGet = oLocale.Language &amp; &quot;-&quot; &amp; oLocale.Country
Case Else
_PropertyGet = Null
End Select
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba
index 9d03fcd6f160..d14e121173cd 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -58,7 +58,9 @@ Private CoreReflection As Object &apos; com.sun.star.reflection.CoreReflection
Private DispatchHelper As Object &apos; com.sun.star.frame.DispatchHelper
Private TextSearch As Object &apos; com.sun.star.util.TextSearch
Private SearchOptions As Object &apos; com.sun.star.util.SearchOptions
-Private Locale As Object &apos; com.sun.star.lang.Locale
+Private SystemLocale As Object &apos; com.sun.star.lang.Locale
+Private OfficeLocale As Object &apos; com.sun.star.lang.Locale
+Private FormatLocale As Object &apos; com.sun.star.lang.Locale
Private PrinterServer As Object &apos; com.sun.star.awt.PrinterServer
Private CharacterClass As Object &apos; com.sun.star.i18n.CharacterClassification
Private FileAccess As Object &apos; com.sun.star.ucb.SimpleFileAccess
@@ -118,7 +120,9 @@ Private Sub Class_Initialize()
Set DispatchHelper = Nothing
Set TextSearch = Nothing
Set SearchOptions = Nothing
- Set Locale = Nothing
+ Set OfficeLocale = Nothing
+ Set FormatLocale = Nothing
+ Set SystemLocale = Nothing
Set PrinterServer = Nothing
Set CharacterClass = Nothing
Set FileAccess = Nothing
diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba
index c0d63bcc6b36..cbe07ce2b0ae 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -288,6 +288,23 @@ Const cstConfigUpdate = &quot;com.sun.star.configuration.ConfigurationUpdateAcce
End Function &apos; ScriptForge.SF_Utils._GetRegistryKeyContent
REM -----------------------------------------------------------------------------
+Private Function _GetSetting(ByVal psPreference As String, psProperty As String) As Variant
+&apos;&apos;&apos; Find in the configuration a specific setting based on its location in the
+&apos;&apos;&apos; settings registry
+
+Dim oConfigProvider As Object &apos; com.sun.star.configuration.ConfigurationProvider
+Dim vNodePath As Variant &apos; Array of com.sun.star.beans.PropertyValue
+
+ &apos; Derived from the Tools library
+ Set oConfigProvider = createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
+ vNodePath = Array(SF_Utils._MakePropertyValue(&quot;nodepath&quot;, psPreference))
+
+ _GetSetting = oConfigProvider.createInstanceWithArguments( _
+ &quot;com.sun.star.configuration.ConfigurationAccess&quot;, vNodePath()).getByName(psProperty)
+
+End Function &apos; ScriptForge.SF_Utils._GetSetting
+
+REM -----------------------------------------------------------------------------
Public Function _GetUNOService(ByVal psService As String _
, Optional ByVal pvArg As Variant _
) As Object
@@ -298,9 +315,7 @@ Public Function _GetUNOService(ByVal psService As String _
&apos;&apos;&apos; pvArg: some services might require an argument
Dim sLocale As String &apos; fr-BE f.i.
-Dim oConfigProvider As Object
Dim oDefaultContext As Object
-Dim vNodePath As Variant
Set _GetUNOService = Nothing
With _SF_
@@ -353,6 +368,16 @@ Dim vNodePath As Variant
Set .FolderPicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
End If
Set _GetUNOService = .FolderPicker
+ Case &quot;FormatLocale&quot;
+ If IsEmpty(.FormatLocale) Or IsNull(.FormatLocale) Then
+ .FormatLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
+ &apos; 1st and 2nd chance
+ sLocale = SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, &quot;ooSetupSystemLocale&quot;)
+ If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;UILocale&quot;)
+ .FormatLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
+ .FormatLocale.Country = Right(sLocale, 2)
+ End If
+ Set _GetUNOService = .FormatLocale
Case &quot;FunctionAccess&quot;
If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then
Set .FunctionAccess = CreateUnoService(&quot;com.sun.star.sheet.FunctionAccess&quot;)
@@ -380,6 +405,16 @@ Dim vNodePath As Variant
End If
End If
Set _GetUNOService = .MailService
+ Case &quot;OfficeLocale&quot;
+ If IsEmpty(.OfficeLocale) Or IsNull(.OfficeLocale) Then
+ .OfficeLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
+ &apos; 1st and 2nd chance
+ sLocale = SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, &quot;ooLocale&quot;)
+ If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;UILocale&quot;)
+ .OfficeLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
+ .OfficeLocale.Country = Right(sLocale, 2)
+ End If
+ Set _GetUNOService = .OfficeLocale
Case &quot;PathSettings&quot;
If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then
Set .PathSettings = CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)
@@ -417,18 +452,13 @@ Dim vNodePath As Variant
End If
Set _GetUNOService = .SearchOptions
Case &quot;SystemLocale&quot;, &quot;Locale&quot;
- If IsEmpty(.Locale) Or IsNull(.Locale) Then
- .Locale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
- &apos; Derived from the Tools library
- Set oConfigProvider = createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
- vNodePath = Array() : ReDim vNodePath(0)
- vNodePath(0) = New com.sun.star.beans.PropertyValue
- vNodePath(0).Name = &quot;nodepath&quot; : vNodePath(0).Value = &quot;org.openoffice.System/L10N&quot;
- sLocale = oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, vNodePath()).getByName(&quot;SystemLocale&quot;)
- .Locale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
- .Locale.Country = Right(sLocale, 2)
+ If IsEmpty(.SystemLocale) Or IsNull(.SystemLocale) Then
+ .SystemLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
+ sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;SystemLocale&quot;)
+ .SystemLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
+ .SystemLocale.Country = Right(sLocale, 2)
End If
- Set _GetUNOService = .Locale
+ Set _GetUNOService = .SystemLocale
Case &quot;SystemShellExecute&quot;
If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then
Set .SystemShellExecute = CreateUnoService(&quot;com.sun.star.system.SystemShellExecute&quot;)
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 858a3ec77a71..94d5a3de7d58 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1218,9 +1218,10 @@ class SFScriptForge:
servicename = 'ScriptForge.Platform'
servicesynonyms = ('platform', 'scriptforge.platform')
serviceproperties = dict(Architecture = False, ComputerName = False, CPUCount = False, CurrentUser = False,
- Fonts = False, Locale = False, Machine = False, OfficeVersion = False, OSName = False,
- OSPlatform = False, OSRelease = False, OSVersion = False, Printers = False,
- Processor = False, PythonVersion = False)
+ Fonts = False, FormatLocale = False, Locale = False, Machine = False,
+ OfficeLocale = False, OfficeVersion = False, OSName = False, OSPlatform = False,
+ OSRelease = False, OSVersion = False, Printers = False, Processor = False,
+ PythonVersion = False, SystemLocale = False)
# Python helper functions
py = ScriptForge.pythonhelpermodule + '$' + '_SF_Platform'