Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically add files for localization C#

Tags:

c#

.net

wpf

resx

I need a help in localizing my Wpf .net 3.5 application. I am going to give only the exe file to my cient with which he will create setup for his users. My client wants to add files for localization by himself.

The general method of localization is creating .resx files for each languages and set the language in CurrentUICulture. but since, he cant use resgen tool to create resource files, I want to know the best method to let him add files in txt,excel,xml format to make the localization.

PS: reading through stream and assigning the key is the only way?

like image 425
Coder323 Avatar asked May 26 '11 08:05

Coder323


1 Answers

If you cannot use the resgen Tool a simple textfile wit Key-Value Pairs would be the simplest way. And if you just staying with simple strings you should use just this. Name them after the default convention with the language in the name to identify to correct file to load and write yourself a custom resourceManager that load this files at startup or on demand into a Dictionary to access them.

Edit:

I go a bit more in details about this...

I would create a resource manager that has static accessors for all used resourcefiles where just the fallback resource is static typed. I guess your language is defined at startup so just load the fallback and the defined language files each into a dictionary and both dictionaries in a static typed for this resource type. Use a GetString("name", Culture) to load a string. You can do the lookups for the culture in the resource dictionary and if one key is missing do a fallback to the static one.

Edit II:

You can ZIP the text-files using one of the .Net libraries out there to prevent anyone from open and change the content. For additional security you can also add a password to the zip. So you end up with smaller files plus the ability to modify the files with any ZIP program. For sure you should also change the file extension.

Hope this helps

like image 63
sra Avatar answered Oct 06 '22 11:10

sra