summaryrefslogtreecommitdiffhomepage
path: root/src/Localize.hsc
diff options
context:
space:
mode:
authorMartin Perner <martin@perner.cc>2011-10-27 20:51:19 +0200
committerMartin Perner <martin@perner.cc>2011-10-27 22:46:28 +0200
commitf6bb8eb4c4350522367f4ab2dacbfeb0a99cd06d (patch)
tree304e4ca8230f78cb659dff9a4aeadd1f65242e85 /src/Localize.hsc
parent9718dabe6c6d5979e3f6837ef04a39d3ad8c786c (diff)
downloadxmobar-f6bb8eb4c4350522367f4ab2dacbfeb0a99cd06d.tar.gz
xmobar-f6bb8eb4c4350522367f4ab2dacbfeb0a99cd06d.tar.bz2
DateZone, Date*L Plugin merges; DateZone API-Change!
To support multiple locales, an lock was introduced. Although through this, supporting DateL and DateZoneL would be cumbersome. To simplify the usage, DateZone was replaced with DateZoneL. Additionally the position of the Alias parameter was changed. Using "" as Zone parameter for DateZoneL simulates DateL. Providing also "" for locale simulates Date.
Diffstat (limited to 'src/Localize.hsc')
-rw-r--r--src/Localize.hsc83
1 files changed, 35 insertions, 48 deletions
diff --git a/src/Localize.hsc b/src/Localize.hsc
index bfaa6f0..b302cd4 100644
--- a/src/Localize.hsc
+++ b/src/Localize.hsc
@@ -18,7 +18,6 @@ module Localize
getTimeLocale
) where
-import Foreign
import Foreign.C
import qualified System.Locale as L
@@ -36,27 +35,21 @@ foreign import ccall unsafe "langinfo.h nl_langinfo"
#{enum NlItem,
, AM_STR , PM_STR \
, D_T_FMT , D_FMT , T_FMT , T_FMT_AMPM \
- , ABDAY_1 , ABDAY_2 , ABDAY_3 , ABDAY_4 , ABDAY_5 , ABDAY_6 , ABDAY_7 \
- , DAY_1 , DAY_2 , DAY_3 , DAY_4 , DAY_5 , DAY_6 , DAY_7 \
- , ABMON_1 , ABMON_2 , ABMON_3 , ABMON_4 , ABMON_5 , ABMON_6 , ABMON_7 \
- , ABMON_8 , ABMON_9 , ABMON_10 , ABMON_11 , ABMON_12 \
- , MON_1 , MON_2 , MON_3 , MON_4 , MON_5 , MON_6 , MON_7 , MON_8 , MON_9 \
- , MON_10 , MON_11 , MON_12\
+ , ABDAY_1, ABDAY_7 \
+ , DAY_1, DAY_7 \
+ , ABMON_1, ABMON_12 \
+ , MON_1, MON_12\
}
-#let LIST_CTR fst,snd,idx = "( getLangInfo "fst""idx" , getLangInfo "snd""idx" )"
-
-getLangInfo :: NlItem -> String
+getLangInfo :: NlItem -> IO String
+getLangInfo item = do
+ itemStr <- nl_langinfo item
#ifdef UTF8
-getLangInfo item = decodeString $ unsafePerformIO $ getLangInfo' item
+ str <- peekCString itemStr
+ return $ decodeString str
#else
-getLangInfo item = unsafePerformIO $ getLangInfo' item
-#endif
-
-getLangInfo' :: NlItem -> IO String
-getLangInfo' item = do
- itemStr <- nl_langinfo item
peekCString itemStr
+#endif
#include <locale.h>
foreign import ccall unsafe "locale.h setlocale"
@@ -65,34 +58,28 @@ foreign import ccall unsafe "locale.h setlocale"
setupTimeLocale :: String -> IO ()
setupTimeLocale l = withCString l (setlocale #const LC_TIME) >> return ()
-getTimeLocale :: L.TimeLocale
-getTimeLocale = L.TimeLocale {
- L.wDays = [ #{LIST_CTR "day","abday","1"}
- , #{LIST_CTR "day","abday","2"}
- , #{LIST_CTR "day","abday","3"}
- , #{LIST_CTR "day","abday","4"}
- , #{LIST_CTR "day","abday","5"}
- , #{LIST_CTR "day","abday","6"}
- , #{LIST_CTR "day","abday","7"}
- ],
- L.months = [ #{LIST_CTR "mon","abmon","1"}
- , #{LIST_CTR "mon","abmon","2"}
- , #{LIST_CTR "mon","abmon","3"}
- , #{LIST_CTR "mon","abmon","4"}
- , #{LIST_CTR "mon","abmon","5"}
- , #{LIST_CTR "mon","abmon","6"}
- , #{LIST_CTR "mon","abmon","7"}
- , #{LIST_CTR "mon","abmon","8"}
- , #{LIST_CTR "mon","abmon","9"}
- , #{LIST_CTR "mon","abmon","10"}
- , #{LIST_CTR "mon","abmon","11"}
- , #{LIST_CTR "mon","abmon","12"}
- ],
- -- Intervals are not available from this interface
- L.intervals = L.intervals L.defaultTimeLocale,
- L.amPm = (getLangInfo amStr, getLangInfo pmStr),
- L.dateTimeFmt = getLangInfo dTFmt,
- L.dateFmt = getLangInfo dFmt,
- L.timeFmt = getLangInfo tFmt,
- L.time12Fmt = getLangInfo tFmtAmpm
- }
+getTimeLocale :: IO L.TimeLocale
+getTimeLocale = do
+ -- assumes that the defined values are increasing by exactly one.
+ -- as they are defined consecutive in an enum this is reasonable
+ days <- mapM getLangInfo [day1 .. day7]
+ abdays <- mapM getLangInfo [abday1 .. abday7]
+
+ mons <- mapM getLangInfo [mon1 .. mon12]
+ abmons <- mapM getLangInfo [abmon1 .. abmon12]
+
+ amstr <- getLangInfo amStr
+ pmstr <- getLangInfo pmStr
+ dtfmt <- getLangInfo dTFmt
+ dfmt <- getLangInfo dFmt
+ tfmt <- getLangInfo tFmt
+ tfmta <- getLangInfo tFmtAmpm
+
+ let t = L.defaultTimeLocale {L.wDays = zip days abdays
+ ,L.months = zip mons abmons
+ ,L.amPm = (amstr, pmstr)
+ ,L.dateTimeFmt = dtfmt
+ ,L.dateFmt = dfmt
+ ,L.timeFmt = tfmt
+ ,L.time12Fmt = tfmta}
+ return t