When you develop extensions, the
vSphere
Client can appear in different languages in different locales.
You can set the information that appears in the vSphere
Client, for
example, the extension name, as resources that can be translated.
You provide the information that requires translation
in an ExtensionResourceInfo data object. You can add an ExtensionResourceInfo
object for every locale that your extension supports. You set an array of ExtensionResourceInfo
objects in the resourceList property of the Extension instance that
defines your extension.
You provide onscreen messages and labels to ExtensionResourceInfo in
a key and value pairing that you add to a KeyValue array in the
ExtensionResourceInfo
data property.
You can set the values for the KeyValue pair directly
in the ExtensionResourceInfo object, or you can refer to entries in resource
files that contain the message text in different languages, according to the locale
in which vSphere is running.
You provide a two-character
ISO-639 language ID for the
KeyValue
locale property, and
set the
module property to
the type of resource to which this locale applies. For example, you can set the
module value to
task
,
event
,
auth
, or
extension
, depending on whether the messages that the
resource contains relate to tasks, events, privileges, or extensions.
Procedure
-
Create an instance of
the
ExtensionResourceInfo
data object.
For example, in
MyManager.java you
can instantiate
ExtensionResourceInfo in the implementation of
Extension.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
[...]
}
-
Set the locale and
module properties for the
ExtensionResourceInfo
object.
For example, in
MyManager.java you
can set the default locale to
en
and apply this locale to the
Extension
instance,
extension
.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
extensionResourceInfo.setLocale("en");
extensionResourceInfo.setModule("extension");
[...]
}
-
Provide the data to the
ExtensionResourceInfo
in the form of a
KeyValue array.
The
label
property is a property of the
Description object,
that
Extension implements,
and defines the name of the extension as it appears in the
vSphere
Client.
For example, in
MyManager.java you
can add the text
My Solution
as the value of the
label property.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
extensionResourceInfo.setLocale("en");
extensionResourceInfo.setModule("extension");
KeyValue keyValue = new KeyValue();
keyValue.setKey(EXTENSION_KEY + ".label");
keyValue.setValue("My Solution");
[...]
}
-
Call the
ExtensionResourceInfo.getData()
method to add the
KeyValue array that
contains the localization data to the
data property of the
ExtensionResourceInfo
object.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
extensionResourceInfo.setLocale("en");
extensionResourceInfo.setModule("extension");
KeyValue keyValue = new KeyValue();
keyValue.setKey(EXTENSION_KEY + ".label");
keyValue.setValue("My Solution");
extensionResourceInfo.getData().add(keyValue);
[...]
}
- (Optional)
Add another
KeyValue object to the
ExtensionResourceInfo
data property that
adds a description of the extension for a given locale.
For example, you can add the following
description to
MyManager.java in a
KeyValue object
named
keyValue_summary.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
extensionResourceInfo.setLocale("en");
extensionResourceInfo.setModule("extension");
KeyValue keyValue = new KeyValue();
keyValue.setKey(EXTENSION_KEY + ".label");
keyValue.setValue("My Solution");
KeyValue keyValue_summary = new KeyValue();
keyValue_summary.setKey(EXTENSION_KEY + ".summary");
keyValue_summary.setValue("This is a brief description of My Solution.");
extensionResourceInfo.getData().add(keyValue);
extensionResourceInfo.getData().add(keyValue_summary);
[...]
}
-
Call the
Extension.getResourceList()
method to pass the
ExtensionResourceInfo
object to the
Extension instance.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
extensionResourceInfo.setLocale("en");
extensionResourceInfo.setModule("extension");
KeyValue keyValue = new KeyValue();
keyValue.setKey(EXTENSION_KEY + ".label");
keyValue.setValue("My Solution");
KeyValue keyValue_summary = new KeyValue();
keyValue_summary.setKey(EXTENSION_KEY + ".summary");
keyValue_summary.setValue("This is a brief description of My Solution.");
extensionResourceInfo.getData().add(keyValue);
extensionResourceInfo.getData().add(keyValue_summary);
extension.getResourceList().add(extensionResourceInfo);
[...]
}
- (Optional)
Add more
ExtensionResourceInfo
instances to provide localized text that displays when the extension runs in
different locales.
For example, you can add an
ExtensionResourceInfo instance to
MyManager.java to
provide a French translation of the extension name.
private Extension createExtensionObject() {
Extension extension = new Extension();
[...]
ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo();
extensionResourceInfo.setLocale("en");
extensionResourceInfo.setModule("extension");
KeyValue keyValue = new KeyValue();
keyValue.setKey(EXTENSION_KEY + ".label");
keyValue.setValue("My Solution");
KeyValue keyValue_summary = new KeyValue();
keyValue_summary.setKey(EXTENSION_KEY + ".summary");
keyValue_summary.setValue("This is a brief description of My Solution.");
extensionResourceInfo.getData().add(keyValue);
extensionResourceInfo.getData().add(keyValue_summary);
ExtensionResourceInfo extensionResourceInfo_FR = new ExtensionResourceInfo();
extensionResourceInfo_FR.setLocale("fr");
extensionResourceInfo_FR.setModule("extension");
KeyValue keyValue_FR = new KeyValue();
keyValue_FR.setKey(EXTENSION_KEY + ".label");
keyValue_FR.setValue("Ceci est une brève description de Ma solution.");
extensionResourceInfo_FR.getData().add(keyValue_FR);
extension.getResourceList().add(extensionResourceInfo);
extension.getResourceList().add(extensionResourceInfo_FR);
[...]
}
- (Optional)
Save your changes, build, and deploy
your solution.
If you edit the label value, the
extension appears in vCenter
Server Extensions with the new name. If you added an ExtensionResourceInfo object for a different locale, the
localized text that you added appears in vCenter
Server Extensions when you connect your solution to a vCenter Server instance that runs in that locale.
Results
You added localizable message resources to the
extension, so that onscreen messages and labels that your extension provides can
appear in different languages in different locales.