.NET Library Localizer

What is it?
.NET Library Localizer is a cloud API for processing compiled .NET libraries made with C# or VB.NET

What does it do?
It facilitates translation of .NET assemblies (DLLs) made with framework versions from 4.0 up to 4.6

Overview

This article is intended for developers who make .NET software using Visual Studio with nuget installed.


An Internet connection is required in order to connect to the API
The minimum framework version for using the API is 4.0

Setup a project

  1. Open Visual Studio and create a new Class Library project, name it TestLibrary.VB if you are using VB.NET or TestLibrary.CSharp for C#
  2. Delete Class1.vb or Class1.cs and create a new class, name it Test.vb or Test.cs
  3. Open project properties and then open the Assembly Information editor; specify the Neutral Language (for this walkthrough) as English (United States)
  4. PM> Install-Package Newtonsoft.Json
  5. Add the helper class in your project:
    1. If you are using VB.Net download this file (Helper.vb.zip)
    2. if you are using C# download this file (Helper.cs.zip)
  6. Open Test.vb or Test.cs and add a function that returns a string

VB.NET example:

    Function GetString() As String
        Return "Hello World!"
    End Function

CSharp example:

public string GetString() { return "Hello World!"; }


The result so far...

TestLibrary.VB - Start.zip (Without dependencies)
TestLibrary.CSharp - Start.zip (Without dependencies)

Load your DLL in the Cloud

First you need to compile your DLL project, then copy either TestLibrary.VB.dll or TestLibrary.CSharp.dll to a new folder in addition to Newtonsoft.Json.dll.

Using code

  1. Open Visual Studio and create a new Console Application project, name it NLL.Com.VB if you are using VB.NET or NLL.Com.CSharp if you are using C#
  2. Now, you need to add 3 references before you connect to the API:
    1. First, Download NLL.zip and add reference to NLL.dll file
    2. PM> Install-Package Newtonsoft.Json
    3. PM> Install-Package DotNetZip
  3. Open Module1.vb or Program.cs and edit Sub Main() or static void Main(string[] args); here is the code to insert...

For VB.NET (Download Project)

Dim NLLClient As New NLL.Client
NLLClient.Load("<Path to TestLibrary.VB.dll>", "TestLibrary.VB", "en-US")

File.WriteAllBytes("TestLibrary.VB.dll", NLLClient.DLLFile)
File.WriteAllBytes(NLLClient.LanguageFileName, NLLClient.LanguageFile)

Console.WriteLine(String.Format("OK! (Elapsed: {0}...)", NLLClient.Elapsed.ToString))
Console.ReadLine()

For CSharp (Download Project)

NLL.Client NLLClient = new NLL.Client();
NLLClient.Load("<Path to TestLibrary.CSharp.dll>", string.Empty, "en-US");

File.WriteAllBytes("TestLibrary.CSharp.dll", NLLClient.DLLFile);
File.WriteAllBytes(NLLClient.LanguageFileName, NLLClient.LanguageFile);

Console.WriteLine(string.Format("OK! (Elapsed: {0}...)", NLLClient.Elapsed.ToString()));
Console.ReadLine();

Run the application, and wait for the result.

The result would be two files saved in the application folder, the modified library "TestLibrary.VB.dll" or "TestLibrary.CSharp.dll" with another file named "TestLibrary.VB en-US" or "TestLibrary.CSharp en-US".

The second file contains simply JSON data representing the strings in the input DLL. Make two copies of this file in the same folder, name the first "TestLibrary.VB fr-FR" or "TestLibrary.CSharp fr-FR" and the second "TestLibrary.VB es-ES" or "TestLibrary.CSharp es-ES".

Now use any text editor (like Notepad) to open the two files you created so far. Look for "Hello World!" and change it to "Bonjour le monde !" inside the file named "TestLibrary.VB fr-FR" or "TestLibrary.CSharp fr-FR" and to "Hola Mundo!" in "TestLibrary.VB es-ES" or "TestLibrary.CSharp es-ES".

That's it! You have now a fully localizable DLL with translations.

Its not over yet, let's go to the test!

Using GUI tool

Download the GUI Tool.
Make sure to enter all the values properly for each project language

Example for VB.NET project (the root namespace is required if not left blank in the VB project, otherwise the server returns an error)

Options for CSharp project (The default namespace is different from root namespace in Visual Basic, leave it blank)

Testing the result

Now that we have the result DLL from the API, we shall test it.

1. Add a reference to TestLibrary.VB.dll or TestLibrary.CSharp.dll back from the server to a new Console Application project called ConsoleDemo.VB or ConsoleDemo.CSharp

2. Open Module1.vb or Program.cs, and update Sub Main() or static void Main(string[] args) with the the following code

For VB.NET

        Dim Test As New TestLibrary.VB.Test
        Dim CultureName As String = "en-US"

        Console.WriteLine(CultureName)
        TestLibrary.VB.HandCode.Helper.ChangeLanguage(CultureName)
        Console.WriteLine(Test.GetString)
        Console.WriteLine()

        CultureName = "fr-FR"
        Console.WriteLine(CultureName)
        TestLibrary.VB.HandCode.Helper.ChangeLanguage(CultureName)
        Console.WriteLine(Test.GetString)
        Console.WriteLine()

        CultureName = "es-ES"
        Console.WriteLine(CultureName)
        TestLibrary.VB.HandCode.Helper.ChangeLanguage(CultureName)
        Console.WriteLine(Test.GetString)

        Console.ReadLine()

For CSharp

            TestLibrary.CSharp.Test Test = new TestLibrary.CSharp.Test();
            string CultureName = "en-US";

            Console.WriteLine(CultureName);
            HandCode.Helper.ChangeLanguage(CultureName);
            Console.WriteLine(Test.GetString());
            Console.WriteLine();

            CultureName = "fr-FR";
            Console.WriteLine(CultureName);
            HandCode.Helper.ChangeLanguage(CultureName);
            Console.WriteLine(Test.GetString());
            Console.WriteLine();

            CultureName = "es-ES";
            Console.WriteLine(CultureName);
            HandCode.Helper.ChangeLanguage(CultureName);
            Console.WriteLine(Test.GetString());

            Console.ReadLine();

3. Inside the project add the three translation files ("TestLibrary.VB en-US", "TestLibrary.VB fr-FR" and "TestLibrary.VB es-ES" or "TestLibrary.CSharp en-US", "TestLibrary.CSharp fr-FR" and "TestLibrary.CSharp es-ES") to the root of your project, select all three and switch to file properties, select Copy Always in Copy to Output Directory

4. Run the project and see it in action...

Download VB.Net demo ConsoleDemo.VB
Download C# demo ConsoleDemo.CSharp

Contact

If you want to tell me about any bugs, make suggestions or critics, or simply comment, send me an email at handcode@outlook.com.

If you are really interested, and want an account with custom features on the server side contact me via Upwork https://www.upwork.com/freelancers/~015a6b6dbddab22502.

Thank you for reading.

Sincerely,
Mohamed Amine SEBBANE