summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2022-03-10 12:10:51 +0100
committerJean-Pierre Ledure <jp@ledure.be>2022-03-10 16:26:11 +0100
commit511cc0cd621ebdc67fdfbd440d098b2d1c23dc58 (patch)
tree727a25ce7ef9a19825ad61cbcd69faa7a41d57a7
parent3edb855e7c0e2ac0d49fa38654efd92c3618ed8f (diff)
ScriptForge - (SF_Root) differ loading of the localized interface
So far, the loading of the user interface in the user's own language was done at the first invocation of ScriptForge, usually via - a CreateScriptService() method - a direct call to any method, f.i. SF_Array.Append() Now the same loading of the user interface in memory is done at the first request of a localized text or message. Due to the fact that since last commit https://gerrit.libreoffice.org/c/core/+/131255 only error messages contain localized texts, the benefit is that correct scripts will not load any unnecessary texts anymore. The "Interface" variable has be renamed "LocalizedInterface" for clarity in the SF_Root class module No impact on documentation or Python scripts. Change-Id: Ie654625540c0c8f8442e9ba36d38ecaab00c0eb1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131313 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
-rw-r--r--wizards/source/scriptforge/SF_Exception.xba13
-rw-r--r--wizards/source/scriptforge/SF_Root.xba28
-rw-r--r--wizards/source/scriptforge/SF_Utils.xba6
3 files changed, 29 insertions, 18 deletions
diff --git a/wizards/source/scriptforge/SF_Exception.xba b/wizards/source/scriptforge/SF_Exception.xba
index 2af37d9534f2..aeac2fb91aab 100644
--- a/wizards/source/scriptforge/SF_Exception.xba
+++ b/wizards/source/scriptforge/SF_Exception.xba
@@ -612,7 +612,7 @@ Public Sub Raise(Optional ByVal Number As Variant _
&apos;&apos;&apos; SF_Exception.Raise(,, &quot;To divide by zero is not a good idea !&quot;)
Dim sMessage As String &apos; Error message to log and to display
-Dim L10N As Object &apos; Alias to Interface
+Dim L10N As Object &apos; Alias to LocalizedInterface
Const cstThisSub = &quot;Exception.Raise&quot;
Const cstSubArgs = &quot;[Number=Err], [Source=Erl], [Description]&quot;
@@ -641,7 +641,7 @@ Try:
If Len(Description) &gt; 0 Then .Description = Description
&apos; Log and display
- Set L10N = _SF_.Interface
+ Set L10N = _SF_._GetLocalizedInterface()
sMessage = L10N.GetText(&quot;LONGERRORDESC&quot;, .Number, .Source, .Description)
.DebugPrint(sMessage)
If _SF_.DisplayEnabled Then MsgBox L10N.GetText(&quot;ERRORNUMBER&quot;, .Number) _
@@ -675,7 +675,7 @@ Public Sub RaiseAbort(Optional ByVal Source As Variant)
Dim sLocation As String &apos; Common header in error messages: location of error
Dim vLocation As Variant &apos; Split array (library, module, method)
Dim sMessage As String &apos; Error message to log and to display
-Dim L10N As Object &apos; Alias to Interface
+Dim L10N As Object &apos; Alias to LocalizedInterface
Const cstTabSize = 4
Const cstThisSub = &quot;Exception.RaiseAbort&quot;
Const cstSubArgs = &quot;[Source=Erl]&quot;
@@ -691,7 +691,7 @@ Try:
With SF_Exception
&apos; Prepare message header
- Set L10N = _SF_.Interface
+ Set L10N = _SF_._GetLocalizedInterface()
If Len(_SF_.MainFunction) &gt; 0 Then &apos; MainFunction = [Library.]Module.Method
vLocation = Split(_SF_.MainFunction, &quot;.&quot;)
If UBound(vLocation) &lt; 2 Then vLocation = SF_Array.Prepend(vLocation, &quot;ScriptForge&quot;)
@@ -701,7 +701,6 @@ Try:
End If
&apos; Log and display
- Set L10N = _SF_.Interface
sMessage = L10N.GetText(&quot;LONGERRORDESC&quot;, .Number, .Source, .Description)
.DebugPrint(sMessage)
If _SF_.DisplayEnabled Then
@@ -741,7 +740,7 @@ Dim sService As String &apos; Service name having detected the error
Dim sMethod As String &apos; Method name having detected the error
Dim vLocation As Variant &apos; Split array (library, module, method)
Dim sMessage As String &apos; Message to log and display
-Dim L10N As Object &apos; Alias of Interface
+Dim L10N As Object &apos; Alias of LocalizedInterface
Dim sAlt As String &apos; Alternative error messages
Dim iButtons As Integer &apos; MB_OK or MB_YESNO
Dim iMsgBox As Integer &apos; Return value of the message box
@@ -760,7 +759,7 @@ Check:
End If
Try:
- Set L10N = _SF_.Interface
+ Set L10N = _SF_._GetLocalizedInterface()
&apos; Location header common to all error messages
If Len(_SF_.MainFunction) &gt; 0 Then &apos; MainFunction = [Library.]Module.Method
vLocation = Split(_SF_.MainFunction, &quot;.&quot;)
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba
index 0ed77373d773..31137c7ec041 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -83,7 +83,7 @@ Private Toolkit As Object &apos; com.sun.star.awt.Toolkit
Private FileSystemNaming As String &apos; If &quot;SYS&quot;, file and folder naming is based on operating system notation
Private PythonHelper As String &apos; File name of Python helper functions (stored in $(inst)/share/Scripts/python)
Private PythonHelper2 As String &apos; Alternate Python helper file name for test purposes
-Private Interface As Object &apos; ScriptForge own L10N service
+Private LocalizedInterface As Object &apos; ScriptForge own L10N service
Private OSName As String &apos; WIN, LINUX, MACOS
Private SFDialogs As Variant &apos; Persistent storage for the SFDialogs library
Private SFForms As Variant &apos; Persistent storage for the SF_Form class in the SFDocuments library
@@ -137,7 +137,7 @@ Private Sub Class_Initialize()
FileSystemNaming = &quot;ANY&quot;
PythonHelper = &quot;ScriptForgeHelper.py&quot;
PythonHelper2 = &quot;&quot;
- Set Interface = Nothing
+ Set LocalizedInterface = Nothing
Set BrowseNodeFactory = Nothing
Set DatabaseContext = Nothing
Set ConfigurationProvider = Nothing
@@ -240,6 +240,20 @@ Finally:
Exit Function
End Function &apos; ScriptForge.SF_Root._AddToPythonStorage
+REM ------------------------------------------------------------------------------
+Public Function _GetLocalizedInterface() As Object
+&apos;&apos;&apos; Returns the LN object instance related to the ScriptForge internal localization
+&apos;&apos;&apos; If not yet done, load it from the shipped po files
+&apos;&apos;&apos; Makes that the localized user interface is loaded only when needed
+
+Try:
+ If IsNull(LocalizedInterface) Then _LoadLocalizedInterface()
+
+Finally:
+ Set _GetLocalizedInterface = LocalizedInterface
+ Exit Function
+End Function &apos; ScriptForge.SF_Root._GetLocalizedInterface
+
REM -----------------------------------------------------------------------------
Public Sub _InitPythonStorage()
&apos;&apos;&apos; Make PythonStorage an array
@@ -269,7 +283,7 @@ End Sub &apos; ScriptForge.SF_Root._InitPythonStorage
REM -----------------------------------------------------------------------------
Public Sub _LoadLocalizedInterface(Optional ByVal psMode As String)
&apos;&apos;&apos; Build the user interface in a persistent L10N object
-&apos;&apos;&apos; Executed - only once - at first ScriptForge invocation by a user script
+&apos;&apos;&apos; Executed - only once - at first request of a label inside the LocalizedInterface dictionary
&apos;&apos;&apos; Args:
&apos;&apos;&apos; psMode: ADDTEXT =&gt; the (english) labels are loaded from code below
&apos;&apos;&apos; POFILE =&gt; the localized labels are loaded from a PO file
@@ -294,19 +308,19 @@ Try:
sLocale = SF_Utils._GetUNOService(&quot;OfficeLocale&quot;).Language
sPOFolder = .BuildPath(sInstallFolder, &quot;po&quot;)
sPOFile = .BuildPath(sPOFolder, sLocale &amp; &quot;.po&quot;)
- If sLocale = &quot;en&quot; Then &apos; Interface loaded by code i.o. read from po file
+ If sLocale = &quot;en&quot; Then &apos; LocalizedInterface loaded by code i.o. read from po file
psMode = &quot;ADDTEXT&quot;
ElseIf Not .FileExists(sPOFile) Then &apos; File not found =&gt; load texts from code below
psMode = &quot;ADDTEXT&quot;
Else
- Set Interface = CreateScriptService(&quot;L10N&quot;, sPOFolder, sLocale)
+ Set LocalizedInterface = CreateScriptService(&quot;L10N&quot;, sPOFolder, sLocale)
End If
End With
End If
If psMode = &quot;ADDTEXT&quot; Then &apos; Use this mode in development to prepare a new POT file
- Set Interface = CreateScriptService(&quot;L10N&quot;)
- With Interface
+ Set LocalizedInterface = CreateScriptService(&quot;L10N&quot;)
+ With LocalizedInterface
&apos; SF_Exception.Raise
.AddText( Context := &quot;ERRORNUMBER&quot; _
, MsgId := &quot;Error %1&quot; _
diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba
index 28aed74fa19f..e0381f8a5d5f 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -226,9 +226,9 @@ Dim sHeader As String &apos; The specific header to insert
Try:
With _SF_
- If Not IsNull(.Interface) Then .Interface.Dispose()
+ If Not IsNull(.LocalizedInterface) Then .LocalizedInterface.Dispose()
._LoadLocalizedInterface(psMode := &quot;ADDTEXT&quot;) &apos; Force reload of labels from the code
- .Interface.ExportToPOTFile(FileName, Header := sHeader)
+ .LocalizedInterface.ExportToPOTFile(FileName, Header := sHeader)
End With
Finally:
@@ -506,8 +506,6 @@ Public Sub _InitializeRoot(Optional ByVal pbForce As Boolean)
If IsEmpty(_SF_) Or IsNull(_SF_) Then
Set _SF_ = New SF_Root
Set _SF_.[Me] = _SF_
- &apos; Localization
- _SF_._LoadLocalizedInterface()
End If
End Sub &apos; ScriptForge.SF_Utils._InitializeRoot