Manually get resource value from resx?

Is it possible to get a value from a resource file that is not configured for the current culture of the user? Our application is based on data opposed to culture.

eg. the document is a French document, and specific labels and fields must be updated and replaced with new data.

Can I instruct the resource manager to use French .resx instead of the standard .resx?

+4
source share
3 answers

You can use the ResourceManager.GetString () method and provide the desired culture as a parameter:

var culture = CultureInfo.CreateSpecificCulture("fr-FR"); var localizedString = ResourceManager.GetString("labelName", culture); 
+3
source

you can set the typeto language in the label text in one of the forms, and then choose the language you want to show to the end user, compared to the language with the IE label text, if the label text is French, then you can show all your control names in French

NOte: only works after you create a resx file in French and manually rewrite all the names of shortcuts and buttons in French as a name, something like this.

  Name value ----------- ------------- lblname.text frenchtype name using System; using System.IO; using System.Linq; using System.Data; using System.Text; using System.Diagnostics; using System.Windows.Forms; using System.Collections.Generic; using System.ComponentModel; public partial class Form1 : Form { public form1() { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); getlanguagaefile(); InitializeComponent(); } // blah // blah private void getlanguagaefile() { if (label1.Text == "French") { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); ComponentResourceManager resources = new ComponentResourceManager(typeof(Wait)); resources.ApplyResources(this, "$this"); applyResources(resources, this.Controls); } } 

you can display french for all label texts and button texts when the form loads

  private void applyResources(ComponentResourceManager resources, Control.ControlCollection controlCollection) { foreach (Control ctl in controlCollection) { resources.ApplyResources(ctl, ctl.Name); applyResources(resources, ctl.Controls); } } } 
+2
source

You can do this through localization, where the resource files are configured in different languages ​​that you want to support. The following links, taken from here , should provide you with what you want.

" . NET Localization, Part 1: Resource Managers - Go to the" Creating Resources for Multiple Languages ​​"section for a good start.

. NET Localization, Part 2: Creating Satellite Assemblies

. NET Localization, Part 3: Text Localization

. NET Localization, Part 4: Localization of Units

+1
source

All Articles