<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shannon Coupland, Author at DMC, Inc.</title>
	<atom:link href="https://static.dmcinfo.com/blog/author/shannonc/feed/index.xml" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Thu, 03 Sep 2026 20:50:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://static.dmcinfo.com/wp-content/uploads/2025/04/site-icon-150x150.png</url>
	<title>Shannon Coupland, Author at DMC, Inc.</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Basic JavaScript Localization Setup Using JSON with Visual Studio Code</title>
		<link>https://static.dmcinfo.com/blog/15997/basic-javascript-localization-setup-using-json-with-visual-studio-code/</link>
		
		<dc:creator><![CDATA[Shannon Coupland]]></dc:creator>
		<pubDate>Mon, 16 Sep 2024 12:55:30 +0000</pubDate>
				<category><![CDATA[Web Application Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/15997/basic-javascript-localization-setup-using-json-with-visual-studio-code/</guid>

					<description><![CDATA[<p>Frontend localization is different than .NET backend localization in that there is not an established “correct way” to accomplish translating text in JS and related frameworks. This is a basic example using JavaScript, but more customization can be done with methods and helpers for accessing text, especially if you are using a JS framework like [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/15997/basic-javascript-localization-setup-using-json-with-visual-studio-code/">Basic JavaScript Localization Setup Using JSON with Visual Studio Code</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Frontend localization is different than .NET backend localization in that there is not an established “correct way” to accomplish translating text in JS and related frameworks. This is a basic example using JavaScript, but more customization can be done with methods and helpers for accessing text, especially if you are using a JS framework like React or Material UI.</p>



<p class="wp-block-paragraph"><strong>Prerequisites</strong></p>



<ul class="wp-block-list">
<li>Visual Studio Code installed on your machine</li>



<li>Node.js version 20.17.0 installed on your machine (other versions of Node will likely work as well)</li>



<li>General understanding of navigation in Visual Studio Code IDE</li>
</ul>



<p class="wp-block-paragraph"><strong>Steps</strong></p>



<ol class="wp-block-list">
<li>Open Visual Studio Code and create an empty folder “LocalizationExampleJS”:<br>
 <br>
 <img decoding="async" alt="Open Visual Studio Code" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-JavaScript-1.png"><br>
 &nbsp;</li>



<li value="2">Add the file &ldquo;LocalizationExample.js&rdquo; at the top level of your new folder:<br />
 <br />
 <img decoding="async" alt="" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-JavaScript-2.png"  /><br />
 &nbsp;</li>



<li value="3">Add a new subfolder &quot;Resources&quot;&nbsp;with empty files &ldquo;en-US.json&rdquo;, &ldquo;es-MX.json&rdquo;, and &ldquo;fr-FR.json&rdquo;:<br />
 <br />
 <img decoding="async" alt="" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-JavaScript-3.png"  /><br />
 <br />
 <img decoding="async" alt="" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-JavaScript-4.png"  /></li>



<li>Add the following code to each JSON translation file. It’s important for the text keys in all 3 files to be identical – in this case, the sample text we are using has the key “HelloWorld”.</li>
</ol>



<p class="wp-block-paragraph"><code><strong>en-US.json</strong></code></p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">JSON</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;code>
{
  "HelloWorld": "Hello World!"
}
es-MX.json
{
  "HelloWorld": "¡Hola Mundo!"
}
fr-FR.json
{
  "HelloWorld": "Bonjour le monde!"
}
&lt;/code></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">&lt;code&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;HelloWorld&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;Hello World!&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span>
<span class="line"><span style="color: #D4D4D4">es-MX.json</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;HelloWorld&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;¡Hola Mundo!&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span>
<span class="line"><span style="color: #D4D4D4">fr-FR.json</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;HelloWorld&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;Bonjour le monde!&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span>
<span class="line"><span style="color: #D4D4D4">&lt;/code&gt;</span></span></code></pre></div>



<ol class="wp-block-list">
<li value="5">Add the following code to &ldquo;LocalizationExample.js&rdquo;. This will enable you to supply a command line argument containing your desired locale string during testing. (Note that in an actual web frontend solution, the frontend code would need to access the current user&rsquo;s culture from the server, NOT via command line argument.)</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">JavaScript</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;code>
const args = process.argv.slice(2);
const currentCulture = args&#91;0&#93;;
console.log("Your supplied culture is: " + currentCulture);
&lt;/code></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">code</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">const args = process.argv.slice(2);</span></span>
<span class="line"><span style="color: #D4D4D4">const currentCulture = args&#91;0&#93;;</span></span>
<span class="line"><span style="color: #D4D4D4">console.log(&quot;Your supplied culture is: &quot; + currentCulture);</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">code</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<ol class="wp-block-list">
<li value="6">Below the code to extract current culture from command line arguments, add the following code to access the &ldquo;HelloWorld&rdquo; string for the supplied culture. If a culture is supplied that is not present in the application, then an error message will log accordingly, and the application will default to the &ldquo;en-US&rdquo; locale.</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">JavaScript</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;code>
var pathToJson = "./Resources/" + args&#91;0&#93; + ".json";
try {
  const jsonObj = require(pathToJson);
  console.log(jsonObj.HelloWorld);
}
catch (err) {
  console.log("Culture \"" + currentCulture + "\" does not exist in this application - using default locale en-US.")
  pathToJson = "./Resources/en-US.json";
  const jsonObj = require(pathToJson);
  console.log(jsonObj.HelloWorld);
}
&lt;/code></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">code</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">var pathToJson = &quot;./Resources/&quot; + args&#91;0&#93; + &quot;.json&quot;;</span></span>
<span class="line"><span style="color: #D4D4D4">try </span><span style="color: #569CD6">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">const</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4"> = </span><span style="color: #DCDCAA">require</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">pathToJson</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">HelloWorld</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #569CD6">}</span></span>
<span class="line"><span style="color: #D4D4D4">catch (err) </span><span style="color: #569CD6">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&quot;Culture </span><span style="color: #D7BA7D">\&quot;</span><span style="color: #CE9178">&quot;</span><span style="color: #D4D4D4"> + </span><span style="color: #9CDCFE">currentCulture</span><span style="color: #D4D4D4"> + </span><span style="color: #CE9178">&quot;</span><span style="color: #D7BA7D">\&quot;</span><span style="color: #CE9178"> does not exist in this application - using default locale en-US.&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">pathToJson</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;./Resources/en-US.json&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">const</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4"> = </span><span style="color: #DCDCAA">require</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">pathToJson</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">HelloWorld</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #569CD6">}</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">code</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<ol class="wp-block-list">
<li value="7">Your code is ready for testing! It should look something like this:</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">JavaScript</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;code>
const args = process.argv.slice(2);
const currentCulture = args&#91;0&#93;;
console.log("Your supplied culture is: " + currentCulture);

var pathToJson = "./Resources/" + args&#91;0&#93; + ".json";
try {
  const jsonObj = require(pathToJson);
  console.log(jsonObj.HelloWorld);
}
catch (err) {
  console.log("Culture \"" + currentCulture + "\" does not exist in this application - using default locale en-US.")
  pathToJson = "./Resources/en-US.json";
  const jsonObj = require(pathToJson);
  console.log(jsonObj.HelloWorld);
}
&lt;/code></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">code</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">const args = process.argv.slice(2);</span></span>
<span class="line"><span style="color: #D4D4D4">const currentCulture = args&#91;0&#93;;</span></span>
<span class="line"><span style="color: #D4D4D4">console.log(&quot;Your supplied culture is: &quot; + currentCulture);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">var pathToJson = &quot;./Resources/&quot; + args&#91;0&#93; + &quot;.json&quot;;</span></span>
<span class="line"><span style="color: #D4D4D4">try </span><span style="color: #569CD6">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">const</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4"> = </span><span style="color: #DCDCAA">require</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">pathToJson</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">HelloWorld</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #569CD6">}</span></span>
<span class="line"><span style="color: #D4D4D4">catch (err) </span><span style="color: #569CD6">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&quot;Culture </span><span style="color: #D7BA7D">\&quot;</span><span style="color: #CE9178">&quot;</span><span style="color: #D4D4D4"> + </span><span style="color: #9CDCFE">currentCulture</span><span style="color: #D4D4D4"> + </span><span style="color: #CE9178">&quot;</span><span style="color: #D7BA7D">\&quot;</span><span style="color: #CE9178"> does not exist in this application - using default locale en-US.&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">pathToJson</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;./Resources/en-US.json&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">const</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4"> = </span><span style="color: #DCDCAA">require</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">pathToJson</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">jsonObj</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">HelloWorld</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #569CD6">}</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">code</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<ol class="wp-block-list">
<li value="8">Open a terminal and test out the LocalizationExample solution using the command node <strong><code>.\LocalizationExample.js</code></strong> xx-XX, where &ldquo;xx-XX&rdquo; is a locale string representing the combination of a language and a region. Try out &ldquo;es-MX&rdquo;, &ldquo;fr-FR&rdquo;, &ldquo;en-US&rdquo;, and &ldquo;pt-BR&rdquo; (Brazilian Portuguese) as command line arguments.<br />
 <br />
 Note that the HelloWorld resource for the cultures &ldquo;en-US&rdquo;, &ldquo;es-MX&rdquo;, and &ldquo;fr-FR&rdquo; all appear translated as expected. However, the &ldquo;pt-BR&rdquo; locale yields the HelloWorld string in English, because this culture is not present in the collection of translations, and our code explicitly defaults to the &ldquo;en-US&rdquo; U.S. English locale in this case.</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-JavaScript-6.png" alt=""/></figure>



<h2 id="h-localization-tips-and-tricks" class="wp-block-heading"><strong>Localization Tips and Tricks</strong></h2>



<p class="wp-block-paragraph">When it comes to localization, there is a lot more to consider than simply translating text and accessing it appropriately from code. Read on to learn some tips and tricks for elevating your localization solution!</p>



<p class="wp-block-paragraph"><strong>Text Key Organization</strong></p>



<p class="wp-block-paragraph">Generally, DMC has found that it is beneficial to organize text keys into separate files based not only on language, but also based on what page of your application the text belongs on. For backend localization, this is likely best done by splitting text by controller. Here is an example of a backend localization file structure that includes two controllers, “Login.cs” and “Home.cs”, and two cultures, a default culture and “es-MX”:</p>



<ul class="wp-block-list">
<li>Resources folder
 
 
<ul class="wp-block-list" style="list-style-type:circle;">
  

<li>Login folder
  

<ul class="wp-block-list">
   

<li>Login.resx</li>


   

<li>Login.es-MX.resx</li>


  </ul>


  </li>


  

<li>Home folder
  

<ul class="wp-block-list">
   

<li>Home.resx</li>


   

<li>Home.es-MX.resx</li>


  </ul>


  </li>


 </ul>
</li>
</ul>



<p class="wp-block-paragraph">This separation organizes your translated text in a way that is easily modifiable for each individual page of your application.</p>



<p class="wp-block-paragraph">In the event that identical text appears in multiple places in your application in English, it is still beneficial to duplicate that text key/value entry across pages, rather than maintaining a single key/value item. For example, if the word “Email” exists on both the “Login” and “Home” pages in the example above, this text key/value should exist in both the “Login” resource files and “Home” resource files. This enables you to update the text in one place without modifying the same text elsewhere, if desired. Also, translations of the same English word or phrase could be different across different languages, depending on the context of how the word or phrase is used – in this case, separate text/key values are necessary for translators to appropriately translate your application text.</p>



<p class="wp-block-paragraph"><strong>Variables and Pluralization</strong></p>



<p class="wp-block-paragraph">Variables and pluralization can be quite tricky to handle in any localization solution. For a backend solution with .resx files, if you have a sentence to translate with a variable in the middle, you need to separate any given string key/value into separate parts that precede and follow the variable.</p>



<p class="wp-block-paragraph">For example, say you want to include the phrase “Hello, {name} – welcome to my site!” The following key/value structure would need to be implemented in each .resx file to handle this phrase:</p>


<table border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="width:319px;">


<p class="wp-block-paragraph"><strong>Key</strong></p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph"><strong>Value (en-US)</strong></p>



<p class="wp-block-paragraph">Hello_BeforeName</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“Hello, “</p>



<p class="wp-block-paragraph">Hello_AfterName</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“ – welcome to my site!”</p>


</td>
</tr>
</tbody>
</table>


<p class="wp-block-paragraph">&nbsp;</p>



<p class="wp-block-paragraph">Additionally, numeric variables add an extra layer of complexity to a localization solution, because pluralization must be implemented for these. The way words are pluralized can actually differ significantly across languages. For example, Slavic languages (e.g. Russian, Czech) have a different style of pluralization for 5 or more of an item than they do for zero, one, or 2-4 items. So a solution that translates to Slavic languages must implement separate logic for pluralizing 5+ items than for other items. For example, the sentence “You have {number} items in your cart!” may have a key/value structure like this in English:</p>


<table border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="width:319px;">


<p class="wp-block-paragraph"><strong>Key</strong></p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph"><strong>Value (en-US)</strong></p>



<p class="wp-block-paragraph">ItemsInCart_BeforeValue_0</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“You have “</p>



<p class="wp-block-paragraph">ItemsInCart_AfterValue_0</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“ items in your cart!”</p>



<p class="wp-block-paragraph">ItemsInCart_BeforeValue_1</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“You have “</p>



<p class="wp-block-paragraph">ItemsInCart_AfterValue_1</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“ item in your cart!”</p>



<p class="wp-block-paragraph">ItemsInCart_BeforeValue_2to4</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“You have “</p>



<p class="wp-block-paragraph">ItemsInCart_AfterValue_2to4</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“ items in your cart!”</p>



<p class="wp-block-paragraph">ItemsInCart_BeforeValue_5up</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“You have “</p>



<p class="wp-block-paragraph">ItemsInCart_AfterValue_5up</p>


</td>
<td style="width:319px;">


<p class="wp-block-paragraph">“ items in your cart!”</p>


</td>
</tr>
</tbody>
</table>


<p class="wp-block-paragraph">As you can see, this is a complex case to translate for – there are 8 total key/value pairs to accommodate just one sentence that integrates a numeric variable. To avoid the need for this, one solution is to reduce or eliminate the need for accommodating plurals – for example, you could rephrase “You have {number} items in your cart!” to instead become “Number of Items in Cart: {number}”. This would only require one key/value pair to be translated instead of eight.</p>



<p class="wp-block-paragraph"><strong>Fallback Cultures</strong></p>



<p class="wp-block-paragraph">When a user’s specific locale does not have a translation present in your application, it can be beneficial to implement fallback cultures so this user is given a more suitable approximation of their desired language. For example, say a Spanish speaker lives in Spain and therefore has their browser locale set to “es-ES”. However, your application only has resources for Mexican Spanish “es-MX”. Ideally this person in Spain would see the application in Mexican Spanish rather than the application default of English, because Mexican Spanish more closely matches their desired language than English does.</p>



<p class="wp-block-paragraph">Using .NET backend localization, fallback cultures can be implemented by simply renaming any files ending in “es-MX.resx” to instead end in “es.resx”. Per .NET’s <a href="#culture-fallback-scenarios">culture fallback scenarios</a>, upon receiving a request from the Spain Spanish user, .NET will still search for “es-ES” first. But upon not finding this specific culture, .NET will “fall back” to just the “es” portion of the locale string and will access the text as it exists in this new general Spanish file. Users using Mexican Spanish “es-MX” will see the same behavior.</p>



<p class="wp-block-paragraph"><strong>Common Pitfalls</strong></p>



<p class="wp-block-paragraph">Localization can be complicated, and there are some common pitfalls you may encounter if you are implementing your own localization solution. Here are some examples:</p>



<ul class="wp-block-list">
<li><strong>Logging / error messaging:</strong> if you are displaying raw exception messages to your users, then these are not able to be localized because they are generally hardcoded in English by the entities providing the error messages. In this case, your application should be updated to display custom error messages to your users instead of raw messages.</li>



<li><strong>Identifying EVERY source of user-facing text:</strong> There are many possible sources of text in your application that can go unnoticed, which can then become difficult to handle late in the localization process. Some examples are images, email templates, and messages from external libraries/packages/APIs. If you are doing frontend only localization, then it becomes necessary to make 100% certain that there is NO user facing text coming from the backend – if you discover late in the process that some user facing text comes from the server, then some “hacky” solutions may be necessary to preserve the frontend-only localization scheme.</li>



<li><strong>Not enforcing a single source of truth for text:</strong> If there is not a very solid system in place for establishing and updating the “source or truth” for translated text, then the localization process can quickly become messy. Things are always changing during development, and if there is not an established system to deliver text updates to translators and other stakeholders, then any one party can modify text without other stakeholders’ knowledge and introduce confusion. Enforce a single source of truth for text that all stakeholders can agree on. (Resource files are likely NOT the appropriate single source of truth, since non-developer stakeholders should also have control over text in the application.)</li>
</ul>



<div class="wp-block-group alignwide has-custom-light-blue-background-color has-background is-layout-flow wp-container-core-group-is-layout-dbd34961 wp-block-group-is-layout-flow" style="border-radius:20px;margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50);padding-top:var(--wp--preset--spacing--50);padding-right:0;padding-bottom:var(--wp--preset--spacing--50);padding-left:0">
<div class="wp-block-columns alignwide are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-43efaee5 wp-block-columns-is-layout-flex" style="padding-right:var(--wp--preset--spacing--60);padding-left:var(--wp--preset--spacing--60)">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:85%">
<h3 class="wp-block-heading has-text-align-left" id="h-have-an-upcoming-project-dmc-can-help-you-take-the-next-step"><strong>Build Applications That Speak Your Users’ Language</strong>.</h3>



<p class="has-text-align-left wp-block-paragraph" id="h-need-help-turning-ideas-into-outcomes-automation-project-to-the-next-level-contact-us-today-to-learn-more-about-our-solutions-and-how-we-can-help-you-achieve-your-goals">Check out our <a href="https://static.dmcinfo.com/services/application-development/" data-type="page" data-id="434">Application Development</a> solutions for JavaScript localization, multilingual interfaces, and scalable translation workflows with Visual Studio Code.</p>
</div>



<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:15%">
<div class="wp-block-buttons is-horizontal is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-2236275c wp-block-buttons-is-layout-flex">
<div class="wp-block-button is-style-fill"><a class="wp-block-button__link has-base-contrast-color has-text-color has-link-color wp-element-button" href="https://static.dmcinfo.com/contact/">Contact Us</a></div>
</div>
</div>
</div>
</div>
<p>The post <a href="https://static.dmcinfo.com/blog/15997/basic-javascript-localization-setup-using-json-with-visual-studio-code/">Basic JavaScript Localization Setup Using JSON with Visual Studio Code</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Basic Localization Setup in .NET 8 with Visual Studio</title>
		<link>https://static.dmcinfo.com/blog/16011/basic-localization-setup-in-net-8-with-visual-studio/</link>
		
		<dc:creator><![CDATA[Shannon Coupland]]></dc:creator>
		<pubDate>Mon, 16 Sep 2024 10:25:01 +0000</pubDate>
				<category><![CDATA[Web Application Development]]></category>
		<category><![CDATA[Localization Setup]]></category>
		<category><![CDATA[Microsoft Visual Studio]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/16011/basic-localization-setup-in-net-8-with-visual-studio/</guid>

					<description><![CDATA[<p>Localization as it pertains to software is a very broad topic, but generally, to “localize” an application means to write or update the user-facing components of an application to simultaneously target users from multiple regions, languages, and/or cultures. Often, software engineers refer to localization to mean simply translating an application into multiple languages. But in [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/16011/basic-localization-setup-in-net-8-with-visual-studio/">Basic Localization Setup in .NET 8 with Visual Studio</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Localization as it pertains to software is a very broad topic, but generally, to “localize” an application means to write or update the user-facing components of an application to simultaneously target users from multiple regions, languages, and/or cultures.</p>



<p class="wp-block-paragraph">Often, software engineers refer to localization to mean simply translating an application into multiple languages. But in reality, localization can be much more involved than basic text translation. When localizing an application, these can all be items a software engineer needs to consider:</p>



<ul class="wp-block-list">
<li>Translation of user-facing text</li>



<li>Date formatting</li>



<li>Currency formatting</li>



<li>Number formatting</li>



<li>Text ordering and direction</li>



<li>Images and other content</li>



<li>Regional language differences</li>



<li>And others</li>
</ul>



<p class="wp-block-paragraph">Every localization system is different, but in general, localization solutions should NOT solely consider target languages. Rather, to target a specific group of users, <em>locales</em> should be used. A locale combines <em>language</em> (what language the target users speak) with <em>region</em> (the area of the world in which the target users live). Region and language can be combined to form a <em>locale string</em>, generally in the format “xx-XX”, where “xx” is a two-letter code indicating the <em>language</em> and “XX” is a two-letter code indicating the <em>region</em>. Here are some examples of locale strings:</p>



<ul class="wp-block-list">
<li>en-US: English as spoken in the United States</li>



<li>en-GB: English as spoken in United Kingdom of Great Britain and Northern Ireland</li>



<li>pt-BR: Portuguese as spoken in Brazil</li>



<li>pt-PL: Portuguese as spoken in Portugal</li>



<li>es-MX: Spanish as spoken in Mexico</li>



<li>es-US: Spanish as spoken in the United States</li>
</ul>



<p class="wp-block-paragraph">Language abbreviations are standardized using the <a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 language codes</a>, and country abbreviations are standardized using the <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 alpha-2 country codes</a>. A combination of codes from these two lists forms a complete locale, used to uniquely identify resources used for a language and region.</p>



<p class="wp-block-paragraph">Successfully implementing an efficient and maintainable localization system involves significant upfront planning, for both software solution structure and communication with text stakeholders and translators.</p>



<h2 class="wp-block-heading" id="h-basic-localization-setup-in-net-8-with-visual-studio"><strong>Basic Localization Setup in .NET 8 with Visual Studio</strong></h2>



<p class="wp-block-paragraph">This section will demonstrate how to set up basic localization in .NET 8 and Visual Studio Code. We will create a .NET 8 solution, and then we will modify the solution to include localization for two additional cultures (Spanish as spoken in Mexico “es-MX” and French as spoken in France “fr-FR”).</p>



<p class="wp-block-paragraph">Note that programmatically, Microsoft uses the terminology “culture” rather than “locale” to indicate a combination of region and language that an application must be localized to.</p>



<p class="wp-block-paragraph"><strong>Prerequisites</strong></p>



<ul class="wp-block-list">
<li>Visual Studio 2022 installed on your machine</li>



<li>.NET 8.0 SDK installed on your machine</li>



<li>General understanding of navigation for Visual Studio IDE</li>
</ul>



<p class="wp-block-paragraph"><strong>Localization Steps</strong></p>



<ol class="wp-block-list">
<li>In Visual Studio 2022, create a new .NET 8 console application named <strong><code>LocalizationExample</code></strong>.</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-1.png" alt="Create a new .NET 8 console application"/></figure>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-2.png" alt="create a new .NET 8 console application named LocalizationExample"/></figure>



<p class="wp-block-paragraph">Once the project is created and opened in Visual Studio, it will look like this:</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-3.png" alt="Created project viewed in Visual Studio"/></figure>



<ol class="wp-block-list">
<li value="2">In the Visual Studio Package Manager Console, run the following commands to install necessary packages:
 

<ol class="wp-block-list" style="list-style-type:lower-alpha;">
  

<li><strong><code>Install-Package Microsoft.Extensions.Hosting</code></strong></li>


  

<li><strong><code>Install-Package Microsoft.Extensions.DependencyInjection</code></strong></li>


  

<li><strong><code>Install-Package Microsoft.Extensions.Localization</code></strong></li>


 </ol>


 </li>
</ol>



<ol class="wp-block-list">
<li value="3">To set up localization with dependency injection, replace the contents of <strong><code>Program.cs</code></strong> with the following lines of code, which add the services required for localizing your application. Note that the specified <strong><code>ResourcePath</code></strong> is &ldquo;Resources&rdquo; &ndash; you will add this path to your project in the next step.</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;

using IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
        services.AddLocalization(options =>
        {
            options.ResourcesPath = "Resources";
        });
    })
    .Build();
Console.WriteLine("Hello, World!");</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Microsoft</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Extensions</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Hosting</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">Microsoft</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Extensions</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">DependencyInjection</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">IHost</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">host</span><span style="color: #D4D4D4"> = </span><span style="color: #4EC9B0">Host</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">CreateDefaultBuilder</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">args</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    .</span><span style="color: #4EC9B0">ConfigureServices</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">services</span><span style="color: #D4D4D4"> =&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #4EC9B0">services</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">AddLocalization</span><span style="color: #D4D4D4">(</span><span style="color: #4EC9B0">options</span><span style="color: #D4D4D4"> =&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">        {</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #4EC9B0">options</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">ResourcesPath</span><span style="color: #D4D4D4"> = &quot;</span><span style="color: #4EC9B0">Resources</span><span style="color: #D4D4D4">&quot;;</span></span>
<span class="line"><span style="color: #D4D4D4">        });</span></span>
<span class="line"><span style="color: #D4D4D4">    })</span></span>
<span class="line"><span style="color: #D4D4D4">    .</span><span style="color: #DCDCAA">Build</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #9CDCFE">Console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">WriteLine</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&quot;Hello, World!&quot;</span><span style="color: #D4D4D4">);</span></span></code></pre></div>



<p class="wp-block-paragraph">&nbsp;</p>



<ol class="wp-block-list">
<li value="4">In the <strong><code>LocalizationExample</code></strong> project, add a new folder called &ldquo;Resources&rdquo;. This directory is where the localization services are set up to search for your localization resource files that will contain your localized text.</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-5.png" alt="Add a new folder called Resources"/></figure>



<ol class="wp-block-list">
<li value="5">In the &ldquo;Resources&rdquo; folder, add a new item using the &ldquo;Resources&rdquo; type template. Name it &ldquo;SampleResource.resx&rdquo;.</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-6.png" alt="Add a new item using the &quot;Resources&quot; type template"/></figure>



<p class="wp-block-paragraph">When “SampleResource.resx” opens, you should see a table open with the columns “Name”, “Value”, and “Comment”. You will also see a dropdown at the top of the file with “Strings” selected – for this exercise you will preserve the “Strings” option, but other resource types can be localized by changing this dropdown. The resource file columns serve the following purposes:</p>



<ol class="wp-block-list" style="list-style-type:lower-alpha;">
 

<li>Name: a string that uniquely identifies the piece of text the entry contains in the.resx files preceded with &ldquo;SampleResource&rdquo;. Note that it cannot begin with a number and cannot contain spaces or most special characters.</li>


 

<li>Value: The string value that corresponds to the Name key for the culture associated with this resource file.</li>


 

<li>Comment: An optional text entry to clarify information about the resource entry.</li>


</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-7.png" alt="View of the “SampleResource.resx” table"/></figure>



<ol class="wp-block-list">
<li value="6">Repeat step 5 to create files &ldquo;SampleResource.es-MX.resx&rdquo; and &ldquo;SampleResource.fr-FR.resx&rdquo;.</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-8.png" alt="Repeat the steps to create additional localization files"/></figure>



<ol class="wp-block-list">
<li value="7">Add the following entries to the .resx files created in steps 5-6. These values are &ldquo;Hello World!&rdquo; in different languages. Note that the file SampleResource.resx is the <em>default</em> resource file &ndash; if a culture is selected that does NOT match &ldquo;fr-FR&rdquo; or &ldquo;es-MX&rdquo; when the resource is accessed, then the application will default to the English value stored in SampleResource.resx.</li>
</ol>


<table border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="width:153px;">


<p class="wp-block-paragraph">File</p>


</td>
<td style="width:142px;">


<p class="wp-block-paragraph">Name</p>


</td>
<td style="width:139px;">


<p class="wp-block-paragraph">Value</p>


</td>
<td style="width:141px;">


<p class="wp-block-paragraph">Comment</p>





<p class="wp-block-paragraph">SampleResource.resx</p>


</td>
<td style="width:142px;">


<p class="wp-block-paragraph">HelloWorld</p>


</td>
<td style="width:139px;">


<p class="wp-block-paragraph">Hello World!</p>


</td>
<td style="width:141px;">


<p class="wp-block-paragraph">Hello World in English</p>





<p class="wp-block-paragraph">SampleResource.es-MX.resx</p>


</td>
<td style="width:142px;">


<p class="wp-block-paragraph">HelloWorld</p>


</td>
<td style="width:139px;">


<p class="wp-block-paragraph">¡Hola Mundo!</p>


</td>
<td style="width:141px;">


<p class="wp-block-paragraph">Hello World in Spanish (MX)</p>





<p class="wp-block-paragraph">SampleResource.fr-FR.resx</p>


</td>
<td style="width:142px;">


<p class="wp-block-paragraph">HelloWorld</p>


</td>
<td style="width:139px;">


<p class="wp-block-paragraph">Bonjour le monde!</p>


</td>
<td style="width:141px;">


<p class="wp-block-paragraph">Hello World in French (FR)</p>


</td>
</tr>
</tbody>
</table>


<p class="wp-block-paragraph">&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-9.png" alt="Add entries for different languages"/></figure>



<ol class="wp-block-list">
<li value="8">Add the following code to Program.cs under the existing usings. This will enable the desired culture to be supplied as a command line argument, as well as add the appropriate using to use our new SampleResource files:</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">C#</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>using System.Globalization; 
if (args is { Length: 1 })
{
    CultureInfo.CurrentCulture =
        CultureInfo.CurrentUICulture =
            CultureInfo.GetCultureInfo(args&#91;0&#93;);
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">using</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">System</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">Globalization</span><span style="color: #D4D4D4">; </span></span>
<span class="line"><span style="color: #C586C0">if</span><span style="color: #D4D4D4"> (</span><span style="color: #9CDCFE">args</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">is</span><span style="color: #D4D4D4"> { </span><span style="color: #9CDCFE">Length</span><span style="color: #D4D4D4">: </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> })</span></span>
<span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">CultureInfo</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">CurrentCulture</span><span style="color: #D4D4D4"> =</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">CultureInfo</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">CurrentUICulture</span><span style="color: #D4D4D4"> =</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">CultureInfo</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">GetCultureInfo</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">args</span><span style="color: #D4D4D4">&#91;</span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4">&#93;);</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p class="wp-block-paragraph">&nbsp;</p>



<ol class="wp-block-list">
<li value="9">In Program.cs, replace the line <strong><code>Console.WriteLine(<span style="color:#cc0000;">&quot;Hello, World!&quot;</span>);</code></strong> with <strong><code>Console.WriteLine(SampleResource.HelloWorld);</code></strong>. Your Program.cs should now look like this:</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-10.png" alt="View of Program.cs after replacing code"/></figure>



<ol class="wp-block-list">
<li value="10">Build the solution by right clicking on the solution in the Solution Explorer and clicking &ldquo;Build Solution&rdquo;.</li>
</ol>



<ol class="wp-block-list">
<li value="11">Open the .NET CLI / Terminal through the View menu.</li>
</ol>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-11.png" alt="Open the .NET CLI / Terminal through the View menu"/></figure>



<ol class="wp-block-list">
<li value="12">Finally, test out the LocalizationExample solution via the newly opened terminal using the command dotnet run &#8211;project LocalizationExample.csproj xx-XX, where &ldquo;xx-XX&rdquo; is a combination of a language and a region. Try out &ldquo;es-MX&rdquo;, &ldquo;fr-FR&rdquo;, &ldquo;en-US&rdquo; (U.S. English), and &ldquo;pt-BR&rdquo; (Brazilian Portuguese) as command line arguments.</li>
</ol>



<p class="wp-block-paragraph">Note that the HelloWorld resource for the cultures “es-MX” and “fr-FR” both appear translated as expected. When .NET reaches into the Resources folder to obtain the “HelloWorld” resource, it uses the culture string associated with the stored CultureInfo.CurrentCulture to access the appropriate .resx file. However, the “en-US” and “pt-BR” cultures both yield the HelloWorld string in English, because neither of these cultures are explicitly provided for the SampleResource resource, and so .NET defaults to the base SampleResource.resx.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/Localization-.Net-12.png" alt="Test out the LocalizationExample solution"/></figure>



<p class="wp-block-paragraph">DMC is a full-service <a href="https://static.dmcinfo.com/services/application-development">application development</a> company focused on custom web, mobile, cloud, and desktop applications.&nbsp; Contact us <a href="https://static.dmcinfo.com/contact#get-in-touch">today</a> to discuss your application development needs.</p>
<p>The post <a href="https://static.dmcinfo.com/blog/16011/basic-localization-setup-in-net-8-with-visual-studio/">Basic Localization Setup in .NET 8 with Visual Studio</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
