From bcc97bfaf54b53757c51af3f3d1e4a64d77183fd Mon Sep 17 00:00:00 2001 From: pfthomas Date: Tue, 28 Mar 2023 14:43:43 +0000 Subject: [PATCH] [MaterialDatePicker] Fix hint for Korean PiperOrigin-RevId: 520025180 --- .../com/google/android/material/datepicker/UtcDates.java | 5 +++++ .../google/android/material/datepicker/UtcDatesTest.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/java/com/google/android/material/datepicker/UtcDates.java b/lib/java/com/google/android/material/datepicker/UtcDates.java index 69ad28c1f9a..7f2f344c0e1 100644 --- a/lib/java/com/google/android/material/datepicker/UtcDates.java +++ b/lib/java/com/google/android/material/datepicker/UtcDates.java @@ -172,6 +172,11 @@ static String getDefaultTextInputHint(Resources res, SimpleDateFormat format) { formatHint = formatHint.replace("y", "yyyy"); } + // Remove duplicate year characters for Korean. + if (Locale.getDefault().getLanguage().equals(Locale.KOREAN.getLanguage())) { + formatHint = formatHint.replaceAll("y+", "y"); + } + return formatHint.replace("d", dayChar).replace("M", monthChar).replace("y", yearChar); } diff --git a/lib/javatests/com/google/android/material/datepicker/UtcDatesTest.java b/lib/javatests/com/google/android/material/datepicker/UtcDatesTest.java index eaff004859a..cebbbcd34dd 100644 --- a/lib/javatests/com/google/android/material/datepicker/UtcDatesTest.java +++ b/lib/javatests/com/google/android/material/datepicker/UtcDatesTest.java @@ -74,4 +74,13 @@ public void textInputHintWith1CharYearLocalized() { assertEquals("m/j/aaaa", hint); } + + @Test + @Config(qualifiers = "ko") + public void textInputHintForKorean() { + SimpleDateFormat sdf = new SimpleDateFormat("yy.M.d."); + String hint = UtcDates.getDefaultTextInputHint(context.getResources(), sdf); + + assertEquals("년.월.일.", hint); + } }