It's quite simple, actually. Create a new resource file, for example Strings.resx
. Set Access Modifier
to Public
. Use the apprioriate file template, so Visual Studio will automatically generate an accessor class (the name will be Strings
, in this case). This is your default language.
Now, when you want to add, say, German localization, add a localized resx file. This will be typically Strings.de.resx
in this case. If you want to add additional localization for, say, Austria, you'll additionally create a Strings.de-AT.resx
.
Now go create a string - let's say a string with the name HelloWorld
. In your Strings.resx
, add this string with the value "Hello, world!". In Strings.de.resx
, add "Hallo, Welt!". And in Strings.de-AT.resx
, add "Servus, Welt!". That's it so far.
Now you have this generated Strings
class, and it has a property with a getter HelloWorld
. Getting this property will load "Servus, Welt!" when your locale is de-AT, "Hallo, Welt! when your locale is any other de locale (including de-DE and de-CH), and "Hello, World!" when your locale is anything else. If a string is missing in the localized version, the resource manager will automatically walk up the chain, from the most specialized to the invariant resource.
You can use the ResourceManager
class for more control about how exactly you are loading things. The generated Strings
class uses it as well.