From 1ff81631609e9e1fb204b5af665a7762c55d0770 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 21 Aug 2016 20:32:05 +0200 Subject: [PATCH] lets use manually translated month names for reliability --- .../calendar/CalendarImpl.java | 2 +- .../simplemobiletools/calendar/Formatter.java | 21 +++++--------- .../calendar/activities/DayActivity.java | 2 +- .../calendar/activities/EventActivity.java | 4 +-- app/src/main/res/values-it/strings.xml | 13 +++++++++ app/src/main/res/values-ja/strings.xml | 13 +++++++++ app/src/main/res/values-sv/strings.xml | 13 +++++++++ app/src/main/res/values/strings.xml | 29 +++++++++++++++++++ 8 files changed, 80 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java b/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java index 72705ab98..1d4247d83 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java +++ b/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java @@ -92,7 +92,7 @@ public class CalendarImpl implements DBHelper.DBOperationsListener { } private String getMonthName() { - String month = Formatter.getMonthName(mTargetDate.getMonthOfYear() - 1); + String month = Formatter.getMonthName(mContext, mTargetDate.getMonthOfYear() - 1); final String targetYear = mTargetDate.toString(YEAR_PATTERN); if (!targetYear.equals(new DateTime().toString(YEAR_PATTERN))) { month += " " + targetYear; diff --git a/app/src/main/java/com/simplemobiletools/calendar/Formatter.java b/app/src/main/java/com/simplemobiletools/calendar/Formatter.java index 3ce668886..0f24b5a27 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/Formatter.java +++ b/app/src/main/java/com/simplemobiletools/calendar/Formatter.java @@ -1,28 +1,26 @@ package com.simplemobiletools.calendar; -import android.text.format.DateFormat; +import android.content.Context; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; -import java.util.Date; - public class Formatter { public static final String DAYCODE_PATTERN = "YYMMdd"; private static final String EVENT_DATE_PATTERN = "d YYYY"; // MMMM doesn't give the proper month name in some languages private static final String EVENT_TIME_PATTERN = "HH:mm"; - public static String getEventDate(String dayCode) { + public static String getEventDate(Context context, String dayCode) { final String dayYear = getDateTimeFromCode(dayCode).toString(EVENT_DATE_PATTERN); final int monthIndex = Integer.valueOf(dayCode.substring(2, 4)) - 1; - return getMonthName(monthIndex) + " " + dayYear; + return getMonthName(context, monthIndex) + " " + dayYear; } - public static String getEventDate(DateTime dateTime) { + public static String getEventDate(Context context, DateTime dateTime) { final String dayYear = dateTime.toString(EVENT_DATE_PATTERN); - return getMonthName(dateTime.getMonthOfYear() - 1) + " " + dayYear; + return getMonthName(context, dateTime.getMonthOfYear() - 1) + " " + dayYear; } public static String getEventTime(DateTime dateTime) { @@ -63,11 +61,8 @@ public class Formatter { return dateTime.toDateTime(DateTimeZone.getDefault()).toString(Formatter.DAYCODE_PATTERN); } - public static String getMonthName(int id) { - final Date date = new Date(); - date.setDate(1); - date.setMonth(id); - String month = DateFormat.format("LLLL", date).toString(); - return month.substring(0, 1).toUpperCase() + month.substring(1).toLowerCase(); + // use manually translated month names, as DateFormat and Joda have issues with a lot of languages + public static String getMonthName(Context context, int id) { + return context.getResources().getStringArray(R.array.months)[id]; } } diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java index fedcfc41f..1cc941b07 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java @@ -74,7 +74,7 @@ public class DayActivity extends SimpleActivity if (mDayCode == null || mDayCode.isEmpty()) return; - final String date = Formatter.getEventDate(mDayCode); + final String date = Formatter.getEventDate(getApplicationContext(), mDayCode); mDateTV.setText(date); mToBeDeleted = new ArrayList<>(); diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java index 3ee4b2cd3..ba33af1f1 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java @@ -219,7 +219,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio } private void updateStartDate() { - mStartDate.setText(Formatter.getEventDate(mEventStartDateTime)); + mStartDate.setText(Formatter.getEventDate(getApplicationContext(), mEventStartDateTime)); } private void updateStartTime() { @@ -227,7 +227,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio } private void updateEndDate() { - mEndDate.setText(Formatter.getEventDate(mEventEndDateTime)); + mEndDate.setText(Formatter.getEventDate(getApplicationContext(), mEventEndDateTime)); } private void updateEndTime() { diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9c043657f..d43d20d18 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -53,4 +53,17 @@ 1 evento eliminato %1$d eventi eliminati + + Gennaio + Febbraio + Marzo + Aprile + Può + Giugno + Luglio + August + Settembre + Ottobre + Novembre + Dicembre diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 093a6d6f1..4217dac42 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -53,4 +53,17 @@ 1 イベントを削除しました %1$d イベントを削除しました + + January + February + March + April + May + June + July + August + September + October + November + December diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index e42a32fc5..c379dbf15 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -53,4 +53,17 @@ 1 händelse borttagen %1$d händelser borttagna + + Januari + Februari + Mars + April + Maj + Juni + Juli + Augusti + September + Oktober + November + December diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e856d324f..44f0d5439 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,4 +60,33 @@ 1 event deleted %1$d events deleted + + January + February + March + April + May + June + July + August + September + October + November + December + + + @string/january + @string/february + @string/march + @string/april + @string/may + @string/june + @string/july + @string/august + @string/september + @string/october + @string/november + @string/december + +