简体   繁体   中英

Forcing the culture of a .NET application non-programmatically

I've found many posts about programmatically forcing the culture of a .NET WinForm program (C#, .NET 4.5).

Is there a way to force the culture without code?

The procedure on Windows 7 (the dialog and names have been altered many times):

  • Start + Control Panel
  • Click Region and Language
  • Click the "Administrative" tab
  • Click the "Change system locale" button
  • Pick one of the locales that starts with "English" and matches where your customer lives.

Any program you start after this will initialize with the default culture you selected in this dialog and that will exercise your satellite assemblies.

Note that changing the Thread.CurrentThread.CurrentCulture and CurrentUICulture properties, as suggested in a comment, is not a true substitute. Threadpool threads still initialize themselves to the system locale. A very nasty problem that finally got fixed in .NET 4.5 with the addition of the CultureInfo.DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture properties.

Do beware that many native Windows dialogs (like MessageBox and OpenFileDialog) will still display text in the language of your operating system. You'd need to purchase a license for Windows Ultimate and install the language pack to get those to change. An MSDN subscription is a good way to get the same language specific operating system that your user boots.

One more strange option that may work for you is to create bootstrap exe that will set bot culture settings (CurrentCulture and CurrentUICulture) and than load your actual exe and call Main function of correct class. Has all drawbacks of only setting culture on main thread, but may be OK as stopgap measure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM