Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# localization [duplicate]

Possible Duplicate:
C# localization , really confusing me

Could someone please share their localization steps for huge C# applications?

I'm pretty sure that the basic resource-based strategy might work when talking about small to medium projects.

However, if we speak about large products, this approach should be paired up with custom build steps and some 3rd party applications used specifically by linguists.

So, could you please advise / share some global localization strategy that is used in your applications (big enough, obviously :)

Thank you.

like image 774
Yippie-Ki-Yay Avatar asked Jul 10 '11 00:07

Yippie-Ki-Yay


2 Answers

Basic resource-based strategy works even in large enterprise applications. This is built-in and easily understandable solution, therefore each and every programmer could use it without a problem.

The only problem is, you need to somehow transform your resource files into Translation Memory files (i.e. tmx) and back - so that translators could use their standard tools.

So what you need is actually a Localization process. Is it different for large applications? Well, if you set-up correct process it would scale. Now onto process. From my point of view it should look like this:

  1. Copy resource files into appropriate folder structure (Localization Engineers should not work directly with application code base). The appropriate folder structure should be somehow similar to:
    [Project Name]
    .
    .
    [neutral] [German] [Japanese] [French]
    .
    .
    (each folder contains translatable resources in given language, neutral is usually English)
    Of course you would need to transform your code base into folder structure somehow, but this could be automated.

  2. Process your translatable resources and create transkits - zip archives containing files that need to be translated (in this case it seems like all of them). The files should be probably transformed, so you won't end-up sending out resx files. The transformation application should read contents of resx files and put translatable strings into some file of format agreed with translators (it could be simply Excel but I won't recommend this solution). Now, I can't give you the names of such tools, although I know that some commercial applications exist, for I have only worked with custom ones.

  3. Send transkits to the translators (most likely translation vendors).

  4. Upon receiving translated files (transkit) back, you need to verify it (this step is crucial). You need to ensure that transkit is complete (i.e. no translatable strings are missing) and technically correct (i.e. file encoding is correct, usually UTF-8 or UTF-16). Also it is at least good to take a glance at the file to see if there are no strange characters like 1/2, 3/4 or something - this usually mean broken encoding.

  5. Import your transkit. This is the reverse step of 2 - you need to put translated strings back to appropriate files.

  6. Copy translated files back to the original code base and run "Localization" build.

  7. Test your application for Localization problems (i.e. overlapping controls, clipping strings, incorrect encoding, etc. - this usually mean that i18n is not done right).
  8. Fix Localization/Internationalization (Localizability) defects.
  9. Proceed to 1 until UI/String freeze period. This assumes that translators would use Translation Memory of some kind and won't charge (or charge less) you for re-translating previously translated strings.
  10. Automate all possible steps and your done.

Apart from that you might won't to establish your common glossary of terms and do linguistic review on translated content.

like image 184
Paweł Dyda Avatar answered Oct 21 '22 14:10

Paweł Dyda


I think you can rely heavily on the resource framework provided by .NET with a few modifications to make it more appropriate for large projects, namely to build and maintain resources independently of the application and to eliminate the generated properties that refer to each resource by name. If there are other goals appropriate for large project localization that aren't addressed below, please describe them so I can consider them too.

  1. Create a stand-alone project to represent your resources that can be loaded as a separate DLL.
  2. Add a "Resources" file to your project by selecting the link on the Resources tab of the project properties: "This project does not contain a default resources file. Click here to create one."
  3. Add another resource with the same root name to represent another language, for example "Resource.de.resx" for German. (Visual Studio apparently uses the filename to determine the language that the resource file represents). Move it to the same directory/folder as the default Resources file. (Repeat for every language.)
  4. In the properties of the Resources.resx file, delete "ResXFileCodeGenerator" from the Custom Tool property to prevent default code generation in the Application's "Properties" namespace. (Repeat for every language.)
  5. Explicitly/manually declare your own resource manager that loads the newly created resources with a line like:

    static System.Resources.ResourceManager resourceMan = new System.Resources.ResourceManager( "LocalizeDemo.Properties.Resources", typeof(Resources).Assembly);

  6. Implement a file that can be generated that contains a list of all the resources you can refer to (see figure 1)

  7. Implement a function to retrieve and format strings (see figure 2).

  8. Now you have enough that you can refer to translated strings from any number of applications (see figure 3).

  9. Use System.Resources.ResXResourceWriter (from System.Windows.Forms.dll) or System.Resources.ResourceWriter (System.dll) to generate the resources instead of having the Resx files be your primary source. In our project, we have an SQL database that defines all of our strings in each language and part of our build process generates all the Resx files before building the resources project.

  10. Now that you can generate your Resx files from any format, you can use any format you want (in our case an SQL database, which we export to and import from Excel spreadsheets) to provide files to send out to translators.

  11. Also notice that the translated resources are building as satellite DLLs. You could conceivably build each language independently with the right command line tools. If that is part of your question (how to do that) let me know. But for the moment, I'll assume you know about that since you already mentioned custom build steps.

Figure 1 - enum identifying all available resources:

namespace MyResources
{
   public enum StrId
   {
      Street
      ....
   }
}

Figure 2 - Code to load and return formatted resource strings:

namespace MyResources
{
   public class Resources
   {
      static System.Resources.ResourceManager resourceMan =
         new System.Resources.ResourceManager("MyResources.Properties.Resources",
         typeof(Resources).Assembly);

      public static string GetString(StrId name,
         System.Globalization.CultureInfo culture = null, params string[] substitutions)
      {
         if (culture == null) culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
         string format = resourceMan.GetString(name.ToString(), culture);
         if (format != null)
         {
            return string.Format(format, substitutions);
         }
         return name.ToString();
      }
   }
}

Figure 3 - accessing resources:

using MyResources;

namespace LocalizationDemo
{
   class Program
   {
      static void Main(string[] args)
      {
         System.Threading.Thread.CurrentThread.CurrentUICulture =
            new System.Globalization.CultureInfo("de-DE");
         Console.WriteLine(Resources.GetString(StrId.Street));
      }
   }
}
like image 28
BlueMonkMN Avatar answered Oct 21 '22 14:10

BlueMonkMN