String resource file naming schemes and management
-
01-10-2019 - |
Question
A trivial question perhaps, but I'm interested in the answers. I'm currently refactoring some very large monolithic string resource files (one dumpster resource file per project, in about 30 projects). I'm splitting them such that we follow a convention for our files and make the strings easier to find and manage when coding.
Generally I'm splitting the files into this scheme:
- ErrorMessages.resx
- LogMessages.resx
- ViewResources.resx
- AppResources.resx
I'm not terribly thrilled with the naming, and I'm just wondering what other people use. For example, instead of AppResources
(strings for internal use by the application), I've seen a lot of demo projects use StringResources
, Internal
(terrible!), etc.
Ideas/anecdotes/suggestions on managing resources or standard naming schemes are appreciated.
Solution
I generally structure my resources like this:
The first resource file is used by the entire application (e.g. Project.Core
) and does include all sorts of widely used common strings. I actually don't make any difference between errors/exceptions and logging:
CommonResources.resx
Access modifier: PublicError_Context
e.g.Error_ArgumentCannotBeNull
Warn_Context
e.g.Warn_ApplicationSettingNotFoundUseDefault
Info_Context
e.g.Info_UpdateAvailable
Validation_Context
e.g.Validation_EmailNotValid
The second resource file is used by the presentation layer and contains all sorts of UI strings. The naming can vary from project to project but generally it looks like the following schema:
PresentationResources.resx
Access modifier: InternalCommon_Context
e.g.Common_Yes
Section/Controller_Window/View_Context
e.g.Help_FAQ_HeadlineHowToUseResources
orHelp_FAQ_TextHowToUseResources
Finally every project/assembly does also have an internal resource file for Error/Warn/Info/Validation resources that are too specific to go in the CommonResources.resx
file. I have to admit, that I mostly name this resource file InternalResources.cs
;)
InternalResources.resx
Access modifier: InternalClassname_Error_Context
e.g.BCrypt_Error_InvalidSaltRevision
Classname_Warn_Context
Classname_Info_Context
Classname_Validation_Context