Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bump 0.0.2; simplified public api.

  • Loading branch information...
commit 7cd26aa68a0269b6dc3bbbb9ad6482fed90034b8 1 parent bfabe80
@freizl freizl authored
Showing with 18 additions and 13 deletions.
  1. +2 −3 snaplet-i18n.cabal
  2. +15 −9 src/Snap/Snaplet/I18N.hs
  3. +1 −1  test/snap.hs
View
5 snaplet-i18n.cabal
@@ -3,10 +3,10 @@
-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
-- The name of the package.
Name: snaplet-i18n
-Version: 0.0.1
+Version: 0.0.2
Description: A light weight i18n snaplet.
Synopsis: snaplet-i18n
-Homepage: freizl.github.com
+Homepage: https://github.com/HaskellCNOrg/snaplet-i18n
License: BSD3
License-file: LICENSE
Author: Haisheng,Wu
@@ -17,7 +17,6 @@ Build-type: Simple
Stability: Experience
Cabal-version: >=1.6
-
Extra-source-files:
README.md
test/snap.hs
View
24 src/Snap/Snaplet/I18N.hs
@@ -5,9 +5,9 @@
module Snap.Snaplet.I18N
( I18NSnaplet
, HasI18N (..)
+ , I18NMessage (..)
, initI18NSnaplet
, getI18NMessages
- , I18NMessage (..)
, lookupI18NValue
) where
@@ -69,24 +69,32 @@ class HasI18N b where
getI18NSnaplet :: HasI18N b => Handler b b I18NSnaplet
getI18NSnaplet = with i18nLens Snap.get
+-- | Get the @I18NMessage@
+--
getI18NMessages :: HasI18N b => Handler b b I18NMessage
getI18NMessages = liftM _getI18NMessage getI18NSnaplet
+-- | Look up a value in, usuallly Handler Monad
+--
+lookupI18NValue :: HasI18N b => T.Text -> Handler b b T.Text
+lookupI18NValue key = do
+ (I18NMessage msg) <- getI18NMessages
+ liftIO $ Config.lookupDefault "Error: no value found." msg key
+
-------------------------------------------------------
-- | Init this I18NSnaplet snaplet.
--
initI18NSnaplet :: (HasHeist b, HasI18N b)
=> Maybe Locale -- ^ Locale, default to @defaultLocale@
- -> Maybe MessageFile -- ^ Message file prefix, default to @defaultMessageFilePrefix@
-> SnapletInit b I18NSnaplet
-initI18NSnaplet l m = makeSnaplet "I18NSnaplet" "" Nothing $ do
- i18nConfig <- return $ I18NConfig (fromMaybe defaultLocale l) (fromMaybe defaultMessageFilePrefix m)
+initI18NSnaplet l = makeSnaplet "I18NSnaplet" "" Nothing $ do
+ i18nConfig <- return $ I18NConfig (fromMaybe defaultLocale l) defaultMessageFilePrefix
config <- liftIO $ readMessageFile i18nConfig
- defaultSplices
+ addDefaultSplices
return $ I18NSnaplet i18nConfig $ I18NMessage config
- where defaultSplices = addSplices [ ("i18n", liftHeist i18nSplice)
- , ("i18nSpan", liftHeist i18nSpanSplice)]
+ where addDefaultSplices = addSplices [ ("i18n", liftHeist i18nSplice)
+ , ("i18nSpan", liftHeist i18nSpanSplice)]
-------------------------------------------------------
--
@@ -140,5 +148,3 @@ lookupI18NValue' m input = Config.lookupDefault "Error: no value found." m (getA
where getAttr' i = case getAttribute i18nSpliceAttr i of
Just x -> x
_ -> ""
-lookupI18NValue :: Config.Config -> T.Text -> IO T.Text
-lookupI18NValue = Config.lookupDefault "Error: no value found."
View
2  test/snap.hs
@@ -91,7 +91,7 @@ app :: SnapletInit App App
app = makeSnaplet "app" "An snaplet example application." Nothing $ do
h <- nestSnaplet "heist" heist $ heistInit "templates"
locale <- liftIO $ getDefaultLocale
- i <- nestSnaplet "i18n" i18n $ initI18NSnaplet (Just "zh_CN") Nothing
+ i <- nestSnaplet "i18n" i18n $ initI18NSnaplet (Just "zh_CN")
addRoutes routes
return $ App h i
Please sign in to comment.
Something went wrong with that request. Please try again.