Skip to content

Commit

Permalink
Add fix: change TabBar localization by settings
Browse files Browse the repository at this point in the history
  • Loading branch information
unchase committed Mar 24, 2020
1 parent 286a353 commit 35f6182
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DotNetRu.Clients.UI/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,28 @@

<TabBar Route="root">
<Tab
x:Name="NewsTab"
Title="{Binding Resources[News]}"
Icon="tab_feed.png"
Route="news">
<ShellContent ContentTemplate="{DataTemplate home:NewsPage}" />
</Tab>
<Tab
x:Name="SpeakersTab"
Title="{Binding Resources[Speakers]}"
Icon="tab_speakers.png"
Route="speakers">
<ShellContent ContentTemplate="{DataTemplate speakers:SpeakersPage}" />
</Tab>
<Tab
x:Name="MeetupsTab"
Title="{Binding Resources[Meetups]}"
Icon="tab_events.png"
Route="meetups">
<ShellContent ContentTemplate="{DataTemplate meetups:MeetupsPage}" />
</Tab>
<Tab
x:Name="AboutTab"
Title="{Binding Resources[About]}"
Icon="tab_about.png"
Route="about">
Expand Down
19 changes: 19 additions & 0 deletions DotNetRu.Clients.UI/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using DotNetRu.Clients.Portable.Helpers;
using DotNetRu.Clients.Portable.ViewModel;
using DotNetRu.Utils.Helpers;
using Xamarin.Forms;

namespace DotNetRu.Clients.UI
Expand All @@ -15,6 +18,22 @@ public AppShell()

// Can't set BackgrounColor as StaticResource, see https://github.com/xamarin/Xamarin.Forms/issues/7055
SetBackgroundColor(this, backgroundColor);

MessagingCenter.Subscribe<LocalizedResources>(this, MessageKeys.LanguageChanged, sender => this.UpdateTabBarLocalization());
}

public void UpdateTabBarLocalization()
{
Device.BeginInvokeOnMainThread(() =>
{
if (this.BindingContext is ViewModelBase viewModel)
{
this.NewsTab.Title = viewModel.Resources["News"] ?? this.NewsTab.Title;
this.SpeakersTab.Title = viewModel.Resources["Speakers"] ?? this.SpeakersTab.Title;
this.MeetupsTab.Title = viewModel.Resources["Meetups"] ?? this.MeetupsTab.Title;
this.AboutTab.Title = viewModel.Resources["About"] ?? this.AboutTab.Title;
}
});
}
}
}

0 comments on commit 35f6182

Please sign in to comment.