Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix datetimepickerlocalization (#11474) fixes #11471 fixes #11472 fixes
Browse files Browse the repository at this point in the history
#12556

* fix date and time picker localizations

* fixed UWP datepicker

* edited UWP datepicker

* added UI tests for datetime picker localization

* Fixes #11472
Fixes #11471

* fixes #11471 fixes #11472

* fixes #11471 fixes #11472

* fixes #11471 #11472

* fixes #11471 #11472

* fixes #11471 #11472

* reverted csproj

* fixes #11471 #11472

* fixes #11471 #11472

* fixes #11471 #11472

* fixes #11471 #11472

* fixes #11471 #11472

* fixes #11471 #11472

* fixes #11471 #11472

* Update Xamarin.Forms.ControlGallery.Tizen.csproj

* Update ErrorMessages.Designer.cs

* - fix uwp

Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
  • Loading branch information
memu8 and PureWeen committed Nov 11, 2020
1 parent ebd6ac3 commit 938700b
Show file tree
Hide file tree
Showing 22 changed files with 612 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Xamarin.Forms.Build.Tasks/ErrorMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Xamarin.Forms.ControlGallery.iOS/GalleryPages/RegionalLocale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using Foundation;
using Xamarin.Forms;
using Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries;

[assembly: Dependency(typeof(Xamarin.Forms.ControlGallery.iOS.GalleryPages.RegionalLocale))]
namespace Xamarin.Forms.ControlGallery.iOS.GalleryPages
{
public class RegionalLocale : ILocalize
{
public string GetCurrentCultureInfo()
{
string iOSLocale = NSLocale.CurrentLocale.CountryCode;
string iOSLanguage = NSLocale.CurrentLocale.LanguageCode;
return iOSLanguage + "-" + iOSLocale;
}
}
}
2 changes: 2 additions & 0 deletions Xamarin.Forms.ControlGallery.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
<array>
<string>en</string>
<string>ar</string>
<string>fr</string>
<string>de</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.DatePicker)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11472, "DateTime Localization Issue",
PlatformAffected.iOS | PlatformAffected.Android)]
public class DateTimeLocalizationTests : TestNavigationPage
{
protected override void Init()
{
#if APP
PushAsync(new GalleryPages.DateTimePickerGalleries.DateTimePickerGallery());
#endif
}

#if UITEST

public string TimeString(String format, String time)
{
RunningApp.ClearText("timeFormatString");
RunningApp.EnterText("timeFormatString", format);
RunningApp.PressEnter();
RunningApp.ClearText("settingTime");
RunningApp.EnterText("settingTime", time);
RunningApp.PressEnter();
var text = RunningApp.WaitForElement("timeClockOptions")[0].ReadText();
return text;
}

public string DateString(String format, String date)
{
RunningApp.ClearText("dateFormatString");
RunningApp.EnterText("dateFormatString", format);
RunningApp.PressEnter();
RunningApp.ClearText("settingDate");
RunningApp.EnterText("settingDate", date);
RunningApp.PressEnter();
var text = RunningApp.WaitForElement("dateCalendarOptions")[0].ReadText();
return text;
}

[Test]
public void TimePicker24H()
{
RunningApp.Tap(x => x.Marked("TimePicker"));
Assert.AreEqual("0.0.0 A", TimeString("H.m.s t", "0, 0"));
Assert.AreEqual("13:05 PM", TimeString("HH:mm tt", "13, 5"));
Assert.AreEqual("12 PM", TimeString("HH tt", "12, 0"));
Assert.AreEqual("5.", TimeString("H.", "5, 1"));
}

[Test]
public void TimePicker12H()
{
RunningApp.Tap(x => x.Marked("TimePicker"));
Assert.AreEqual("12 0/AM", TimeString("hh m/tt", "0, 0"));
Assert.AreEqual("12", TimeString("hh", "12, 37"));
Assert.AreEqual("11-00", TimeString("h-ss", "23, 59"));
Assert.AreEqual("07:59", TimeString("hh:mm", "7, 59"));

}

[Test]
public void TimePickerOther()
{
RunningApp.Tap(x => x.Marked("TimePicker"));
Assert.AreEqual("59, P", TimeString("mm, t", "13, 59"));
Assert.AreEqual("ABCDEGIJLNOP", TimeString("ABCDEGIJLNOP", "23, 59"));
Assert.AreEqual("QRSTUVWXYZ", TimeString("QRSTUVWXYZ", "23, 59"));
Assert.AreEqual("abceijklnopqruvwx", TimeString("abceijklnopqruvwx", "23, 59"));
}

[Test]
public void DatePickerDMY()
{
RunningApp.Tap(x => x.Marked("DatePicker"));
Assert.AreEqual("31/1/99", DateString("d/M/y", "1999, 1, 31"));
Assert.AreEqual("02-29-00", DateString("MM-dd-yy", "2000, 2, 29"));
Assert.AreEqual("2010, Apr, Thu", DateString("yyy, MMM, ddd", "2010, 4, 15"));
Assert.AreEqual("August.Saturday.2015", DateString("MMMM.dddd.yyyy", "2015, 8, 1"));
}

[Test]
public void DatePickerMissing()
{
RunningApp.Tap(x => x.Marked("DatePicker"));
Assert.AreEqual("October 97", DateString("MMMM yy", "1997, 10, 30"));
Assert.AreEqual("Monday", DateString("dddd", "2020, 7, 20"));
Assert.AreEqual("2002: Dec", DateString("yyyy: MMM", "2002, 12, 31"));
}

[Test]
public void DatePickerLetters()
{
RunningApp.Tap(x => x.Marked("DatePicker"));
Assert.AreEqual("ABCDEGIJLNOP", DateString("ABCDEGIJLNOP", "2002, 12, 31"));
Assert.AreEqual("QRSTUVWXYZ", DateString("QRSTUVWXYZ", "2002, 12, 31"));
Assert.AreEqual("abceijklnopqruvwx", DateString("abceijklnopqruvwx", "2002, 12, 31"));
}

#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11430.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11247.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10608.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateTimePickerLocalizationTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11800.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11572.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11571.xaml.cs" />
Expand Down Expand Up @@ -2463,4 +2464,4 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>
2 changes: 2 additions & 0 deletions Xamarin.Forms.Controls/CoreGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Xamarin.Forms.Controls.GalleryPages.AppThemeGalleries;
using Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries;
using Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.CarouselViewGalleries;
using Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries;
using Xamarin.Forms.Controls.GalleryPages.DragAndDropGalleries;
using Xamarin.Forms.Controls.GalleryPages.GradientGalleries;
using Xamarin.Forms.Controls.GalleryPages.PlatformTestsGallery;
Expand Down Expand Up @@ -336,6 +337,7 @@ public override string ToString()
new GalleryPageFactory(() => new AlertGallery(), "DisplayAlert Gallery"),
new GalleryPageFactory(() => new ToolbarItems(), "ToolbarItems Gallery"),
new GalleryPageFactory(() => new ActionSheetGallery(), "ActionSheet Gallery"),
new GalleryPageFactory(() => new DateTimePickerGallery(), "DateTime Picker Localization Gallery"),
new GalleryPageFactory(() => new ActivityIndicatorCoreGalleryPage(), "ActivityIndicator Gallery"),
new GalleryPageFactory(() => new BehaviorsAndTriggers(), "BehaviorsTriggers Gallery"),
new GalleryPageFactory(() => new ContextActionsGallery(), "ContextActions List Gallery"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries.DatePage"
Title="DatePicker">
<ContentPage.Content>
<ScrollView>
<StackLayout VerticalOptions="Center" Padding="10">
<Label Text="DatePicker Default (No Format String):" FontSize="20" FontAttributes="Bold" TextColor="#2488ad"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" Margin="20">
<Label Text="DatePicker:" FontSize="18" VerticalOptions="Center"/>
<DatePicker x:Name="datepickerdefault" HorizontalOptions="CenterAndExpand" MinimumWidthRequest="110"/>
</StackLayout>
<Label Text="DatePicker Changes With Format String:" FontSize="20" FontAttributes="Bold" TextColor="#2488ad"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="DatePicker:" FontSize="16" VerticalOptions="Center"/>
<DatePicker x:Name="datepicker" HorizontalOptions="CenterAndExpand" WidthRequest="300" AutomationId="dateCalendarOptions"/>
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="Set Date (year, month, day):" FontSize="18" VerticalOptions="Center" />
<Entry x:Name="dateSetting" AutomationId="settingDate" Placeholder="enter Date " MaxLength="20" HorizontalOptions="CenterAndExpand" Completed="dateSetting_Completed"/>
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="Format String:" FontSize="18" VerticalOptions="Center"/>
<Entry x:Name="dateformat" AutomationId="dateFormatString" Placeholder="enter Format string" MaxLength="20" Completed="dateformat_Completed" VerticalOptions="Center"/>
</StackLayout>
<Label x:Name="datesphoneculture" HorizontalOptions="CenterAndExpand" FontSize="18" Margin="20"/>
<Label HorizontalOptions="StartAndExpand" FontSize="10" FontAttributes="Bold" TextColor="Black" Text="Format String Key:"/>
<Label HorizontalOptions="StartAndExpand" FontSize="10" TextColor="Black" Text=" &#x2022; M, MM = month from 1-12/01-12
&#x0a; &#x2022; MMM/MMMM = abbreviated/full month string
&#x0a; &#x2022; d/dd = day from 0-31/01-31
&#x0a; &#x2022; ddd/dddd = abbreviated/full day of the week
&#x0a; &#x2022; y, yy, yyy, yyyy = year with at least corresponding number of digits" />
<Label HorizontalOptions="StartAndExpand" FontSize="10" FontAttributes="Bold" TextColor="Black" Text="Some Example Format Strings:" />
<Label HorizontalOptions="StartAndExpand" FontSize="10" TextColor="Black" Text=" &#x2022; MM/dd/yy
&#x0a; &#x2022; MMMM.d.yyyy
&#x0a; &#x2022; dd-M-yy
&#x0a; &#x2022; MMMM dd, yyyy" />
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="See full list of date/time format strings here"
TextColor="Blue"
TextDecorations="Underline"
FontSize="10">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}"
CommandParameter="https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings"/>
</Span.GestureRecognizers>
</Span>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries
{
public partial class DatePage : ContentPage
{
public DatePage()
{
InitializeComponent();
BindingContext = this;
var dep = DependencyService.Get<ILocalize>();
if (dep != null)
{
datesphoneculture.Text = $"Device Culture: {dep.GetCurrentCultureInfo()}";
}
else
{
var s = System.Globalization.CultureInfo.CurrentCulture.Name;
datesphoneculture.Text = "Device Culture: " + s;
}
}

void dateformat_Completed(System.Object sender, System.EventArgs e)
{
var text = ((Entry)sender).Text;
datepicker.Format = text;
}

void dateSetting_Completed(System.Object sender, System.EventArgs e)
{
var date = ((Entry)sender).Text;
string[] divided = date.Split(',');
int[] sep_dates = Array.ConvertAll(divided, int.Parse);
datepicker.Date = new DateTime(sep_dates[0], sep_dates[1], sep_dates[2]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries"
x:Class="Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries.DateTimePickerGallery">
<local:DatePage AutomationId = "DateTab"/>
<local:TimePage AutomationId ="TimeTab"/>
<local:KeyboardPage/>
</TabbedPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Xamarin.Forms.Xaml;

namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DateTimePickerGallery : TabbedPage
{
public DateTimePickerGallery()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Globalization;
namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries
{
public interface ILocalize
{
string GetCurrentCultureInfo();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries.KeyboardPage"
Title="Keyboards">
<ContentPage.Content>
<ScrollView>
<StackLayout VerticalOptions="Center" Padding="10">
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="Keyboard Type Picker:" FontSize="18" VerticalOptions="Center" />
<Picker x:Name="KeyboardType" HorizontalOptions="FillAndExpand" WidthRequest="100" SelectedIndexChanged="KeyboardType_SelectedIndexChanged">
<Picker.Items>
<x:String>Default</x:String>
<x:String>Numeric</x:String>
<x:String>Plain</x:String>
<x:String>Text</x:String>
<x:String>Chat</x:String>
<x:String>Email</x:String>
<x:String>Telephone</x:String>
<x:String>Url</x:String>
</Picker.Items>
</Picker>
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="Entry with Keyboard:" FontSize="18" VerticalOptions="Center" />
<Entry x:Name="keyboardEntry" Placeholder="click to see keyboard" HorizontalOptions="CenterAndExpand"/>
</StackLayout>
<Label x:Name="keyboardphoneculture" HorizontalOptions="CenterAndExpand" FontSize="18" Margin="20"/>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries
{
public partial class KeyboardPage : ContentPage
{
public KeyboardPage()
{
InitializeComponent();
BindingContext = this;
var dep = DependencyService.Get<ILocalize>();
if (dep != null)
{
keyboardphoneculture.Text = $"Device Culture: {dep.GetCurrentCultureInfo()}";
}
else
{
var s = System.Globalization.CultureInfo.CurrentCulture.Name;
keyboardphoneculture.Text = "Device Culture: " + s;
}
}

void KeyboardType_SelectedIndexChanged(System.Object sender, System.EventArgs e)
{
string selectedValue = KeyboardType.Items[KeyboardType.SelectedIndex];
var converter = new KeyboardTypeConverter();
string keyboardStringValue = "Keyboard." + selectedValue;
keyboardEntry.Keyboard = (Keyboard)converter.ConvertFromInvariantString(keyboardStringValue);
}
}
}
Loading

0 comments on commit 938700b

Please sign in to comment.