From 60f786bde4524bbba462eccc6578715f39020076 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Ledure Date: Thu, 17 Feb 2022 15:07:07 +0100 Subject: 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 Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure --- 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(-) (limited to 'wizards') 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 ''' CreateScriptService("L10N"[, FolderName[, Locale]]) ''' FolderName: the folder containing the PO-files (in SF_FileSystem.FileNaming notation) ''' Locale: in the form la-CO (language-COUNTRY) +''' Encoding: The character set that should be used (default = UTF-8) +''' Use one of the Names listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml +''' Locale2: fallback Locale to select if Locale po file does not exist (typically "en-US") +''' Encoding2: Encoding of the 2nd Locale file ''' Service invocation examples: ''' Dim myPO As Variant ''' myPO = CreateScriptService("L10N") ' 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 ''' Use one of the Names listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml ''' Note that LibreOffice probably does not implement all existing sets ''' Default = UTF-8 +''' Locale2: fallback Locale to select if Locale po file does not exist (typically "en-US") +''' Encoding2: Encoding of the 2nd Locale file ''' Returns: the instance or Nothing ''' Exceptions: ''' UNKNOWNFILEERROR The PO file does not exist Dim oL10N As Variant ' Return value Dim sFolderName As String ' Folder containing the PO files -Dim sLocale As String ' Passed argument or that of the user session +Dim sLocale As String ' Passed argument or that of the user session +Dim sLocale2 As String ' Alias for Locale2 Dim oLocale As Variant ' com.sun.star.lang.Locale Dim sPOFile As String ' PO file must exist Dim sEncoding As String ' Alias for Encoding +Dim sEncoding2 As String ' 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 ' Called from Python, the Locale argument may be the zero-length string - Set oLocale = SF_Utils._GetUNOService("SystemLocale") + Set oLocale = SF_Utils._GetUNOService("OfficeLocale") sLocale = oLocale.Language & "-" & oLocale.Country End If If UBound(pvArgs) >= 2 Then + If IsMissing(pvArgs(2)) Or IsEmpty(pvArgs(2)) Then pvArgs(2) = "UTF-8" If Not SF_Utils._Validate(pvArgs(2), "Encoding (Arg2)", V_STRING) Then GoTo Catch sEncoding = pvArgs(2) Else sEncoding = "UTF-8" End If + sLocale2 = "" + If UBound(pvArgs) >= 3 Then + If Not SF_Utils._Validate(pvArgs(3), "Locale2 (Arg3)", V_STRING) Then GoTo Catch + sLocale2 = pvArgs(3) + End If + If UBound(pvArgs) >= 4 Then + If Not SF_Utils._Validate(pvArgs(4), "Encoding2 (Arg4)", V_STRING) Then GoTo Catch + sEncoding2 = pvArgs(4) + Else + sEncoding2 = "UTF-8" + End If If Len(sFolderName) > 0 Then sPOFile = SF_FileSystem.BuildPath(sFolderName, sLocale & ".po") - If Not SF_FileSystem.FileExists(sPOFile) Then GoTo CatchNotExists + If Not SF_FileSystem.FileExists(sPOFile) Then + If Len(sLocale2) = 0 Then GoTo CatchNotExists ' No fallback => error + ' Try the fallback + sPOFile = SF_FileSystem.BuildPath(sFolderName, sLocale2 & ".po") + 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) -- cgit