wizards/source/scriptforge/SF_L10N.xba           |    4 +++
 wizards/source/scriptforge/SF_Services.xba       |   28 ++++++++++++++++++++---
 wizards/source/scriptforge/python/scriptforge.py |    5 ++--
 3 files changed, 32 insertions(+), 5 deletions(-)

New commits:
commit 60f786bde4524bbba462eccc6578715f39020076
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Thu Feb 17 15:07:07 2022 +0100
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Thu Feb 17 16:18:49 2022 +0100

    ScriptForge - (L10N): add new arguments to the service creation
    
    Actual arguments:
      - FolderName: the folder containing the PO-files
      - Locale: in the form la-CO (language-COUNTRY)
      - Encoding: The character set that should be used
    
    New arguments introduced by this commit:
      - Locale2: fallback Locale to select if Locale po file does not exist
      - Encoding2: Encoding of the 2nd Locale file
    
    Both new arguments are optional => no regression on existing scripts
    
    The arguments are available in Basic and Python equally.
    They may be passed as keyworg arguments in Python only.
    
    The default locale is now set to the "OfficeLocale",
    which is the locale in the user interface.
    NB: the distinction between SystemLocale and OfficeLocale
    is new in version 7.4.
    
    Change-Id: Ie3bc5d30193df35a8c6c1ec706e13eaea0050981
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130074
    Tested-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>

diff --git a/wizards/source/scriptforge/SF_L10N.xba 
b/wizards/source/scriptforge/SF_L10N.xba
index 859f67386ba4..6bc6b236f3f3 100644
--- a/wizards/source/scriptforge/SF_L10N.xba
+++ b/wizards/source/scriptforge/SF_L10N.xba
@@ -51,6 +51,10 @@ Option Explicit
 &apos;&apos;&apos;                     CreateScriptService(&quot;L10N&quot;[, 
FolderName[, Locale]])
 &apos;&apos;&apos;                             FolderName: the folder 
containing the PO-files (in SF_FileSystem.FileNaming notation)
 &apos;&apos;&apos;                             Locale: in the form la-CO 
(language-COUNTRY)
+&apos;&apos;&apos;                             Encoding: The character set 
that should be used (default = UTF-8)
+&apos;&apos;&apos;                                     Use one of the Names 
listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml
+&apos;&apos;&apos;                             Locale2: fallback Locale to 
select if Locale po file does not exist (typically &quot;en-US&quot;)
+&apos;&apos;&apos;                             Encoding2: Encoding of the 2nd 
Locale file
 &apos;&apos;&apos;             Service invocation examples:
 &apos;&apos;&apos;                     Dim myPO As Variant
 &apos;&apos;&apos;                     myPO = 
CreateScriptService(&quot;L10N&quot;)    &apos;  AddText, AddTextsFromDialog 
and ExportToPOTFile are allowed
diff --git a/wizards/source/scriptforge/SF_Services.xba 
b/wizards/source/scriptforge/SF_Services.xba
index c6910aea5e50..b2932553d919 100644
--- a/wizards/source/scriptforge/SF_Services.xba
+++ b/wizards/source/scriptforge/SF_Services.xba
@@ -521,16 +521,20 @@ Public Function _NewL10N(Optional ByVal pvArgs As 
Variant) As Variant
 &apos;&apos;&apos;                             Use one of the Names listed in 
https://www.iana.org/assignments/character-sets/character-sets.xhtml
 &apos;&apos;&apos;                             Note that LibreOffice probably 
does not implement all existing sets
 &apos;&apos;&apos;                             Default = UTF-8
+&apos;&apos;&apos;             Locale2: fallback Locale to select if Locale po 
file does not exist (typically &quot;en-US&quot;)
+&apos;&apos;&apos;             Encoding2: Encoding of the 2nd Locale file
 &apos;&apos;&apos;     Returns: the instance or Nothing
 &apos;&apos;&apos;     Exceptions:
 &apos;&apos;&apos;             UNKNOWNFILEERROR                The PO file 
