Reputation: 247
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
Upvotes: 1
Views: 208
Reputation: 24614
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?
Upvotes: 0