4

I am afraid I am missing something, but I can't find how to create a custom Localizable Message in Tridion 2013 SP1. In an Event System I want to throw an Exception like the following:

throw new TridionInvalidOperationException(new Tridion.Localization.LocalizableMessage("eventsystem-cannot-publish"));

But when the Event System is triggered I get the following message:

enter image description here

Could you please help me find the correct documentation, or (if this is not available) help me out on how to fix this?

1
  • 1
    @Velmurugan I would image Peter is trying to cancel an event by throwing an exception, and if doing that in a Initiated phase, the message is exposed to the user, so you would want it localized in the users UI language. Mar 5, 2018 at 13:13

2 Answers 2

3

A localizable message is one from the resource bundles, so the method you are using is expecting a resourceName, and the error indicates that it cannot find your resource name in the Tridion bundles (which makes sense).

If you wish to use your own resource bundle, then you have to make sure that Tridion knows about this, and you can do that with one of the overrides of the LocalizableMessage method:

public LocalizableMessage(
    ResourceManager specifiedResourceManager,
    string resourceName
)

or

public LocalizableMessage(
    ResourceManager specifiedResourceManager,
    string resourceName,
    params Object[] parameters
)

Where the parameters have the following details:

specifiedResourceManager

  • Type: System.Resources.ResourceManager
  • Specifies a ResourceManager that will be used to lookup the string resource.

resourceName

  • Type: System.String
  • The string resource name.

parameters

  • Type: System.Object[]
  • The parameter values can be any object (the object's ToString() implementation will be used to format the message). A parameter value may also be a LocalizableMessage instance, in which case it will be localized in the appropriate culture.

update

I was looking for an example of the methods, take a look at https://github.com/bkoopman/sdl-tridion-world/blob/master/Example%20Event%20System/Example%20Event%20System/EventHandler.cs#L169

Properties.Resources.ResourceManager in there points to the Resource bundle added to the solution which you can find in the Properties folder: https://github.com/bkoopman/sdl-tridion-world/blob/master/Example%20Event%20System/Example%20Event%20System/Properties/Resources.resx

And you can then add localized resx files in the same location and make them Embedded Resources too.

1

Example of the first LocalizableMessage Bart has mentioned:

ResourceManager resourceManager = new ResourceManager("Some.Namespace.CustomErrorMessages", typeof(MyClass).Assembly);
throw new SomeLocalizableException(new LocalizableMessage (resourceManager, "MyErrorMessage"));

The assumption here is that there is an entry under the name of "MyErrorMessage" in the "Some.Namespace.CustomErrorMessages.resx" file. And that the SomeLocalizableException is an inherited class of the LocalizableException abstract class. The list of such classes can be found in the API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.