Dynamically add files for C # localization

I need help localizing my Wpf.net 3.5 application. I am going to provide only an exe file for my cient, with which it will create settings for its users. My client wants to add files for localization on their own.

A common localization method is to create .resx files for each language and set the language to CurrentUICulture. but since he cannot use the resgen tool to create resource files, I want to know a better way for him to add files in txt, excel, xml format to do localization.

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

+6
source share
1 answer

If you cannot use the Resgen Tool, a simple plain wit Key-Value Pairs text file will be the easiest way. And if you just stay with simple strings, you should use just that. Name them after the default agreement with the language in the name to identify the correct file to download and write yourself a custom resourceManager that loads these files at startup or on demand into a dictionary to access them.

Edit:

I’ll talk a little more about this ...

I would create a resource manager that has static accessors for all used resourcefiles, where only the backup resource is static. I think your language is determined at startup, so just load the backup and define the language files in the dictionary and both dictionaries in the static for this type of resource. Use GetString ("name", "Culture") to load the string. You can search for culture in the resource dictionary, and if one key is missing, static.

Edit II:

You can zip text files using a single .Net library there to prevent opening and changing content. For added security, you can also add a password to the zipper. Thus, you get fewer files plus the ability to modify files with any ZIP program. Of course, you should also change the file extension.

Hope this helps

+4
source

Source: https://habr.com/ru/post/889088/


All Articles