Skip to content

Working With Localization

Youssef Sellami edited this page Nov 10, 2022 · 3 revisions

the method .WithMessage() takes a string message as input and associates it with the Result object instance.
so if you want to attach a localized message to the Result object, you need to do the following:

// so you may have an action that retrieves the localized message string
var localized_message =  GetLocalizedMessage("some_text_code");

// and then you pass the message value
var result = Result.Failure()
   .WithMessage(localized_message)
   .WithCode("some_error_code");

as you can see this breaks the fluent nature of the Result object instantiation. now, how can we fix this?

.WithLocalizedMessage()

in version 1.4.0 we have introduced a new extension method that will allow you to set the localized message in a more fluent manner.

// to use the error code as the text_code
var result = Result.Failure()
   .WithCode("some_error_code")
   .WithLocalizedMessage();

// to use the error code as the text_code
var result = Result.Failure()
   .WithLocalizedMessage("text_code");

But where do these localized messages come from?

Clone this wiki locally