开发者

Dynamically add files for localization C#

开发者 https://www.devze.com 2023-03-08 07:03 出处:网络
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 b

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 .re开发者_JAVA百科sx 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消