字符串资源文件命名方案及管理

发布于 2024-08-29 20:58:08 字数 1431 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习ぎ惯性依靠 2024-09-05 20:58:08

我通常这样构造我的资源:

第一个资源文件由整个应用程序使用(例如Project.Core),并且包含各种广泛使用的常见字符串。实际上,我对错误/异常和日志记录没有任何区别:

  • CommonResources.resx
    访问修饰符:公共

    • Error_Context
      例如Error_ArgumentCannotBeNull
    • Warn_Context
      例如Warn_ApplicationSettingNotFoundUseDefault
    • Info_Context
      例如Info_UpdateAvailable
    • Validation_Context
      例如Validation_EmailNotValid

第二个资源文件由表示层使用,包含各种 UI 字符串。命名可能因项目而异,但通常类似于以下架构:

  • PresentationResources.resx
    访问修饰符:内部

    • Common_Context
      例如Common_Yes
    • Section/Controller_Window/View_Context
      例如Help_FAQ_HeadlineHowToUseResourcesHelp_FAQ_TextHowToUseResources

最后,每个项目/程序集还有一个用于错误/警告/信息/验证资源的内部资源文件,这些资源太具体而无法放入CommonResources.resx 文件。我必须承认,我主要将此资源文件命名为 InternalResources.cs ;)

  • InternalResources.resx
    访问修饰符:内部

    • Classname_Error_Context
      例如BCrypt_Error_InvalidSaltRevision
    • Classname_Warn_Context
    • Classname_Info_Context
    • Classname_Validation_Context

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: Public

    • Error_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: Internal

    • Common_Context
      e.g. Common_Yes
    • Section/Controller_Window/View_Context
      e.g. Help_FAQ_HeadlineHowToUseResources or Help_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: Internal

    • Classname_Error_Context
      e.g. BCrypt_Error_InvalidSaltRevision
    • Classname_Warn_Context
    • Classname_Info_Context
    • Classname_Validation_Context
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文