lets use manually translated month names for reliability

This commit is contained in:
tibbi 2016-08-21 20:32:05 +02:00
parent 9fd690f0d9
commit 1ff8163160
8 changed files with 80 additions and 17 deletions

View file

@ -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;

View file

@ -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];
}
}

View file

@ -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<>();

View file

@ -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() {

View file

@ -53,4 +53,17 @@
<item quantity="one">1 evento eliminato</item>
<item quantity="other">%1$d eventi eliminati</item>
</plurals>
<string name="january">Gennaio</string>
<string name="february">Febbraio</string>
<string name="march">Marzo</string>
<string name="april">Aprile</string>
<string name="may">Può</string>
<string name="june">Giugno</string>
<string name="july">Luglio</string>
<string name="august">August</string>
<string name="september">Settembre</string>
<string name="october">Ottobre</string>
<string name="november">Novembre</string>
<string name="december">Dicembre</string>
</resources>

View file

@ -53,4 +53,17 @@
<item quantity="one">1 イベントを削除しました</item>
<item quantity="other">%1$d イベントを削除しました</item>
</plurals>
<string name="january">January</string>
<string name="february">February</string>
<string name="march">March</string>
<string name="april">April</string>
<string name="may">May</string>
<string name="june">June</string>
<string name="july">July</string>
<string name="august">August</string>
<string name="september">September</string>
<string name="october">October</string>
<string name="november">November</string>
<string name="december">December</string>
</resources>

View file

@ -53,4 +53,17 @@
<item quantity="one">1 händelse borttagen</item>
<item quantity="other">%1$d händelser borttagna</item>
</plurals>
<string name="january">Januari</string>
<string name="february">Februari</string>
<string name="march">Mars</string>
<string name="april">April</string>
<string name="may">Maj</string>
<string name="june">Juni</string>
<string name="july">Juli</string>
<string name="august">Augusti</string>
<string name="september">September</string>
<string name="october">Oktober</string>
<string name="november">November</string>
<string name="december">December</string>
</resources>

View file

@ -60,4 +60,33 @@
<item quantity="one">1 event deleted</item>
<item quantity="other">%1$d events deleted</item>
</plurals>
<string name="january">January</string>
<string name="february">February</string>
<string name="march">March</string>
<string name="april">April</string>
<string name="may">May</string>
<string name="june">June</string>
<string name="july">July</string>
<string name="august">August</string>
<string name="september">September</string>
<string name="october">October</string>
<string name="november">November</string>
<string name="december">December</string>
<string-array name="months" translatable="false">
<item>@string/january</item>
<item>@string/february</item>
<item>@string/march</item>
<item>@string/april</item>
<item>@string/may</item>
<item>@string/june</item>
<item>@string/july</item>
<item>@string/august</item>
<item>@string/september</item>
<item>@string/october</item>
<item>@string/november</item>
<item>@string/december</item>
</string-array>
</resources>