Note that there are some explanatory texts on larger screens.

plurals
  1. POLocalization .NET; Fallback language when using ResourceManager
    text
    copied!<p>Recently I was delving into Localization with .NET. Essentially, I learnt how to customize a form (using the Language and Localizable property) and then change the culture accordingly.</p> <p>However, I found that when migrating my hard coded English strings into the auto-generated resource files, and use .GetString("Key") -- well, let's just say it wasn't happy :P.</p> <p>I decided to make a separate set of resx files dedicated purely to the hard coded string translations. They followed the convention/requirement of [name].[culture-code].resx. I made of of these for each relevant language; e.g. <strong>appstrings.de.resx</strong> (For German) and <strong>appstrings.resx</strong> (as invariant baseline).</p> <p>To utilise these new resources, I created an instance of ResourceManager and Resource Set</p> <pre><code>Dim resManager As New ResourceManager("LanguageTest.appstrings", Assembly.GetExecutingAssembly) Dim resSet As ResourceSet = resManager.GetResourceSet(My.Application.UICulture, True, True) </code></pre> <p>The current UI culture was set (for example, to German) using</p> <pre><code>My.Application.ChangeUICulture("de") </code></pre> <hr> <p><strong>Original issue</strong></p> <p>Unless the resSet.GetString("Key") is explicitly defined in the <strong>appstrings.de.resx</strong>, it will return a blank string. Is there anyway I can make it fallback to the <strong>appstrings.resx</strong> (where "Key" does exist), which I assumed would be the default baseline?</p> <p><strong>Update</strong></p> <p>Rhapsody made a suggestion below, while the actual tip itself didn't work, it did in-fact spark an interesting point, using resManager.GetString("Key") as opposed to resSet.GetString("Key"). This appears to work without flaw so far. That is, values present in the specialized language file are returned, while 'missing' values fall-back to the default culture when accessed by a single key.</p> <p><strong>Subsequent Issue</strong></p> <p>The only remaining issue would be whether the performance impact of using ResourceManger as opposed to a cached ResourceSet will be that detrimental?</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