Xamarin Localization and binding error

JoJo.1302JoJo.1302 USMember ✭✭

I have problem with translation binding text. How could I do it that binding item works fine ? I have tried change sequence but still nothing and i dont't have idea what now.

This code work fine

<Grid RowSpacing="10" Padding="30" VerticalOptions="Center" >

<Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>

    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>

    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Button  Grid.Row="2"  Text="{resource:TranslateExtension Szukaj}"
            BorderRadius="30"
            BackgroundColor="#80FFFFFF"

            FontSize="18"
            TextColor="#ffe2fb"
            BorderWidth="4"
            BorderColor="#ffe2fb"
            Clicked="Button_Clicked_1"/>

<Button  Grid.Row="3"  Text="{resource:TranslateExtension Mapa}"
            BorderRadius="30"
            BackgroundColor="#80FFFFFF"
            FontSize="18"
            TextColor="#ffe2fb"                    
            BorderWidth="4"
            BorderColor="#ffe2fb"
            Clicked="Button_Clicked"/> 

But this code not:

<RelativeLayout>
<ListView x:Name="ListaNazw" SeparatorColor="#3d122c" HasUnevenRows="True"
          RelativeLayout.HeightConstraint="{ConstraintExpression Property=Height,Factor=1,Type=RelativeToParent}"
          RelativeLayout.WidthConstraint="{ConstraintExpression Property=Width,Factor=1,Type=RelativeToParent}"  ItemSelected="ListaNazw_ItemSelected" >
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Horizontal"  Padding="5" BackgroundColor="#50FFFFFF">
                    <StackLayout HorizontalOptions="StartAndExpand">
                        <Label Text="{resource:TranslateExtension {Binding nazwa}}" TextColor="#fff2f2" FontSize="17"/>
                        <Label Text="{resource:TranslateExtension {Binding opis}}" TextColor="#ffe5e5" />
                    </StackLayout>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Answers

  • MabroukMabrouk USMember ✭✭✭
    edited October 16

    Hi,

    1. did you add this Attribute? :

             [ContentProperty("Text")]
              public class TranslateExtension : IMarkupExtension
      
    2. make it sure that you added in your XAML page , the Namespace where you extension is implemented.. like :
      xmlns:resource="clr-namespace:YOUR_APP.Utils" (this is an example)

    3. To translate : Text="{resource:Translate Mapa}" ( Translate not TranslateExtension)

    I hope that helps,
    Mabrouk

  • JoJo.1302JoJo.1302 USMember ✭✭

    Yes i did it, Like I wrote. Everything works besides . How translate this?

    {resource:TranslateExtension {Binding opis}} 
    {resource:TranslateExtension {Binding nazwa}} 
    
     Task.Factory.StartNew(() =>
                {
                    ListaNazw.ItemsSource = new List<Listyy>
              {
    
                  new Listyy { nazwa = "Pierwsze Spotkanie", opis="Niech to spotkanie będzie udane" , ema = 1 },
                  new Listyy { nazwa = "Spotkanie Biznesowe", opis = "Zaimponuj swojemu partnerowi", ema = 2 },
                  new Listyy { nazwa = "Spotkanie Towarzyskie", opis = "Make your day", ema = 3 },
                  new Listyy { nazwa = "Pierwsza Randka", opis = "Oczaruj swoją drugą połówkę", ema = 4 },
                  new Listyy { nazwa = "Pierwszy Raz", opis = "Zapewne to będzie wyjątkowe", ema = 5 },
                  new Listyy { nazwa = "Spotkanie", opis = "Luźna rozmowa przy kawie", ema = 6 },
                  new Listyy { nazwa = "Rozrywka", opis = "Czas na chwilę szaleństwa", ema = 7 },
                  new Listyy { nazwa = "Impreza", opis = "Ubierz coś ładnego, my zajmiemy się resztą", ema = 8 },
                  new Listyy { nazwa = "Spacer", opis = "Park, molo? Pozwól sobie pomóc", ema = 9 },
                  new Listyy { nazwa = "Odpoczynek", opis = "Chwila relaksu z pewnością Ci nie zaszkodzi", ema = 10 },
                  new Listyy { nazwa = "Urodziny", opis = "Zrób niespodziankę swoim bliskim", ema = 11 },
                  new Listyy { nazwa = "Czas wolny", opis = "Znajdziemy Ci idealne miejsce", ema = 12 },
    
              };
                });
            });
    
  • MabroukMabrouk USMember ✭✭✭
  • JoJo.1302JoJo.1302 USMember ✭✭

    i solved it

  • MabroukMabrouk USMember ✭✭✭

    @JoJo.1302

    Thats good that you solved it, but it will be well if you share the solution too if it wasn't my answer, that helps other developers to fix it when they meet the same Problem ;)

Sign In or Register to comment.