Set the extension name and localization resources
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.- Create an instance of theExtensionResourceInfodata object.For example, inMyManager.javayou can instantiateExtensionResourceInfoin the implementation ofExtension.private Extension createExtensionObject() { Extension extension = new Extension(); [...] ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo(); [...] }
- Set the locale and module properties for theExtensionResourceInfoobject.For example, inMyManager.javayou can set the default locale toenand apply this locale to theExtensioninstance,extension.private Extension createExtensionObject() { Extension extension = new Extension(); [...] ExtensionResourceInfo extensionResourceInfo = new ExtensionResourceInfo(); extensionResourceInfo.setLocale("en"); extensionResourceInfo.setModule("extension"); [...] }
- Provide the data to theExtensionResourceInfoin the form of aKeyValuearray.Thelabelproperty is a property of theDescriptionobject, thatExtensionimplements, and defines the name of the extension as it appears in thevSphere Client.For example, inMyManager.javayou can add the textMy Solutionas the value of thelabelproperty.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 theExtensionResourceInfo.getData()method to add theKeyValuearray that contains the localization data to thedataproperty of theExtensionResourceInfoobject.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); [...] }
- Add anotherKeyValueobject to theExtensionResourceInfodataproperty that adds a description of the extension for a given locale.For example, you can add the following description toMyManager.javain aKeyValueobject namedkeyValue_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 theExtension.getResourceList()method to pass theExtensionResourceInfoobject to theExtensioninstance.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); [...] }
- Add moreExtensionResourceInfoinstances to provide localized text that displays when the extension runs in different locales.For example, you can add anExtensionResourceInfoinstance toMyManager.javato 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); [...] }
- Save your changes, build, and deploy your solution.If you edit thelabelvalue, the extension appears invCenter Server Extensionswith the new name. If you added anExtensionResourceInfoobject for a different locale, the localized text that you added appears invCenter Server Extensionswhen you connect your solution to avCenter Serverinstance that runs in that locale.
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.