Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>Add a Resource file to your project (you can call it "strings.resx") by doing the following: <br/>Right-click <strong>Properties</strong> in the project, select <strong>Add -> New Item...</strong> in the context menu, then in the list of <strong>Visual C# Items</strong> pick <strong>"Resources file"</strong> and name it <code>strings.resx</code>.</li> <li>Add a string resouce in the resx file and give it a good name (example: name it "Hello" with and give it the value "Hello")</li> <li>Save the resource file (<strong>note:</strong> this will be the <strong>default</strong> resource file, since it does not have a two-letter language code)</li> <li>Add references to your program: <code>System.Threading</code> and <code>System.Globalization</code></li> </ul> <p>Run this code:</p> <pre><code>Console.WriteLine(Properties.strings.Hello); </code></pre> <p>It should print "Hello".</p> <p>Now, add a new resource file, named "strings.fr.resx" (note the "fr" part; this one will contain resources in French). Add a string resource with the same name as in strings.resx, but with the value in French (Name="Hello", Value="Salut"). Now, if you run the following code, it should print Salut:</p> <pre><code>Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr-FR"); Console.WriteLine(Properties.strings.Hello); </code></pre> <p>What happens is that the system will look for a resource for "fr-FR". It will not find one (since we specified "fr" in your file"). It will then fall back to checking for "fr", which it finds (and uses).</p> <p>The following code, will print "Hello":</p> <pre><code>Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); Console.WriteLine(Properties.strings.Hello); </code></pre> <p>That is because it does not find any "en-US" resource, and also no "en" resource, so it will fall back to the default, which is the one that we added from the start.</p> <p>You can create files with more specific resources if needed (for instance strings.fr-FR.resx and strings.fr-CA.resx for French in France and Canada respectively). In each such file you will need to add the resources for those strings that differ from the resource that it would fall back to. So if a text is the same in France and Canada, you can put it in strings.fr.resx, while strings that are different in Canadian french could go into strings.fr-CA.resx.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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