Permalink
Browse files

allow wrap other elements

  • Loading branch information...
freizl committed May 19, 2012
1 parent a7c6c3d commit a8745e27f6c743474676c9474312c5ba7c51bc00
Showing with 20 additions and 7 deletions.
  1. +1 −0 README.md
  2. +13 −7 src/Snap/Snaplet/I18N.hs
  3. +6 −0 test/snaplets/heist/templates/index.tpl
View
@@ -1,4 +1,5 @@
+[![Build Status](https://secure.travis-ci.org/HaskellCNOrg/snaplet-i18n.png?branch=master)](http://travis-ci.org/HaskellCNOrg/snaplet-i18n)
## snaplet-i18n
View
@@ -113,14 +113,26 @@ readMessageFile config = do
-------------------------------------------------------
+
+-- | 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.
--
@@ -130,12 +142,6 @@ i18nSpanSplice = do
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.
--
getNameAttr :: Node -> T.Text
@@ -20,5 +20,11 @@
<i18n name="invalidekey"></i18n>
</p>
+ <p>
+ <i18n name="shanghai">
+ <input type="submit" value="${i18nValue}" />
+ </i18n>
+</p>
+
</body>
</html>

0 comments on commit a8745e2

Please sign in to comment.