Skip to main content

Multilingual

Overview

Next Design allows you to switch the display language. By adding logic to the implementation code so that the display language of the extension also switches in conjunction with the switching, the extension can be made multilingual.

Multilingual extension support is optional. If you do not need multilingual support, you do not need to support the following.

To make the extension multilingual, first create a locale file that defines the resource string for each display language. Then, it can be realized by adding/changing the logic to acquire the resource string corresponding to the display location from those locale files to the implementation code. Adding/changing the implementation code for multilingual support in this way is called globalize.

Creating a locale file

  • You can define a resource string for each display language by adding a locale file with the following name to the folder where the manifest exists.

    File name format: locale. {lang} .json

    LanguagelangFile Name
    Japanesejalocale.ja.json
    Englishenlocale.en.json
  • Use UTF-8 as the character code of the locale file.

Locale file implementation example

locale.ja.json

{
"locale": "ja",
"resourceStrings": {
"MyExt.Tab.Label": "Extension",
"MyExt.ValidationGroup.Label": "Model Validation",
"MyExt.ValidationButton.Label": "Validation",
"MyExt.ValidationButton.Description": "Validate all models.",,
"MyExt.Error.CanNotBeEmpty.Title": "Cannot empty",
"MyExt.Error.CanNotBeEmpty.Message": "Name field cannot be empty",
"MyExt.Error.CanNotChange.Message2": "{0} cannot be {1}"
}
}

locale.en.json

{
"locale": "en",
"resourceStrings": {
"MyExt.Tab.Label": "Extension",
"MyExt.ValidationGroup.Label": "Model Validation",
"MyExt.ValidationButton.Label": "Validate",
"MyExt.ValidationButton.Description": "Validate all models.",
"MyExt.Error.CanNotBeEmpty.Title": "Can't be empty.",
"MyExt.Error.CanNotBeEmpty.Message": "Name field can't be empty.",
"MyExt.Error.CanNotChange.Message2": "Can't set {0} to {1}."
}
}

Globalize strings in the manifest

  • Instead of specifying the string directly in the manifest, you can specify something like "% resource string name%" to replace it with the resource string defined in the locale file.
  • If the corresponding resource string name does not exist in the locale file, "% resource string name%" is displayed as it is.

manifest.json

{
"extensionPoints": {
"ribbon": {
"tabs": [
{
"id": "MyExtensions.Tab",
"label": "% MyExt.Tab.Label%",
"groups": [
{
"id": "MyExtensions.ValidationGroup",
"label": "% MyExt.ValidationGroup.Label%",
"controls": [
{
"type": "Button",
"id": "MyExtensions.ValidationButton",
"label": "% MyExt.ValidationButton.Label%",
"description": "% MyExt.ValidationButton.Description%",
"imageLarge": "resources/icon.png",
"command": "Validate.Run"
}
]
}
]
}
]
}
},
}

Globalization of strings in handlers

Get the resource string from the locale file as follows:

Simple resource string

var message = context.GetResourceString ("MyExt.Error.CanNotBeEmpty.Message");
model.AddError ("Name", "Error", null, message);

Parameter-embedded resource string

var message = context.GetResourceString2 ("MyExt.Error.CanNotChange.Message2", "aaa", "bbb");
model.AddError ("Name", "Error", null, message);

API for getting resource string

public interface IContext
{
//Get the resource string of the current display language
string GetResourceString (string key);
string GetResourceString1 (string key, string param1);
string GetResourceString2 (string key, string param1, string param2);
string GetResourceString3 (string key, string param1, string param2, string param3);
}