1

The project I am working on supports a number of locales. The solution is based on using some Castle Monorail mechanism. Appropriate controller class is marked as follows:

[Resource("pageResx", "...Controllers.Static")]

Where StaticTemplate is the Controller name prefix and resource file is placed in '..\Resources\Controllers\StaticTemplate*'.

On the other hand StatiController inherits from the BaseController class which is marked as follows:

[LocalizationFilter(RequestStore.Session, "locale")]

So, the locale for the user is stored in the session. And this is it. The final step is NVelocity vm-file where the appropriate resource is taken like this:

$pageResx.Buttons_Download

This way the resource string with ID = 'Buttons_Download' for user with locale='de' is taken from file '..\Resources\Controllers\Static.de.resx'.

However, there is another place in the project where localization is held - constructing emails. The following logic is implemented there:

public class EmailPersonalizer : IEmailPersonalizer
{
    ...
    printJobResourceManager = new ResourceManager("...Resources.PrintJob", 
                                        typeof (EmailPersonalizer).Assembly);
    public string ToLocalizedString(string resourceId, VendorUser user, 
          params object[] args)
    {
        ...
        var resourceString = printJobResourceManager.GetString(resourceId, 
                                    culture);
        ...
    }
    ...
}

Given values for the parameters the resourceString is evaluated correctly. But...

Here comes the Magic. There is a resource file for brazilian locale. It has suffix 'pt-BR'. There is also portuguese locale, but no appropriate resource file - no 'pt' file. In terms of view pages Monorail gets the localized resource from pt-BR file for pt-user. But the logic which implements the email constructing fails to do the same. Instead is gets the localized string from the basic resource which 'en' is used to be.

I read about the .NET mechanism for mapping resources (http://msdn.microsoft.com/en-us/library/sb6a8618.aspx). But failed to find the description for Monorail's one.

The question is how does Monorail (or whoever) map 'pt' to 'pt-BR'? And what am I supposed to do to implement the same logic outside?

Thanks in advance

godspeed
  • 247
  • 1
  • 4
  • 15
  • I am guessing here that you are not using Monorail's Email rendering mechanism, am I correct? if you did, it should have used the same resource-resolution mechanism used for regular web views – Ken Egozi Feb 04 '13 at 18:42
  • also - would you be able to specify which version of Monorail you are using in this project? – Ken Egozi Feb 04 '13 at 18:42
  • > Ken: You are right - I am not using Monorail's Email rendering mechanism. We use Monorail v2.0.5* on the project. – godspeed Feb 05 '13 at 07:20
  • > Ken: I use monorail approach in constructing email body. But the thing is it is implemented on server side. Another project at all. So that is the logic: printJobResourceManager = new ResourceManager("...Resources.PrintJob", typeof (EmailPersonalizer).Assembly); – godspeed Feb 05 '13 at 09:38
  • how are you setting that `culture` value? and what is the CurrentCulture and CurrentUICulture? – Ken Egozi May 01 '13 at 22:17

1 Answers1

0

I'm assuming this is runs outside of the visitors web context? In order for .NET to fetch the appropriate strings from your resources, you will need to change the culture of the current thread:

var culture = CultureInfo.CreateSpecificCulture( "pt" );
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

I see that you pass on culture in your call:

 var resourceString = printJobResourceManager.GetString(resourceId, 
                                culture);

Are you saying that this invoke returns the worng result even when you send in the appropriate culture?

jishi
  • 24,126
  • 6
  • 49
  • 75