Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do I localize XAML TextBlocks with formating elements

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support
View previous topic :: View next topic  
Author Message
waltersb



Joined: 12 Jun 2012
Posts: 5

PostPosted: Tue Jun 12, 2012 2:46 pm    Post subject: How do I localize XAML TextBlocks with formating elements Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jun 13, 2012 1:32 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
waltersb



Joined: 12 Jun 2012
Posts: 5

PostPosted: Thu Jul 05, 2012 7:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group