Skip to main content

Multilingual

Overview

You can support multiple languages ​​by switching the display language of the extension in conjunction with the switching of the display language of Next Design.
Multilingual support for extensions is optional. If multilingual support is not required, the following support is not required.

Multilingual support for extensions requires the following implementations:

  • Create locale file
  • String globalization

Create locale file

A file that defines resource strings for each display language is called a locale file.
Resource strings can be defined for each display language by adding a locale file with the following name to the folder where the manifest resides:

LanguageFile name
Japaneselocale.ja.json
Englishlocale.en.json
note
  • Use UTF-8 for the locale file character code.

Implementation example

locale.ja.json

{
"locale": "en",
"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 be 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}."
}
}

String globalization

Adding or changing the implementation code for multilingual support is called globalization.
Globalization can be achieved by adding/modifying the implementation code to obtain the resource string corresponding to the display location from the locale file.

Manifest

For globalization in the manifest, specify the resource string defined in the locale file as %resource string identifier%.

Implementation example

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"
}
]
}
]
}
]
}
},
}

Handler

For globalization within the handler, use the following API with the identifier of the resource string defined in the locale file set as an argument.

API for getting resource strings

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

Implementation example

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);
note
  • If the corresponding resource string name identifier does not exist in the locale file, the resource string identifier is displayed as is.