Hey guys,
Here is what I think is an innovative approach to localization, using a standard binding syntax. As far as I can judge, this solution will fail in Silverlight (as will most other solutions anyway…), but it has the advantage of being dynamic, of using a Binding syntax which is more familiar than a custom markup extension (even though the “dot” and array syntax is probably not very familiar to many newbies), and provides a fallback value for design mode.
What do you guys think?
Laurent
--
Laurent Bugnion [Microsoft MVP, MCP]
Blog: http://blog.galasoft.ch
Support children in Calcutta: http://www.calcutta-espoir.ch
|
|
My business card as |
Very interesting and far better that locbaml stuff, love to have same syntax on SL too, at the moment closest counterpart is the one’s from Tim Heuer
http://timheuer.com/blog/archive/2009/08/26/silverlight-string-localization.aspx
-Corrado
BTW: In my current Silverlight project I’ve created a LocalizedViewModelBase as base for others Viewmodel that requires localization:
public class LocalizableViewModelBase : ViewModelBase
{
private static Resources resources = new Resources();
private static CultureInfo cachedCulture;
public Resources LocalizedText
{
get
{
return resources;
}
}
protected void SetCulture(string userCulture, bool cacheCurrent)
{
…
if (Thread.CurrentThread.CurrentUICulture.Name != userCulture)
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(userCulture);
this.RaisePropertyChanged("LocalizedText");
}
}
}
and then I bind UI elements this way:
<TextBlock Text="{Binding LocalizedText.UserName, Mode=OneWay}"
TextWrapping="Wrap"
Height="15"
VerticalAlignment="Bottom"
Grid.Column="1" />
What do you think?
-Corrado
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Laurent Bugnion, GalaSoft
Sent: martedì 8 settembre 2009 23:27
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Interesting approach to localization
Yes, I use Visual Studio integrated editor, works pretty well…
-Corrado
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Laurent Bugnion, GalaSoft
Sent: mercoledì 9 settembre 2009 07:48
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: Interesting approach to localization
Hey Corrado,
How do you set the texts in the resources? Do you use the Resx file?
Laurent
From: wpf-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com] On Behalf Of Corrado Cavalli
Sent: Wednesday, September 09, 2009 7:05 AM
To: wpf-di...@googlegroups.com
Subject: [WPF Disciples] Re: Interesting approach to localization
BTW: In my current Silverlight project I’ve created a LocalizedViewModelBase as base for others Viewmodel that requires localization: