-
Notifications
You must be signed in to change notification settings - Fork 665
Localization best practices for Dynamo developers
Making a project localizable includes the following steps:
- Adding
*.resx
and*.en-US.resx
files to project - Updating
AssemblyInfo.cs
of the project - Referencing the string resource in
*.cs
files - Referencing the string resource in
*.xaml
files
These steps are detailed in the following sections.
TODO: Add images for steps to add these files...
Note that both *.resx
and *.en-US.resx
files must always be kept completely in-sync. The process of updating these files typically includes adding the desirable strings into *.resx
file, and then copy it to overwrite *.en-US.resx
file. This way they are always 100% identical.
With *.resx
and *.en-US.resx
files added to the project, the AssemblyInfo.cs
must be updated to specify a fallback assembly in the event that a desirable localized *.resources.dll
cannot be found during runtime (typically the fallback is on en-US
resources). This can be done in either of the following ways.
This is the preferred way for any development work under DynamoDS/Dynamo
repository. In addition to the existing Properties/AssemblyInfo.cs
file that came with the project, add a link reference to AssemblySharedInfo.cs
file at this location:
Dynamo/src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs
Having this reference ensures that the version number always matches that of the main Dynamo build. This is how a link reference can be added:
TODO: Add an image with screenshot
If for some reason Option 1 is not feasible, then the existing Properties/AssemblyInfo.cs
can be updated by adding the following line:
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
To reference a string by its ID SettingsMigrationDialogTitle
in a CSharp file, do this:
string dialogTitle = Properties.Resources.SettingsMigrationDialogTitle;
To reference the same string in *.xaml
file, do this:
<Window xmlns:p="clr-namespace:Dynamo.Wpf.Properties"
...
Title="{x:Static p:Resources.SettingsMigrationDialogTitle}"
...>
<Button Content="{x:Static p:Resources.MigrationAcceptButton}" ... />
</Window>
- Move Get a color given a color range string into the corresponding
*.resx
file. - Give an Id of
ColorRangeDescription
to the newly added string. - Copy the
*.resx
file to overwrite*.en-US.resx
file so they match up. - Add a
NodeDescription
attribute like so:
[NodeDescription("ColorRangeDescription",typeof(DSCoreNodesUI.Properties.Resources))]
public class ColorRange : NodeModel
{
// ...
}
- Adding search terms for a
NodeModel
- Localizing
enum
values for display
Looking for help with using the Dynamo application? Try dynamobim.org.
- Dynamo 2.0 Language Changes Explained
- How Replication and Replication Guide work: Part 1
- How Replication and Replication Guide work: Part 2
- How Replication and Replication Guide work: Part 3