View previous topic :: View next topic |
Author |
Message |
waltersb
Joined: 12 Jun 2012 Posts: 5
|
Posted: Tue Jun 12, 2012 2:46 pm Post subject: How do I localize XAML TextBlocks with formating elements |
|
|
Hi,
How can I localize the following XAML-Textblock?
With the standard WPF Globalizer conversion rules that textblock is not localized.
Code: |
<TextBlock>
<Bold>
Define alarms
</Bold>
<LineBreak>
<Italic>
Create or Change the alarms. Proceed as follows:
<LineBreak>
Choose the alarm source.
<LineBreak>
Indicate whether the alarm should be exceeded or fallen below the threshold.
<LineBreak>
</Italic>
</TextBlock>
|
Regards
Stefan |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Jun 13, 2012 1:32 am Post subject: |
|
|
Unfortunately there is no really nice way to do this that I could find. At first I thought that you may be able to simply define your text without the markup and then scan the XAML normally so that you get
Code: | <TextBlock Text="{Resx TextBlock_Text1}" /> |
Then I thought you could edit the resx value (either in Globalizer or Visual Studio) and add in the markup. However if you do this the Markup is not converted to attributes and is just displayed as text.
One solution I did find at:
http://www.charlespetzold.com/blog/2005/11/201108.html
Is to create TextBlock programatically and add it to its parent. So I added the code in the constructor of a page:
Code: | string str = WpfApp.Properties.Resources.TextBlock_Content;
StringReader strreader = new StringReader(str);
XmlTextReader xmlreader = new XmlTextReader(strreader);
TextBlock text = (TextBlock)XamlReader.Load(xmlreader);
_container.Content = text; |
And defined the TextBlock_Content resource to contain the markup eg
Code: | <TextBlock xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Bold>Define alarms</Bold>
<LineBreak/>
<Italic>
Create or Change the alarms. Proceed as follows:
<LineBreak/>
Choose the alarm source.
<LineBreak/>
Indicate whether the alarm should be exceeded or fallen below the threshold.
<LineBreak/>
</Italic>
</TextBlock> |
The resource will then be scanned by Globalizer and can be translated. _________________ Infralution Support |
|
Back to top |
|
|
waltersb
Joined: 12 Jun 2012 Posts: 5
|
Posted: Thu Jul 05, 2012 7:13 am Post subject: |
|
|
I used the following solution:
I encapsulated the individual sections of text in TextBlock elements
Code: |
<TextBlock Grid.Row="0" Margin="5">
<Bold>
<TextBlock Text="{Resx TextBlock_Text2}" />
</Bold>
<LineBreak />
<TextBlock Text="{Resx TextBlock_Text3}" />
<LineBreak />
<TextBlock Text="{Resx TextBlock_Text4}" />
<Italic>
<TextBlock Text="{Resx TextBlock_Text5}" />
</Italic>
<TextBlock Text="{Resx TextBlock_Text6}" />
</TextBlock>
|
|
|
Back to top |
|
|
|