|
![]() |
The API provides a basic amount of support for localization using additional .name files which are loaded at the same time as the plugin assembly. Certain information can only be set in attributes, for example PluginAttribute..::..Name, however the .name file entries override the attribute values allowing the developer to localize these values as well.
In this section we examine the localisation methods available in the .NET API and how to access them.
.name files
The first step in localizing samples is to provide a .name file for the assembly. A sample name file is shown below:

# This file uses UTF8 encoding. Lines starting with # or $, or ending with = # do NOT need translating. $utf8 DisplayName= Hello to the World Tooltip= Shows/hides the Basic Doc Pane Plug-in HelloWorldText= Hello World
as can be seen in the example, commented lines begin with a '#' character. The file should be saved with encoding set to UTF8, as shown below when saving in Notepad.
The content of the name file can contain a mixture of alternative values for PluginAttribute parameters as well as custom string values which developers can access using any of the following:
An example file, 'BasicDockPanePlugin.ADSK.name', is shown below, in which we have declared 3 localized values.

# This file uses UTF8 encoding. Lines starting with # or $, or ending with = # do NOT need translating. $utf8 DisplayName= BasicDockPanePlugin Tooltip= Shows/hides the Basic Doc Pane Plug-in HelloWorldText= Hello World
'DisplayName' and 'ToolTip' variables will override the respective properties in PluginAttribute. 'HelloWorldText' is a custom text value which would be loaded but not used until the developer requests it.
In order that the name file is loaded and used for localisation, an extra attribute needs to be added to the plugin class declaration, called StringsAttribute. For example:

using System.Windows.Forms; using Autodesk.Navisworks.Api.Plugins; namespace BasicDockPanePlugin { [Plugin("BasicDockPanePlugin.BasicDockPanePlugin", "ADSK", DisplayName = "BasicDockPanePlugin", ToolTip = "Basic Docking Pane Plugin")] [DockPanePlugin(100, 300)] [Strings("BasicDockPanePlugin.ADSK.name")] //name of the Localisation file public class BasicDockPanePlugin : DockPanePlugin { public override Control CreateControlPane() { //create the control that will be used to display in the pane HelloWorldControl control = new HelloWorldControl(); control.Dock = DockStyle.Fill; //localisation control.Text = this.TryGetString("HelloWorldText"); //create the control control.CreateControl(); return control; } public override void DestroyControlPane(Control pane) { pane.Dispose(); } } }
As can be seen from the example, the full filename, including the .name extension needs to be passed in the StringsAttribute attribute.
The .name file should be saved in a subdirectory named using the localization code, for example, en-us. This directory in turn should be placed in the same location as the resulting assembly.
ApplicationResources class
Once a plug-in's localisation resources have been loaded, it is possible to access the content of the .name file from another plug-in through the ApplicationResources class.
As with the plug-ins, similar methods are available to access these string values:
- ApplicationResources..::..GetString
- ApplicationResources..::..GetStringSafe
- ApplicationResources..::..TryGetString
However, in order to obtain the strings from a specific plug-in using these methods, the required value must be prefixed by the full qualifying name of the plug-in.
For example, to access the same value as in the example above, but from a different plug-in, the developer would use:

string aString = Autodesk.Navisworks.Api.Application.Resources.TryGetString("BasicDockPanePlugin.BasicDockPanePlugin.ADSK.HelloWorldText");