All throughout an application wherever error messages (or other user messages) are used I typically hard-code a string. Obviosly this can be really bad (especially when you may have to come back and localize an app). What is the best approach to centralize these strings? A static class? Constants? An XML File? Or a combination (like creating a static class with constants that are used to read from an xml file).
views:
146answers:
6.net has a pretty good support for so-called ressource-files where you can store all strings for one language.
I've always defined constants wherever they make the most sense based on your language (a static class? application-wide controller? resource file?) and just call them where/whenever needed. Sure they're still "hard-coded" in a way at that point, but they're also nicely centralized, with naming conventions that make sense.
Create the strings in a resource file. You can then localise by adding additional resource files.
Check out http://geekswithblogs.net/dotNETPlayground/archive/2007/11/09/116726.aspx
Create a Resource (.resx) file and add your strings there. VS will generate a class for you for easy access to these resources with full intellisence. You can then add localised resources in the same manner.
Does anyone else find the use of .Net resource files constricting? I dislike having a bottleneck file that will always have multiple developers contending for it. I think it also makes refactoring more difficult when you need to move modules between DLLs/projects.
Are there acceptable/standard alternatives to resource files for this purpose? (e.g. the _ function in Python?)