Open Closed

Access localization across modules #4434


User avatar
0
trina.thompson created
  • ABP Framework version: v6.0.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

I have a solution with several modules (CoreModule, CrmModule, etc.). I have a need to access localization from CrmModule within CoreModule. When I attempt to do so, the error code is not found. What do I need to do to be able to access localization across all modules?

Below is details regarding my scenario.

BusinessException (in CrmModule):

public class ContactDoesNotExistException : BusinessException { public ContactDoesNotExistException() : base(CrmErrorCodes.ContactDoesNotExistException) { } }

ErrorCode (in CrmModule):

public const string ContactDoesNotExistException = "Contact:00001";

en.json (in CrmModule):

"Contact:00001": "Contact does not exist",

Write exception message to a string (in CoreModule):

exceptionMessage = L[((BusinessException)row.Exception).Code];

I want exceptionMessage to display "Contact does not exist" but instead I'm getting "Contact:00001."


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can create a shared module(CoreLocalizationModule, CoreLocalizationResource) for localization.

  • User Avatar
    0
    trina.thompson created

    Thanks for the suggestion. Instead of creating a shared module, we decided to use the business exception code namespace to lookup the correct localization resource.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09