Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your C# function, the follow variable <em>exceptionMessage</em> :</p> <pre><code>string exceptionMessage = ResourcesNameSpace.ResourceFileName.strYouMustSelectAValidCategory; </code></pre> <p>can assume the correct value (the spanish or the english text), if you have the key "strYouMustSelectAValidCategory" in both files ResourceFileName.resx and ResourceFileName.en-US.resx.</p> <p>So, you can then write:</p> <pre><code>throw new Exception(exceptionMessage); </code></pre> <p>The application will "know" the current culture in runtime :) </p> <p>To set the current culture in your application, you can use, say, a link button with code-behind:</p> <pre><code>// Changes the CurrentUICulture of the current thread: Thread.CurrentThread.CurrentUICulture = new CultureInfo( "en-US", false ); </code></pre> <p>(source: <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentuiculture.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentuiculture.aspx</a>)</p> <hr> <p>To add resource files to the project, you can right click your project icon (ModeloInventario), select "Add New Item", select "Resource file" and type a name for your file (I'm using vs2008, hope it isn't too different!).</p> <p>Your default Resource file can be named: <strong>MIResources.resx</strong> </p> <p>Then, you add another one, and name it: <strong>MIResources.en-US.resx</strong>, for english... <strong>MIResources.fr</strong> for french... And so on, one file for each additional language you would like (Language codes here: <a href="http://msdn.microsoft.com/en-us/library/ms533052%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms533052%28VS.85%29.aspx</a>).</p> <p>The default resource file is the default place where a value is searched when the item is not present in the current culture resource file or when there is no resource file for the current culture.</p> <p>You then start by adding the keys and values to your default resource file (strYouMustSelectAValidCategory: Debe seleccionarse una Categoría válida.), and then add the same keys to the MIResources.en-US.resx with the transation (strYouMustSelectAValidCategory: You must select a valida category.)... So, same keys, different values.</p> <p>After all this, you can get a key's (string) value anywhere in the application, using:</p> <pre><code>string str = ResourcesNameSpace.MIResources.strYouMustSelectAValidCategory; </code></pre> <p>The ResourcesNameSpace is the namespace that's created with the resource file, if any! You can check it or edit it in the code-behind of the default resource file... If none, you don't need to use it (as long as you get to your MIResources.strYouMustSelectAValidCategory).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload