Featured post
swing - non standard locale with java.util.Calendar -
we have customer in sweden, using software in english. set locale(en, sv)
. did hope calendar class adhere country settings, uses language , locale assumes settings.
so searching way let calendar know new firstdayofweek
, minimumdayinfirstweek
settings prefered standard way other setting manually , hardcoded.
for clarification: 29. august 2010 in sweden in cw 34 (also in germany , great britain) in reported cw 36. different results fact 01.01.2010 friday , 29.08.2010 sunday.
i cannot change language setting swedish , use english fallback since not support swedish language, sun/oracle/.. does, swing ui have mixture of swedish , english texts, not acceptable.
and adding properties file named "sun.util.resources.calendardata_en_sv.properties" not work out: not read! manually resourcebundle that's possible. somehow localedata.getcalendardata(locale) own magic in reading resourcfiles cannot find out since source of not available. method called here: java.util.calendar.setweekcountdata(locale)
.
i found java.util.spi package not provide access firstdayofweek , minimumdaysinfirstweek settings.
perhaps can try intercept calls resourcebundles , use default fallback english , let calls calendardata proceed!? sounds hacky.
for clueless ...
thx help!
ciao,
nils drews
package de.drews.i18n; import java.util.calendar; import java.util.locale; import java.util.resourcebundle; public class test { /** * @param args */ public static void main(string[] args) { // en_gb = 34 // en_us = 36 // sv_sv = 34 // en_sv = 36 --> wrong printtest("en", "gb", 34); printtest("en", "us", 36); printtest("sv", "sv", 34); printtest("en", "sv", 34); } private static void printtest(string language, string country, int expected) { locale locale = new locale(language, country); calendar cal = calendar.getinstance(locale); cal.set(calendar.year, 2010); cal.set(calendar.month, calendar.august); cal.set(calendar.date, 29); int actual = cal.get(calendar.week_of_year); system.out.println(actual + "\t" + expected + "\t" + ((actual == expected) ? "yeah!" : "-") + "\t" + language + "\t" + country); } }
how using getinstance(timezone zone, locale alocale)
providing timezone select calendar behaviour , locale define language?
- Get link
- X
- Other Apps
Comments
Post a Comment