Displaying day name in long and short format for all languages

Sorry to ask a similar question to before but this is slightly different.

How (what actual steps) whould I take to be able to show the days of the week in short (Mon, Tue, etc) and long (Monday, Tuesday) format for all languages supported by all devices when I'm using a custom font?

Clearly I have to make sure ALL possible characters are in my font, i.e. Latin and Cyrillic (this might be a problem as resources are an issue).

At the moment I get the short version in English and convert it to the long format. But do I have to detect the langauge and store all the long versions for all languages?

Also can this actually be tested in the simulator?

Thanks!
  • It would seem to me that you'd want to create a language-specific resource strings file (e.g., resources-ces/strings.xml for Czech) for each language that you wish to support. That file would look something like this, and you have to be sure to save the file with a proper encoding (UTF-8)...

    <resources>
    <strings>
    <string id="day0Abbr">ne</string>
    <string id="day1Abbr">po</string>
    <string id="day2Abbr">út</string>
    <string id="day3Abbr">st</string>
    <string id="day4Abbr">&#269;t</string>
    <string id="day5Abbr">pá</string>
    <string id="day6Abbr">so</string>

    <string id="day0Name">ned&#283;le</string>
    <string id="day1Name">pond&#283;lí</string>
    <string id="day2Name">úterý</string>
    <string id="day3Name">st&#345;eda</string>
    <string id="day4Name">&#269;tvrtek</string>
    <string id="day5Name">pátek</string>
    <string id="day6Name">sobota</string>

    <string id="mon1Abbr">led.</string>
    <string id="mon2Abbr">ún.</string>
    <string id="mon3Abbr">b&#345;ez.</string>
    <string id="mon4Abbr">dub.</string>
    <string id="mon5Abbr">kv&#283;t.</string>
    <string id="mon6Abbr">&#269;erv.</string>
    <string id="mon7Abbr">&#269;erven.</string>
    <string id="mon8Abbr">srp.</string>
    <string id="mon9Abbr">zá&#345;.</string>
    <string id="mon10Abbr">&#345;íj.</string>
    <string id="mon11Abbr">list.</string>
    <string id="mon12Abbr">pros.</string>

    <string id="mon1Name">leden</string>
    <string id="mon2Name">únor</string>
    <string id="mon3Name">b&#345;ezen</string>
    <string id="mon4Name">duben</string>
    <string id="mon5Name">kv&#283;ten</string>
    <string id="mon6Name">&#269;erven</string>
    <string id="mon7Name">&#269;ervenec</string>
    <string id="mon8Name">srpen</string>
    <string id="mon9Name">zá&#345;í</string>
    <string id="mon10Name">&#345;íjen</string>
    <string id="mon11Name">listopad</string>
    <string id="mon12Name">prosinec</string>

    <string id="amAbbr">dop.</string>
    <string id="pmAbbr">opd.</string>

    <string id="amName">dop.</string>
    <string id="pmName">opd.</string>
    </strings>
    </resources>


    Then, in your code, you'd probably have functions like this...

    var weekday_name_cache;

    function get_weekday_name(day)
    {
    // this is probably a premature optimization
    if (weekday_name_cache == null) {
    weekday_name_cache = [
    Ui.loadResource(Rez.Strings.day0Name),
    Ui.loadResource(Rez.Strings.day1Name),
    Ui.loadResource(Rez.Strings.day2Name),
    Ui.loadResource(Rez.Strings.day3Name),
    Ui.loadResource(Rez.Strings.day4Name),
    Ui.loadResource(Rez.Strings.day5Name),
    Ui.loadResource(Rez.Strings.day6Name)
    ];
    }

    return weekday_name_cache[day];
    }

    var weekday_abbr_cache;

    function get_weekday_abbr(day)
    {
    // this is probably a premature optimization
    if (weekday_abbr_cache == null) {
    weekday_abbr_cache = [
    Ui.loadResource(Rez.Strings.day0Abbr),
    Ui.loadResource(Rez.Strings.day1Abbr),
    Ui.loadResource(Rez.Strings.day2Abbr),
    Ui.loadResource(Rez.Strings.day3Abbr),
    Ui.loadResource(Rez.Strings.day4Abbr),
    Ui.loadResource(Rez.Strings.day5Abbr),
    Ui.loadResource(Rez.Strings.day6Abbr)
    ];
    }

    return weekday_abbr_cache[day];
    }

    // similar functions...
    function get_month_name(month);
    function get_month_abbr(month);

    function get_ampm_name(hour);
    function get_ampm_abbr(hour);


    Then, you'd define your font resource (e.g., resources-ces\fonts.xml) to be something like this, being sure to filter out unnecessary characters. Again, be sure to save this using a proper encoding.

    <resources>
    <fonts>
    <font id="myFont" filename="fonts/myFont.fnt" filter="áabb&#269;d&#283;eíijklnop&#345;rstúuvýz" />
    </fonts>
    </resources>


    Your actual font file (myFont.fnt in this case) would likely contain all characters you would ever need, and you'd filter them down for each language.

    I'd probably write wrapper functions to get the short/medium/long names, and then another to do all of the localization stuff for me.

    function get_weekday(day_of_week, format) {
    if (format == Time.FORMAT_MEDIUM) {
    return get_weekday_abbr(day_of_week);
    }
    else if (format == Time.FORMAT_LONG) {
    return get_weekday_name(day_of_week);
    }
    else {
    return day_of_week;
    }
    }

    // similar functions...
    function get_month(month, format);
    function get_ampm(hour, format);


    So, you should create a custom string resource for every supported language. You should create a custom font resource for every language as well, so you can minimize the size of the generated font data. You do not have to detect the language, the appropriate binary should be loaded onto the user device given their language. I don't believe there should be any problem testing this in the simulator.

    Travis