Change the "(default)" ResX language in a C# app

I'm making an app in C#, with a lot of forms and other stuff. I wanted to localize it, so I used the integrated localization functions in VS. The app was originally in French (cause I am) with English translation RESXes, but now that it is on Codeplex with some other developers who doesn't speak french, I want to change the "default" language in the app and the RESX files so they can translate to other languages without reading French. Cause when you choose another language in VS Form Designer, it shows the default language (here, French). I tried to rename all the files, but the problem is all the form properties are stored in the default RESX, the French one, so if I rename, it will break all the stuff. Is it possible to change the default language to English?

EDIT: I think I need to be more precise. The app is originally in French. Then I localized it in English. There is now a MainWindow.resx that contains form properties + original french localization and a MainWindow.en-US.resx that contains ONLY english localization. So if in the Designer, in "Language" I choose "(default)" it shows me the MainWindow.resx FRENCH, and if I want to translate, It shows me the French texts. To make the translation more easy for the other developers, I want to make the MainWindow.resx ENGLISH localization and create a seperate MainWindow.fr-FR.resx. I also tried to change "Neutral Language" in AssemblyInfo.cs, no effect.


You can change the CurrentCulture and CurrentUICulture in your application through code. It's the same approach that is used to change the apps language at runtime.

Have a look at this code:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

Hope it helps.


While you could do renames in file system to achieve neutral culture/resource change, you need to update project file as well, which is cumbersome. I found the simplest way was to do this via Visual studio extension named ResXManager.

Steps in detail:

1. Run & configure ResXManager

In VS: Tools -> ResXManager.

  • Choose configuration tab (below)
  • Disable option "Confirm adding new resource files". Otherwise you would have to click later per each file to accept its creation.
  • Set Neutral Resource language so it would show up with a correct flag for your viewing pleasure.
  • Switch back to main tab where you see all solution resources with translations side-by-side.
  • 2. Extract neutral culture resources as explicitly French

  • Adda a new column for French using the "Add new language" button in the toolbar.
  • Copy all French resources from existing neutral language column (CTRL-SHIFT-DOWN helps top select full column)
  • Paste all resources to new French column.
  • Note that ResXManager will create new resx files for you and add them to project file.

    3. Set neutral culture reousrces to English ones

  • Copy all English resources from specific culture column
  • Paste all resources to Neutral culture column
  • 4. Inform .Net that neutral culture is now english

    [assembly: NeutralResourcesLanguage("en-GB", UltimateResourceFallbackLocation.MainAssembly)]
    

    5. Remove explicit English resx files.

    Since the neutral resx files now already contain english resources then you don't need to keep them the culture-specific ones. Unfortunately ResXManager didn't seem to have a button for this but you can I chose to use VS solution manager filter "en-GB.resx" and deleted all files it found. Again, doing it within VS automatically updates your project file.

    All done.

    链接地址: http://www.djcxy.com/p/95380.html

    上一篇: Visual Studio 2008不加载MFC dll符号

    下一篇: 在C#应用程序中更改“(默认)”ResX语言