roomorama/Caldroid — pull request #77 by villesinisalo (2013-11-24 21:42:32+00:00)
Title: add support for overriding date string formats

I was using Caldroid, and it's pretty awesome. But I ran into problems when localizing to Finnish. As soon as I change my phone language to Finnish, some localization assumptions made by Caldroid fail (more detailed explanation below.) To allow fixing, I made it so that CaldroidFragment can be subclassed to manually specify the string formats for the month header and the week day column headers, by insulating the formatting code from in-line to two `protected` methods. Code-wise, it's pretty trivial, and no existing functionality has been altered in any way. But it's probably a must-have requirement to anyone wishing to correctly localize Caldroid.

#### In detail
So what is the localization assumption that fails? It's essentially that by simply changing the locale you get correctly localized strings for a wall calendar from a standard date formatting implementation designed for expressing individual dates in writing.

The problem is hard to demonstrate in English, as for English this *is* a valid assumption. The standard date string format is something like "24 November 2013" or "D MMMM YYYY". Then in Englsih, you can get the name of the month suitable for a *wall calendar* like Caldroid simply using Date4J's DateTime.format("MMMM"). But in languages unlike English, that make a heavy use of [declension](https://en.wikipedia.org/wiki/Declension), the name of the month in the standard date string format like "D MMMM YYYY" is not necessarily declined in the same noun case as is correct for wall calendars. In Finnish, for example, 2013-11-24 would be "24. marraskuuta 2013", yielding the [partitive case](https://en.wikipedia.org/wiki/Finnish_noun_cases) "marraskuuta" for DateTime.format("MMMM"). But a wall calendar should definitely use the nominative case form "Marraskuu" for the name of the month. Note the end of word and letter case; looks like a minute difference, but is actually not.

The other misassumption is that DateTime.format("WWW") returns sensible values. This is actually a bug with Date4J. With "WWW", it returns three-letter week day name abbreviations for every language regardless of locale:
```java
else if(WWW.equals(aCurrentToken)){
int weekday = aDateTime.getWeekDay();
result = firstThreeChars(fullWeekday(weekday));
}
```
But Finnish (and many other languages) use two-letter week day name abbreviations ("ma", "ti", "ke" ...), *never* three-letter ones like English ("Mon", "Tue," "Wed" ...). With a Finnish locale I get "maa", "tii", "kes" ... which is actually so bad that a native speaker could have hard time figuring out what is it even supposed to mean.

It seems the most straightforward fix is to subclass CaldroidFragment and explicitly specify month and week day names for each localized language in my app's private resources. There are anyway only 12 + 7 strings to specify (each month name and each week name) for the languages I am localizing for. The pull request only makes introducing custom month and week day formatting possible; it does ''not'' try to fix the problems described above because they are very specific to each and every language. One way forward in more universal regard could be to investigate how the platform Calendar app gets the right month and weekday strings, because it has them already correctly at least with Finnish as phone language.