Skip to content
Asterios Raptis edited this page Mar 27, 2026 · 1 revision

i18n (Internationalization)

PluginForge supports multilingual strings loaded from YAML files.

Setup

Create language files under config/i18n/:

# config/i18n/en.yaml
app:
  title: "My Application"
  subtitle: "Plugin-powered"
plugins:
  export:
    label: "Export"
    description: "Export documents"
common:
  save: "Save"
  cancel: "Cancel"
  delete: "Delete"
# config/i18n/de.yaml
app:
  title: "Meine Anwendung"
  subtitle: "Plugin-basiert"
plugins:
  export:
    label: "Export"
    description: "Dokumente exportieren"
common:
  save: "Speichern"
  cancel: "Abbrechen"
  delete: "Loeschen"

Usage

pm = PluginManager("config/app.yaml")

# Use default language (from app config)
pm.get_text("common.save")         # "Speichern" (if default_language: "de")

# Specify language explicitly
pm.get_text("common.save", "en")   # "Save"
pm.get_text("common.save", "de")   # "Speichern"

# Nested keys with dot notation
pm.get_text("plugins.export.label", "en")  # "Export"

Default Language

Set in config/app.yaml:

app:
  default_language: "de"

If not set, defaults to "en".

Fallback Behavior

  1. Look up key in the requested language
  2. If not found, look up in the default language
  3. If still not found, return the key itself
# Key exists in "en" but not in "fr"
pm.get_text("common.save", "fr")   # Falls back to "en" -> "Save"

# Key does not exist at all
pm.get_text("nonexistent.key")     # Returns "nonexistent.key"

Caching

Language files are loaded lazily on first access and cached. Subsequent calls for the same language do not re-read the file.

I18n Class (Direct Usage)

from pluginforge.i18n import I18n

i18n = I18n("config", default_lang="de")
i18n.get_text("common.save")        # "Speichern"
i18n.get_text("common.save", "en")  # "Save"

Clone this wiki locally