I have a problem localizing a Silverlight application using resources. I wanted my multilingual engine to be cross-platform, so I put all the localized resources in a project like Portable Class Library. In this project, I created two resource files, Localization.resx and Localization.en.resx, and I set the modifier access for the public in both files. Then I created a proxy class called "LocalizationProxy", which is a proxy class for enabling bindings.
public class LocalizationProxy : INotifyPropertyChanged { public Localization LocalizationManager { get; private set; } public LocalizationProxy() { LocalizationManager = new Localization(); } public void ResetResources() { OnPropertyChanged(() => LocalizationManager); } #region INotifyPropertyChanged region public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged<T>(Expression<Func<T>> selector) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(GetPropertyNameFromExpression(selector))); } } public static string GetPropertyNameFromExpression<T>(Expression<Func<T>> property) { var lambda = (LambdaExpression)property; MemberExpression memberExpression; if (lambda.Body is UnaryExpression) { var unaryExpression = (UnaryExpression)lambda.Body; memberExpression = (MemberExpression)unaryExpression.Operand; } else { memberExpression = (MemberExpression)lambda.Body; } return memberExpression.Member.Name; } #endregion }
In the next step, I modified the Silverlight csproj file and added the culture "en" to the supported types
<SupportedCultures>en</SupportedCultures>
In addition, in the application resources that I created and the instance of the LocalizationProxy class
<Application.Resources> <Localization:LocalizationProxy x:Key="LocalizationProxy"></Localization:LocalizationProxy> </Application.Resources>
I also changed the "Neutral language" in the assembly to "Polish" - this should be the default application language. In the last step, I moved some values ββfrom the view to resources
<TextBlock TextWrapping="Wrap" x:Name="PageTitle" Text="{Binding Source={StaticResource LocalizationProxy},Path=LocalizationManager.Title,Mode=TwoWay}" />
Unfortunately, even though Thread.CurrentThread.CurrentCulture is "pl-PL", my application is still in English. However, if I use the same code in a Windows Phone application, everything works fine - I can even change the language of the application at runtime, is there a difference in the localization of the Silverlight application and the localization of Windows Phone applications?
Here is my application
http://www.fileserve.com/file/TkQkAhV/LocalizationSolution.rar
As I mentioned earlier, localization in Windows Phone works fine, but the labels are not translated in Silverlight applications