Localization in Class Library - c#

I would like to localize my c# class library
The library will output a .dll file, which I will distribute to .net application bin folders.
I want localization in the class library but I do not want to have to recompile the DLL each time a localization change is required.
So ideally....
have c# class with resx files outside the assembly, so that when the contents of the resx changes, all that should be required is that the asp.net host application might require a restart.
Best case scenario, is that the asp.net host application doesn't require a restart.
Thanks in advance for your advice - the resx file will just hold string values.
If possible I would like to do this using a best practice method, or at least without writing a whole custom localization solution.

Check this stackoverflow question.
Is there any performance difference in using .resx file and satellite assembly?
Looks like you can have a seperate resource dll.

Related

Different resx for different deployments c#

I'm using an embedded resource generated by 'PublicResXFileGenerator' which generates my ResourceManager class.
I'm trying to find a way to support multiple resx files for the same language or in some way being able to modify it from a deployed application but this doesnt seem possbible.
For example client 'x' is using the en-US translation:
Flat
and the other client 'y' are using the en-US translation:
Appartment
Maybe the above example is stupid but I hope you get my point.
Different users are using different namings for the same thing and I'd like to support this.
Is it possible?
Note:
My code is written in C#.
The strings in your default resource file (probably Resources.resx) are embedded in your executable file.
If you define a language specific resource file (e.g. Resources.en-US.resx) then Visual Studio will automatically generate a satellite DLL containing the localized resources.
The same applies if you add localized resources to a WinForms form, as shown here for Form1.
The satellite DLL is generated in a sub-directory of the bin directory.
The DLL must be deployed on the target machine in a sub-directory with exactly the same name.
This works for localized strings in any language, but it works exactly the same for strings in the current default language.
If the current default is en-US, and there is a satellite DLL for en-US, and it contains the required resources, then the .NET Framework will automatically use resources from the satellite DLL.
If you don't want the resources from the satellite DLL, no problem. Don't deploy it to the target machine. Then the .NET framework will use the default resources which are embedded in the executable.
If you only have two variations, then it is easy to manage in Visual Studio using the default resource file and an en-US resource file. If you have more than two variations, you are going to need a strategy to generate the resources. The simplest way would probably be to misuse another language.
Alternatively, you could use some other tool. Winres might do the job, but I'm not 100% sure.
Technically, you can define custom cultures, e.g. en-US-medical, or en-US-legal, but in my experience that is more bother than it is worth. I don't think (just my opinion) that Microsoft is strongly committed the concept.

Dynamically Update Resource file in Asp.Net Mvc

I have Asp.net MVC as a Class library. All of my .resx files are also in the same class library project as Embedded resource. So basically ill get output as a dll
And my requirement is that i need a page where i can get all the key value pair from the .resx files from the dll (which is bit easy) and again update the resx in the dll to reflect the changes on screen.
So the basic idea is I need a page where i can dynamically update the .resx file which are avaliable as the external class library. And the updated resources must be seen 'AS UPDATED' wherever needed.
Any Kind suggestions or some other working approach heartly welcomed.

I can add and edit resources from dll compiled at runtime?

I have a project webr that hosts two resource resx files in webr.properties, and resources are accessed as static properties, but when publishing the website becomes bin/webr.dll and bin/es/webr.resources.dll resx file are embedded in these dll, I can add and edit these resources in runtime in persistently? It is not to affect other projects that keep static reference to these resources.
What do you suggest?
I would recommend storing the new resources you want on the file system or in a database, and accessing them that way. Modifying the resources at runtime could be in theory possible, but feels like a strange solution. If it is images you are talking about, then I would try to find out how it is recommended to serve images in the specific web framework you are using.
No, you are referring to satellite assembly and that is precompiled and stored in your bin.
You can use other means like filesystem,database or any similar mechanism.

Proper procedure to import existing RESX files into a C#/WPF project

I have my auto generated Resource.resx file set up with keys and strings. I also have three other resx files for German, French and Spanish given to me from translators. I'm not able to get the localization functioning and I suspect that the resx files aren't being called correctly. I added them to the project by dragging them into the solution explorer under "Properties". I have a nagging suspicion that just dragging them in isn't creating the proper connections behind the scene.
Now It's totally possible my issue lies somewhere else. If anyone can tell me whether it's ok to add resource files this way or if not, what the correct way is, it would save me tons of time spent chasing my tail. Thanks!
Resx files in Visual Studio include a special tool which is run at build time and translates them into embedded resources. Right-click your original VS-created resx file and click Properties. You should see Build Tool or something similar. Also note the resource type (Embedded, etc.). Make sure that you match these settings for your manually added files.
Once this is set up, you will need to use the CurrentUICulture property to tell .NET to pick up the appropriate resources. You can choose to change the culture/language at install-time or run-time. Here is a comprehensive tutorial which describes the various options available to you:
WPF Localization Using RESX Files
That said, as a best practice, translated Resx files are generally deployed as satellite assemblies. The main application DLL/EXE contains only the language neutral resources file. Other resource files are compiled into separate assemblies and deployed side-by-side with specific naming conventions. This allows you to dynamically add translations, localizations, etc. even after the application is deployed. Here's an introduction: Packaging and Deploying Resources in Desktop Apps

Is it possible to extract Global.asax into a common library outside of the websites bin directory?

Using the solution in this question, I moved my MvcApplication logic to a SharedHttpApplication class in my common library that inherits from HttpApplication.
In my asp.net mvc 3 project, I have my Global.asax MvcApplication inherit from my SharedHttpApplication.
My common library Assembly lives on the server file system in a standard location, and I am trying to prevent having to copy local to keep it in one place.
I am not getting a parser error for line one of my Global.asax page. I've read this is because the DLL containing the application is not in the bin directory.
Does anyone have a solution for what I'm trying to do here?
Thanks in advance for any help!
The only way I believe you can do what you're talking about it by installing the shared DLL to the GAC. That will make it accessible to anything on the server. If you don't care about the security implications of that, then that could be the way to go.
http://msdn.microsoft.com/en-us/library/dkkx7f79.aspx
Otherwise, copying the dll to each of the application's bin folders is not really bad practice, as long as you have a good deployment strategy in place for that.

Categories

Resources