Skip to content

Multilanguage Client-Addin for NAV2009

October 26, 2010

Because i live in a multilingual country (switzerland) we need to develop our solutions multilingual too. Inside Navision this is no big deal, but when it comes to addins, it’s a bit difficult.

So what can we do to achieve that?

There are two basic solutions to do it. You can eighter use de NAV Textconstants and send the correct caption to your addin (set some xml to the SourcExpression) or you can generate Multilanguage Resource Files within .Net and store your captions there.

Both methods have their up- and downsides. Let’s compare them:

TextConstats
+
you can change  and add captions easy within NAV
-slow (you need to send that data to your addin
-overhead

ResourceFiles in .NET
+Fast (no need of sending data)
+Very Easy to do
+Better when dealing with lots of captions
-Every change of  a caption needs an install of your localized resource Dll on every client
-No overhead

In my opinion the Resource File method is a lot better than the TextConstant method when you are dealing with lots of captions because its just so easy and in most cases captions don’t need to be changed very often and since it’s an addin, a reinstall of the addin component on every client is nothing new…

Example

First you need to add a new Resource File item to your project and name it something like this: StaticLanguageResources.resx

This is going to be your default language file. I prefere to use the ENU Language as default.
In this file you need to add the name of your caption ex. “TitleCaption” and its Value “This is a nice title”

Now you can add a second Resource File and name it <Original Resource File Name>.<Localized Language>.resx
for ex. for swiss-german it would be StaticLanguageResources.de-CH.resx

In this fiel you can add your localized translation.

To get the right translation we need a little bit of code. I used a static class and method for this

internal static class StaticLanguageHelper
{
  private static ResourceManager rm;
  public static string GetString(string Field)
  {
  if (rm == null)
    rm = new ResourceManager("NamespaceOfStaticLanguageResources", Assembly.GetExecutingAssembly());
  return (rm.GetString(Field, Thread.CurrentThread.CurrentUICulture));
  }
}

With this small peace of code we can catch the currently selected language of the RTC Client and us that to get our localized translations!

To access your captions we just use this:

Label1.Text = StaticLanguageHelper.GetString("TitleCaption");
Advertisements

From → C# .NET, Dynamics NAV

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s