Skip to content

Commit

Permalink
Use OfficeLocale for LO 7.4 or newer
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelhlima committed Aug 10, 2022
1 parent fb45757 commit 84955ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 19 additions & 1 deletion Source/RemoveBlankCells/RBL10n.xba
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ Function GetExtensionFolder() As String
GetExtensionFolder = basePath
End Function

'Return the Locale to be used by the extension
'Up until LO 7.3 the Locale property of the Platform service is used (OS locale)
'Starting with LO 7.4 use the OfficeLocale (used by LibreOffice UI)
Function GetLocale() As String
On Local Error GoTo CatchError
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Dim svc As Object, sLocale As String
svc = CreateScriptService("Platform")
Try:
sLocale = svc.OfficeLocale
GoTo Finally:
CatchError:
On Local Error GoTo 0
sLocale = svc.Locale
Finally:
GetLocale = sLocale
End Function

'Create a dictionary with all string IDs and en-US text
Function CreateStringDictionary() As Object
' Dictionary will all string IDs
Expand Down Expand Up @@ -141,4 +159,4 @@ Sub ShowPathToPO()
MsgBox pathToPO
End Sub

</script:module>
</script:module>
8 changes: 4 additions & 4 deletions Source/RemoveBlankCells/RBMain.xba
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ Sub InitializeExtension()
glb_basePath = RBL10n.GetExtensionFolder()
glb_poPath = glb_basePath &amp; &quot;/po&quot;
&apos;Check if the current locale po file exists
Dim fso As Object, plt As Object
Dim fso As Object, currentLocale As String
fso = CreateScriptService(&quot;FileSystem&quot;)
plt = CreateScriptService(&quot;Platform&quot;)
currentLocale = RBL10n.GetLocale()
&apos;File name of the la-CO.po file
Dim requiredPO As String : requiredPO = glb_poPath &amp; &quot;/&quot; &amp; plt.Locale &amp; &quot;.po&quot;
Dim requiredPO As String : requiredPO = glb_poPath &amp; &quot;/&quot; &amp; currentLocale &amp; &quot;.po&quot;
&apos;File name of the generic la.po file (generic language, without country)
&apos;This is used as fallback when the specific la-PO file does not exist
Dim requiredLaPO As String, sLanguage As String
sLanguage = Split(plt.Locale, &quot;-&quot;)(0)
sLanguage = Split(currentLocale, &quot;-&quot;)(0)
requiredLaPO = glb_poPath &amp; &quot;/&quot; &amp; sLanguage &amp; &quot;.po&quot;
If fso.FileExists(requiredPO) Then
&apos;If the full locale file exists, use it
Expand Down

0 comments on commit 84955ae

Please sign in to comment.