-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Axemasta/feature/binding-extensions
Add SetTranslation Binding Extension
- Loading branch information
Showing
37 changed files
with
915 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Application | ||
x:Class="Mocale.Samples.App" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
x:Class="Mocale.Samples.App" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
using Mocale.Samples.Views; | ||
namespace Mocale.Samples; | ||
|
||
public partial class App : Application | ||
{ | ||
public App(IntroductionPage introductionPage) | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
|
||
MainPage = new NavigationPage(introductionPage); | ||
MainPage = new AppShell(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Shell | ||
TabBarIsVisible="False" | ||
x:Class="Mocale.Samples.AppShell" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:keys="clr-namespace:Mocale.Translations" | ||
xmlns:mocale="http://axemasta.com/schemas/2022/mocale" | ||
xmlns:pages="clr-namespace:Mocale.Samples.Pages" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> | ||
|
||
|
||
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems"> | ||
<ShellContent ContentTemplate="{DataTemplate pages:IntroductionPage}" Title="{mocale:Localize Key={x:Static keys:TranslationKeys.IntroductionPageTitle}}" /> | ||
|
||
<ShellContent ContentTemplate="{DataTemplate pages:BindingPage}" Title="{mocale:Localize Key={x:Static keys:TranslationKeys.BindingPageTitle}}" /> | ||
|
||
<ShellContent ContentTemplate="{DataTemplate pages:ParameterPage}" Title="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageTitle}}" /> | ||
</FlyoutItem> | ||
</Shell> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Mocale.Samples; | ||
|
||
public partial class AppShell : Shell | ||
{ | ||
public AppShell() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
samples/Mocale.Samples/Converters/CityDescriptionConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Globalization; | ||
|
||
namespace Mocale.Samples.Converters; | ||
|
||
internal sealed class CityDescriptionConverter : IValueConverter | ||
{ | ||
private readonly ITranslatorManager translatorManager = MocaleLocator.TranslatorManager; | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (value is not string) | ||
{ | ||
throw new InvalidOperationException($"Value must be of type {nameof(String)}"); | ||
} | ||
|
||
var key = $"CityDescription_{value}"; | ||
|
||
//return new Binding | ||
//{ | ||
// Mode = BindingMode.OneWay, | ||
// Path = $"[{key}]", | ||
// Source = translatorManager, | ||
//}; | ||
|
||
return translatorManager.Translate(key); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
108 changes: 54 additions & 54 deletions
108
...mples/Converter/LanguageEmojiConverter.cs → ...ples/Converters/LanguageEmojiConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
using System.Globalization; | ||
|
||
namespace Mocale.Samples.Converter; | ||
|
||
internal sealed class LanguageEmojiConverter : IValueConverter | ||
{ | ||
private readonly ITranslatorManager translatorManager; | ||
|
||
public LanguageEmojiConverter() | ||
{ | ||
translatorManager = MocaleLocator.TranslatorManager; | ||
} | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var currentCulture = translatorManager.CurrentCulture; | ||
|
||
if (currentCulture is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return GetFlag(currentCulture.EnglishName); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private static string GetFlag(string country) | ||
{ | ||
// Adapted from | ||
// https://itnext.io/convert-country-name-to-flag-emoji-in-c-the-net-ecosystem-115f714d3ef9 | ||
var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).ToList(); | ||
var englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(country)); | ||
|
||
if (englishRegion == null) | ||
{ | ||
return "🏳"; | ||
} | ||
|
||
var region = new RegionInfo(englishRegion.LCID); | ||
|
||
var countryAbbrev = region.TwoLetterISORegionName; | ||
var flag = IsoCountryCodeToFlagEmoji(countryAbbrev); | ||
return flag; | ||
} | ||
|
||
private static string IsoCountryCodeToFlagEmoji(string countryCode) | ||
{ | ||
return string.Concat(countryCode.ToUpperInvariant().Select(x => char.ConvertFromUtf32(x + 0x1F1A5))); | ||
} | ||
} | ||
using System.Globalization; | ||
|
||
namespace Mocale.Samples.Converters; | ||
|
||
internal sealed class LanguageEmojiConverter : IValueConverter | ||
{ | ||
private readonly ITranslatorManager translatorManager; | ||
|
||
public LanguageEmojiConverter() | ||
{ | ||
translatorManager = MocaleLocator.TranslatorManager; | ||
} | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var currentCulture = translatorManager.CurrentCulture; | ||
|
||
if (currentCulture is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return GetFlag(currentCulture.EnglishName); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private static string GetFlag(string country) | ||
{ | ||
// Adapted from | ||
// https://itnext.io/convert-country-name-to-flag-emoji-in-c-the-net-ecosystem-115f714d3ef9 | ||
var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).ToList(); | ||
var englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(country)); | ||
|
||
if (englishRegion == null) | ||
{ | ||
return "🏳"; | ||
} | ||
|
||
var region = new RegionInfo(englishRegion.LCID); | ||
|
||
var countryAbbrev = region.TwoLetterISORegionName; | ||
var flag = IsoCountryCodeToFlagEmoji(countryAbbrev); | ||
return flag; | ||
} | ||
|
||
private static string IsoCountryCodeToFlagEmoji(string countryCode) | ||
{ | ||
return string.Concat(countryCode.ToUpperInvariant().Select(x => char.ConvertFromUtf32(x + 0x1F1A5))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.