Skip to main content

Localization

Plugins can provide translations for all user-facing texts, such as the labels of metrics, categories and settings.

Language Files​

To enable localization, specify the relative path to the folder containing the localization files under the localization key in the mobro_plugin_config.json.

The following example is taken from the MoBroHardwareMonitor plugin:

Plugin.MoBroHardwareMonitor/mobro_plugin_config.json
{
"name": "modbros_mobrohardwaremonitor",
"displayName": "MoBro Hardware Monitor",
"author": "ModBros",
"description": null,
"assembly": "Plugin.MoBroHardwareMonitor.dll",
"localization": "Resources/Localization",
"settings": []
}

The localization files — one for each supported language — must be placed in this folder (e.g., Resources/Localization in the given example) and be part of the published plugin.

These files are JSON files containing simple key-value pairs with the translated texts for a specific language.

Example Files​

Below are examples of localization files from the MoBroHardwareMonitor plugin:

English Language File:

Plugin.MoBroHardwareMonitor/Resources/Localization/en.json
{
"metrics.system.osname.title": "Name",
"metrics.system.osname.desc": "The name of the operating system",
"metrics.system.osversion.title": "Version",
"metrics.system.osversion.desc": "The specific version of the operating system",
"metrics.system.ostype.title": "Type",
"metrics.system.ostype.desc": "The type of the operating system (32bit/64bit)"
}

German Language File (same keys):

Plugin.MoBroHardwareMonitor/Resources/Localization/de.json
{
"metrics.system.osname.title": "Bezeichnung",
"metrics.system.osname.desc": "Der Name des Betriebssystems",
"metrics.system.osversion.title": "Version",
"metrics.system.osversion.desc": "Die Version des Betriebssystems",
"metrics.system.ostype.title": "Typ",
"metrics.system.ostype.desc": "Der Typ des Betriebssystems (32bit/64bit)"
}

Usage​

To use a translated text, reference its key from the localization files wherever a plain string would be used.
MoBro automatically handles the translation.

Example​

Instead of using a plain string when creating a metric, pass the localization keys:

Plugin.cs
var metric = MoBroItem
.CreateMetric()
.WithId("osname")
.WithLabel("metrics.system.osname.title", "metrics.system.osname.desc")
.OfType(CoreMetricType.Text)
.OfCategory(CoreCategory.System)
.OfNoGroup()
.Build();

This approach applies to all registrable items (metrics, categories, groups, etc.), plugin settings, and more.
Whenever you pass a string to MoBro, you can use a localization key instead.