Skip to content

I18N

For an application that is available across borders, internationalization is crucial. slicer’s scripting API allows you to access this layer and provide localizations for your scripts or even for the native UI, if you find it lacking in some regard. You can also read more about how to contribute translations to the native UI in the CONTRIBUTING.md file.

This is primarily facilitated by the I18NContext API, accessible through the context.

context.i18n.locale; // returns the current selected locale string (e.g. "en", "es", "cs")
context.i18n.t("menu.file"); // translates a key, optionally accepts additional arguments for formatting
// register a translation under a specified locale and key
context.i18n.add("cs", "my_script/amazing_feature", "Moje úžasná funkce");
// remove a previously registered translation
context.i18n.remove("cs", "my_script/amazing_feature");

Remember that translation keys in slicer usually follow the a.b.c dot-notation format, and it is highly recommended to prefix your script’s translations with a unique namespace, much like tabs or options, so they don’t override native translations or translations from other scripts.