Are there any performance issues or caveats with r

2019-02-06 03:07发布

问题:

Resource files seem great for localization of labels and messages, but are they perfect?

For example:

  1. Is there a better solution if there is a huge amount of resources? Like 100,000 strings in a .resx file? (Theoretically, I do not actually have this problem)
  2. Is this a good method for storing the other types of data, such as images, icons, audio files, regular files, etc.?
  3. Is it a best practice to store your .resx files in a stand-alone project for easier updates/compiling?
  4. Are there any other issues that you have run into when using .resx files?

回答1:

 1. Is there a better solution if there is a huge amount of resources? Like 100,000 strings in a .resx file? (Theoretically, I do not actually have this problem)

I've used Alfresco as an alternative content repository on Java projects. RESX files, from a maintaince standpoint (because of encoding issues I guess) can really stink.

 2. Is this a good method for storing the other types of data, such as images, icons, audio files, regular files, etc.?

I've seen it work with images...but that's it. (not sure with other media/files)

 3. Is it a best practice to store your .resx files in a stand-alone project for easier updates/compiling?

I don't, but you can edit a resx file on a live site and then edit will go through, I believe. Certainly that's the way it works in development (except for the global resx, I think)

 4. Are there any other issues that you have run into when using .resx files?

Besides being really annoying to maintain, and the fact that visual studio doesn't provide the neatest tools for working with them...no.



回答2:

I recently used a .resx file with 5 million strings (normal length, like this sentence), compiled in different DLLS about 1 GB in size. It still works fine in an Azure web project.

The load time is unknown, maybe few seconds or so, since it always can heat up in stages, I never noticed it.



回答3:

We have been using resource files on a relatively large .NET Windows Forms application (over 500 various forms, approximately 20 resource strings per form) and we've had no performance issues regarding resources from .resx files. We have used Babylon.NET as a tool for managing translations (has a free version just for translators). You did not specify if your project will be web or desktop application. One functionality that resource files offers for desktop applications is the ability to also localize control positions and size which IMHO is not possible using other tools (unless you are using something like DevExpress layout control which has automatic sizing).



回答4:

I have had two problems with resource files, both about performance of the translators (people), rather than the speed of string lookup.

The sales staff at the oversee office that did the translators could not cope with editing XML or learning any new tool.

So they just used Excel to edit the translations. Therefore, we might as well have stored the translated strings as a CVS file, so avoiding having to copy the translated strings into the resource files.

A new build needs to be done so as to need the effect of any translations.

Once again if the translated strings were stored as a CSV file, we could have cached them in the ASP.NET cache. Then any changes to the translations would show up on the next page load.


So we could have used a custom implementation of the resource provider and keep to the standard ASP.NET resource lookup system. Or just ignore the standard resource lookup system if it does not help in your case – it depends on how your pages are written.


You may find at some point that you wish to be able to override strings for a single customer, if so you will need a multi-stage lookup system. Otherwise, you have to merge the customer’s custom strings with the translated string each time you ship a new version of the system.



回答5:

For point#4.
I have been using .resx files for all strings on our site that must be localized into many languages and haven't had any major issues with them.

The one thing that you need to think about is if you want this text to be searchable. For some of the sites I work on there are some localized resources that need to be searchable so I must keep them in the database. However, when I have the choice I prefer the .resx file for similar reasons mentioned above.



回答6:

I will simply add that you should look for custom implementations (or do you own) of the resource provider (provider model like the membership provider) to store your resources in a database. That's what we did for our CMS, and it's very useful.

When we first looked for an example back then we found Creating a Data Driven ASP.NET Localization Resource Provider and Editor.



回答7:

Here is my take on resource files:

  1. I would assume that if there is a LARGE amount of string, that using a database might be the best method to allow for searching and sorting of the data. It would probably not be too difficult to account for multiple languages in a resource table, and the speed should best fast.

  2. I would think that this is a good method for storing static resources, or things that might be changed by a client. As for dynamic resources, it might be better to use a database, either alone, or in conjunction with the file system. I think in the new SQL Server there is a new type that is an optimal hybrid of using a database and the file system.

  3. I read in another question (don't know which) that using resource files in an external project is a good practice, because you wouldn't have to recompile an entire project when resources change. Just recompile the resource project. This would also allow for (fairly) easy edits to be made by clients, where they would only need to "source code" for the resource project, and not your other real code (API code, etc.).

  4. I have not used resource files enough to make any claims about their reliability, extensibility, or any potential issues that you might have when working with them.



回答8:

Never seen any problems with resx resources, they are being cached perfectly. We have used them in WinForms, asp.net mvc, wpf, etc...

One thing you should do is use the Microsoft MAT (Multilingual App Toolkit) extension for Visual Studio.

You can control your translations, export them to send to translators (e.g. not the locked translations), import them again and verify them or comment on it, recycle existing translations (saving you a lot of time!)

and it works with the industry standard xlf format!

If you sign up with the Azure api you can even automatically translate resources (you have a few thousand words free of monthly credit on azure). See: https://multilingualapptoolkit.uservoice.com/knowledgebase/articles/1167898-microsoft-translator-moves-to-the-azure-portal

you can even see how much work already has been done in a project:

Oh and it comes with a handy editor which your translators can also use!

To get started:

  1. install the MAT Visual Studio extension
  2. Go to your project in Visual Studio
  3. Click Properties --> open AssemblyInfo.cs
  4. Add this attribute: [assembly: System.Resources.NeutralResourcesLanguage("en")]
  5. Select your project in Solution Explorer and to in Visual Studio to [Tools] --> [Multilingual App Toolkit] --> [Enable selection]
  6. This will add a new folder "MultilingualResources" to your project
  7. Right mouse click your project --> [Multilingual App Toolkit] --> [Add translation languages…] --> select the language you want to translate (e.g. Dutch).
  8. In the "MultilingualResources" folder you will see a new file "....nl.xlf", double click it, it will open with the Multilingual Editor. (if not right mouse click and change the default "Open With" to the multilingual editor)

Now you only add strings to your default Resources.resx file (the language should be same as the "NeutralResourcesLanguage" you added in AssemblyInfo.cs. For the translations you DONT add strings to the ...nl.resx files, you work with the .xlf files, located in the MultiLingualResources folder.

(after you have done lots of translations, a rebuild might be needed so that the translated .xlf files update the translated .resx files)

Where to get it:

  • feedback: https://multilingualapptoolkit.uservoice.com/
  • visual studio extension: https://marketplace.visualstudio.com/items?itemName=MultilingualAppToolkit.MultilingualAppToolkit-18308
  • knowledge base: https://multilingualapptoolkit.uservoice.com/knowledgebase
  • github of Cameron (Microsoft) who manages this project: https://github.com/TheMATDude