Creating Multilingual LibreOffice Extensions

This guide outlines the end-to-end process of developing, localizing, packaging, and publishing multilingual extensions for LibreOffice. Developers will learn how to structure an OpenOffice/LibreOffice Extension (.oxt) package, localize extension metadata, implement multi-language string resources for UI components, and distribute the final package on the official LibreOffice Extensions repository.


1. Understanding the Extension Package Structure

A LibreOffice extension is a ZIP archive saved with the .oxt extension. To support multiple languages, the directory structure must separate executable code from localized resource files.

A typical structure looks like:

my-extension.oxt
├── META-INF/
│   └── manifest.xml
├── description.xml
├── description/
│   ├── desc_en.txt
│   ├── desc_de.txt
│   └── desc_fr.txt
├── strings/
│   ├── strings_en.properties
│   ├── strings_de.properties
│   └── strings_fr.properties
├── dialogs/
│   └── MainDialog.xdl
└── src/
    └── main.py (or .bas, .jar, etc.)

2. Localizing Metadata in description.xml

The description.xml file at the root of the extension manages metadata displayed in the LibreOffice Extension Manager. It supports built-in localization using the xml:lang attribute.

<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006"
             xmlns:xlink="http://www.w3.org/1999/xlink">
    <identifier value="org.example.multilingext" />
    <version value="1.0.0" />
    
    <display-name>
        <name lang="en">Document Formatter</name>
        <name lang="de">Dokumentformatierer</name>
        <name lang="fr">Formateur de Document</name>
    </display-name>

    <publisher>
        <name xlink:href="https://example.org" lang="en">Dev Team</name>
    </publisher>

    <extension-description>
        <src xlink:href="description/desc_en.txt" lang="en"/>
        <src xlink:href="description/desc_de.txt" lang="de"/>
        <src xlink:href="description/desc_fr.txt" lang="fr"/>
    </extension-description>
</description>

3. Localizing Dialogs and UI Elements

If your extension uses UNO Dialogs (.xdl files), you can localize them using resource files or directly within the LibreOffice Dialog Editor:

  1. Using LibreOffice Dialog Editor: Open the dialog editor in LibreOffice Basic, enable Manage Languages in the toolbar, and add your target locales. The editor generates the appropriate resource mappings inside the library automatically.
  2. External Resource Files (.properties): Store key-value pairs per locale:
    • strings_en.properties: BTN_SUBMIT = Submit
    • strings_de.properties: BTN_SUBMIT = Absenden
    • strings_fr.properties: BTN_SUBMIT = Soumettre

4. Handling String Translation in Code

To load localized strings dynamically in code (Python, Basic, or Java), use the UNO com.sun.star.resource.StringResourceWithLocation service.

Example (Python):

import uno

def get_string_resource(ctx, extension_id):
    smgr = ctx.ServiceManager
    string_provider = smgr.createInstanceWithContext(
        "com.sun.star.resource.StringResourceWithLocation", ctx
    )
    
    # Path to your strings folder within the extension
    pip = smgr.createInstanceWithContext("com.sun.star.deployment.PackageInformationProvider", ctx)
    location = pip.getPackageLocation(extension_id) + "/strings"
    
    # Initialize with default locale and path
    string_provider.initialize((location, False, ctx.ServiceManager.createInstanceWithContext("com.sun.star.lang.Locale", ctx), "strings", "", uno.Any()))
    return string_provider

def get_localized_message(ctx, key):
    sr = get_string_resource(ctx, "org.example.multilingext")
    return sr.resolveString(key)

5. Packaging and Testing the Extension

  1. Build the Archive: Create a .zip archive containing your extension files and rename the extension to .oxt:

    zip -r my-extension.oxt META-INF description.xml description strings dialogs src
  2. Test Multiple Locales:

    • Open LibreOffice.
    • Go to Tools > Extension Manager… and add my-extension.oxt.
    • Switch the UI language via Tools > Options > Language Settings > Languages > User Interface.
    • Restart LibreOffice to confirm strings, descriptions, and dialogs update according to the active locale.

6. Distributing on the LibreOffice Extensions Site

  1. Register an Account: Visit the LibreOffice Extensions and Templates site and register for a developer account.
  2. Submit a New Release:
    • Click Add Extension and upload the .oxt file.
    • Provide multilingual descriptions on the submission form where prompted.
    • Specify compatible LibreOffice versions (e.g., LibreOffice 7.x, 24.x) and operating systems.
  3. Publish: Submit the extension for automated verification and moderation. Once approved, the extension is publicly available, and LibreOffice users worldwide will receive the extension localized in their native language.