How to use Scriptforge.L10N?

Hello,
I am trying to learn how to use Scriptforge.L10N to create localized versions of a macro.
To test, I have created a macro that simply displays a MsgBox saying “Hello world”.
I followed the following steps

  • First I’ve created the POT file with the following macro:
Sub CreatePOT
	GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
	Dim myPO As Variant
	Set myPO = CreateScriptService("L10N")
	myPO.AddText(, "Hello world")
	myPO.ExportToPOTFile("c:\kk\myFile.pot")
End Sub
  • Next I’ve copied myFile.pot to es-ES.po
  • I’ve translated the only string in the es-ES.po file:
msgid  "Hello world"
msgstr "Hola mundo"
  • Next I’ve executed the following macro with LibreOffice in Spanish (Spain):
Sub Mensaje
	GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
	Dim myPO As Variant
	Set myPO = CreateScriptService("L10N")
	Dim texto As String
	texto = myPo.GetText("Hello world")
	MsgBox(texto)
End Sub

I expect the message in Spanish but the message is in inglish
What are I missing?

According to the help, you must indicate where the PO files are.

myPO = CreateScriptService("L10N", "C:\myPOFiles\")

According with documentation, foldername is optional in CreateScriptService. I understand that if foldername is missing, it uses current folder.

Any case, I had tried it with a foldername and also it didn’t work (I have tried it again, just in case).

More over, if I pretend to use it in a extension, I need a relative folder because I don’t know the installation folder in advance.

The folder name may be missing in the CreateScriptService("L10N", ...) statement only if your intent is to create the POT file by code (use of l10n.AddText() and l10n.ExportToPOTFile(). In normal use, to translate strings on-the-fly, it is required.

The Locale argument is also mandatory in the same statement. Indeed, LO has several locale settings available. You can get them with the Platform service: platform.OfficeLocale, platform.SystemLocale, platform.FormatLocale. They might differ depending on the user settings. Up to you to choose the most appropriate.

Finally, you can determine in which directory an extension is installed: use filesystem.ExtensionFolder().