15

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?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John B
  • 20,062
  • 35
  • 120
  • 170
  • There is none (yet), but I'm going to be working on a project that will rely on resource files for the localization of its labels and messages. Just wanted to make sure there weren't any major caveats, or better alternatives. – John B Aug 14 '09 at 14:54
  • If I had even tens of thousands of strings I would be using a database to store this information. I likely would already be using a database by the time I hit thousands, let alone hundreds of thousands. – Chris Marisic Sep 17 '14 at 12:57

9 Answers9

6

 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.

Scott Schulthess
  • 2,853
  • 2
  • 27
  • 35
  • about 1. if you want to have control over it install the free Microsoft MAT (Multilingual App Toolkit) extension for Visual Studio ;-) – juFo Jul 12 '18 at 08:21
5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eric Yin
  • 8,737
  • 19
  • 77
  • 118
  • Thanks for the feedback. It's always good to hear success stories. – John B Mar 26 '12 at 13:47
  • I do not recommend it, stupid solution, take long for deployment. I guess eventually they will move it to Azure Table Storage. But it approve the big res file works. – Eric Yin Mar 26 '12 at 13:51
3

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 see 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.

Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
  • @SkippyFire, the problem with the "external .resx editor tool" is that a translator has to learn how to use it. – Ian Ringrose Oct 13 '09 at 13:47
  • 1
    Dude, the resgen tool can transform resx to key=value text files that are trivial for translators to use. Then you can use resgen to transform the key=value files back into xml resx files. – Andrew Arnott Oct 13 '09 at 15:38
  • There is a simple free tool, can't remember the name, that opens the resx file in a spreadsheet like fashion. There is really nothing to learn at all. – Pete Oct 13 '09 at 22:24
  • @Pete, but the tool has to be installed and more often then not in my experience the translations are done by a "sales person" in the local sales office. Not someone that is good at learning how to use new software however easy it is to use.. – Ian Ringrose Oct 14 '09 at 09:26
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).

3

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:

enter image description here

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

enter image description here

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:

juFo
  • 17,849
  • 10
  • 105
  • 142
1

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.

Matthew Manela
  • 16,572
  • 3
  • 64
  • 66
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
W3Max
  • 3,328
  • 5
  • 35
  • 61
  • 1
    Why would you want to store these non-changing resources in a Database? That seems like a great way to run into scalability problems fairly soon. – UpTheCreek Oct 13 '09 at 08:01
  • @Sosh, who said resources are "non-changing". On the contrary, resources are like any other content, constantly changing and you probably want a web based interface to managed them so that a none technical person can do that. And the thing about scalability can be handled in many ways... I didn't know that storing data in databases would necessarily imply scalability problems... – W3Max Oct 16 '09 at 20:42
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John B
  • 20,062
  • 35
  • 120
  • 170
0

I've been using resource files in a .net razor page app after dumping our previous proxy server that used a custom regular expression language to replace strings as they passed through the proxy.

We dumped the proxy method as it was more suited to large strings (paragraphs) and pretty awkward for all the dynamic fragments and stuff we had.

Had no problem at all and it's faster so far than the proxy server. I store all the target pages, comments, names, en and all other available languages in a DB..trivial to add a new column for a new language.

We have about 5k entries in multiple resx files so far

I then use a builder process to create all the resx files and place them in the correct local and global folders any time something is updated.

Dead easy to build a simple interface for translators to search for pages, languages, comments, names etc and update. We choose not to auto rebuild the resx files on a change but you could if you trust your translators ;)

We also allow translators to add new fragments/text to translate but as yet we've not had any bright ideas on how to include them automatically and have to manually substitute the string in the source file and recompile.

For editing resx files I've used zeta,

https://www.zeta-resource-editor.com/index.html

Which can open all your languages in one go and highlights differences in placeholders and also missing translations. You can edit all the languages on one row and save all the files in one go. We don't use it now as everything is in the DB but recommend it.

Rolf Herbert
  • 45
  • 1
  • 8