snaplet-i18n 0.0.2 → 0.0.2.1
raw patch · 4 files changed
+30/−8 lines, 4 files
Files
- README.md +10/−0
- snaplet-i18n.cabal +1/−1
- src/Snap/Snaplet/I18N.hs +13/−7
- test/snaplets/heist/templates/index.tpl +6/−0
README.md view
@@ -1,3 +1,6 @@++[](http://travis-ci.org/HaskellCNOrg/snaplet-i18n)+ ## snaplet-i18n 1. create config below into `data/message_en.cfg`@@ -20,3 +23,10 @@ - [what is snaplet] [what is snaplet]: http://snapframework.com/docs/tutorials/snaplets-tutorial++## TODO++- maybe multiple locale support at run time.+- build failed at Hakcage+ - because heist does not specify version of `transformers`, which will conflick with `transformer` of `mtl`+ - Upgrade heist would be fine.
snaplet-i18n.cabal view
@@ -3,7 +3,7 @@ -- 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.2+Version: 0.0.2.1 Description: A light weight i18n snaplet. Synopsis: snaplet-i18n Homepage: https://github.com/HaskellCNOrg/snaplet-i18n
src/Snap/Snaplet/I18N.hs view
@@ -113,14 +113,26 @@ ------------------------------------------------------- ++-- | element attribute used for looking up i18n value.+-- e.g. <i18n name="hello" />+-- +i18nSpliceAttr :: T.Text+i18nSpliceAttr = "name"++ -- | Splices just wrap value fonud at l10n message.+-- When it is used for wrap around other elements, a.k.a children is not empty,+-- binding `i18nValue`. -- -- FIXME: Turns out that it is not possible to fail at compilation if value is Nothing but runtime. i18nSplice :: HasI18N b => Splice (Handler b b) i18nSplice = do input <- getParamNode value <- lift . lookupI18NValue $ getNameAttr input- return [X.TextNode value]+ case childElements input of+ [] -> return [X.TextNode value]+ _ -> runChildrenWithText [("i18nValue", value)] -- | Splices. use 'span' html element wrap result. -- @@ -129,12 +141,6 @@ input <- getParamNode value <- lift . lookupI18NValue $ getNameAttr input return [X.Element "span" (elementAttrs input) [X.TextNode value]]---- | element attribute used for looking up i18n value.--- e.g. <i18n name="hello" />--- -i18nSpliceAttr :: T.Text-i18nSpliceAttr = "name" -- | Look up 'name' attribute value. --
test/snaplets/heist/templates/index.tpl view
@@ -20,5 +20,11 @@ <i18n name="invalidekey"></i18n> </p> + <p>+ <i18n name="shanghai">+ <input type="submit" value="${i18nValue}" />+ </i18n>+</p>+ </body> </html>