Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding how to localize resources

I know that there are lot of example but I didn't get my head around it... I just want to localize some strings and textfiles. That's what I currently do to receive a string or filecontent

MyResources.ResourceManager.GetString(name + "IdentString");

now I was looking for a way to store additional languages. The resources are wrapped into provider (about twelve provider at the moment, but that count will grow in the future) used by a ASP.Net MVC application (no view attached!)

As far as I know there are two ways to archive this:

  • Satellite assembly for each language that contains the resource
  • Filebased ResourceManager where each language has it's own binary resource file

And as far as I understand I have to use external tools in both scenarios and either have to link some satellite assemblies to the origin resource (each for one language) that get automatically loaded by the resource manager or I have to use a FilebasedResourceManager that loads the resource-file (a binary version for each language) from a external location. That means in both cases only the origin resource is embed in the project and the others are just attached in some sort. Did I get it right or am I totally wrong?

Some additional info

No need to say that I don't have any idea which one to take or how they really work or if there even other ways. As I started looking for this I thought about just naming my resource file after a convention like fr-resource.resx or de-resource.resx so that the resource-manager can take the thread culture or a given one and try to fetch the string from this resource or fallback to the default. But I found just something about satellites (what just remind me of a damn song) which should be registered to the web.config but need to build by just external tools...

like image 845
sra Avatar asked May 19 '11 09:05

sra


1 Answers

You are on the right path by renaming the resx files according to culture. However you'd name them like the following

  • resources.resx (This will be the default fallback.)
  • resources.de.resx (This will be the culture neutral german resources.)

If you place these files next to the default resx and include them in the project then the compiler will take care of building the sattelite assemblies, and the resource manager will take care of finding them.

Sattelite assemlies will be blaced in a sub-folder with the name of the culture. So if you have \myApp.exe as the output you will also get a \de\myApp.resources.dll

You won't have to do something to link these files to your original assembly. If you "forget" to supply theses sattelite assembly's your app just won't have german resources and falls back to the default.

like image 117
Jan-Peter Vos Avatar answered Sep 20 '22 20:09

Jan-Peter Vos