does not exist
 
 Dim oL10N As Variant           &apos;  Return value
 Dim sFolderName        As String       &apos;  Folder containing the PO files
-Dim sLocale     As String              &apos;  Passed argument or that of the 
user session
+Dim sLocale As String          &apos;  Passed argument or that of the user 
session
+Dim sLocale2 As String         &apos;  Alias for Locale2
 Dim oLocale As Variant         &apos;  com.sun.star.lang.Locale
 Dim sPOFile As String          &apos;  PO file must exist
 Dim sEncoding As String                &apos;  Alias for Encoding
+Dim sEncoding2 As String       &apos;  Alias for Encoding2
 
        If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
 
@@ -547,18 +551,36 @@ Check:
                        sLocale = pvArgs(1)
                End If
                If Len(sLocale) = 0 Then        &apos;  Called from Python, the 
Locale argument may be the zero-length string
-                       Set oLocale = 
SF_Utils._GetUNOService(&quot;SystemLocale&quot;)
+                       Set oLocale = 
SF_Utils._GetUNOService(&quot;OfficeLocale&quot;)
                        sLocale = oLocale.Language &amp; &quot;-&quot; &amp; 
oLocale.Country
                End If
                If UBound(pvArgs) &gt;= 2 Then
+                       If IsMissing(pvArgs(2)) Or IsEmpty(pvArgs(2)) Then 
pvArgs(2) = &quot;UTF-8&quot;
                        If Not SF_Utils._Validate(pvArgs(2), &quot;Encoding 
(Arg2)&quot;, V_STRING) Then GoTo Catch
                        sEncoding = pvArgs(2)
                Else
                        sEncoding = &quot;UTF-8&quot;
                End If
+               sLocale2 = &quot;&quot;
+               If UBound(pvArgs) &gt;= 3 Then
+                       If Not SF_Utils._Validate(pvArgs(3), &quot;Locale2 
(Arg3)&quot;, V_STRING) Then GoTo Catch
+                       sLocale2 = pvArgs(3)
+               End If
+               If UBound(pvArgs) &gt;= 4 Then
+                       If Not SF_Utils._Validate(pvArgs(4), &quot;Encoding2 
(Arg4)&quot;, V_STRING) Then GoTo Catch
+                       sEncoding2 = pvArgs(4)
+               Else
+                       sEncoding2 = &quot;UTF-8&quot;
+               End If
                If Len(sFolderName) &gt; 0 Then
                        sPOFile = SF_FileSystem.BuildPath(sFolderName, sLocale 
&amp; &quot;.po&quot;)
-                       If Not SF_FileSystem.FileExists(sPOFile) Then GoTo 
CatchNotExists
+                       If Not SF_FileSystem.FileExists(sPOFile) Then
+                               If Len(sLocale2) = 0 Then GoTo CatchNotExists   
&apos;  No fallback =&gt; error
+                               &apos;  Try the fallback
+                               sPOFile = SF_FileSystem.BuildPath(sFolderName, 
sLocale2 &amp; &quot;.po&quot;)
+                               If Not SF_FileSystem.FileExists(sPOFile) Then 
GoTo CatchNotExists
+                               sEncoding = sEncoding2
+                       End If
                End If
        End If
 
diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index 53a724d9b8f4..dea3a9854ebf 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1194,11 +1194,12 @@ class SFScriptForge:
         serviceproperties = dict(Folder = False, Languages = False, Locale = 
False)
 
         @classmethod
-        def ReviewServiceArgs(cls, foldername = '', locale = '', encoding = 
'UTF-8'):
+        def ReviewServiceArgs(cls, foldername = '', locale = '', encoding = 
'UTF-8',
+                              locale2 = '', encoding2 = 'UTF-8'):
             """
                 Transform positional and keyword arguments into positional only
                 """
-            return foldername, locale, encoding
+            return foldername, locale, encoding, locale2, encoding2
 
         def AddText(self, context = '', msgid = '', comment = ''):
             return self.ExecMethod(self.vbMethod, 'AddText', context, msgid, 
comment)

Reply via email to