snaplet-i18n 0.0.4 → 0.0.5
raw patch · 10 files changed
+77/−86 lines, 10 filesdep +bytestringdep +snaplet-i18ndep ~heistdep ~snapdep ~textnew-component:exe:demoPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring, snaplet-i18n
Dependency ranges changed: heist, snap, text
API changes (from Hackage documentation)
Files
- README.md +7/−20
- example/snap.hs +3/−15
- example/snaplets/heist/templates/index.tpl +0/−25
- example/snaplets/i18n/message-en_US.cfg +0/−2
- example/snaplets/i18n/message-zh_CN.cfg +0/−2
- snaplet-i18n.cabal +29/−17
- snaplets/heist/templates/index.tpl +28/−0
- snaplets/i18n/message-en_US.cfg +2/−0
- snaplets/i18n/message-zh_CN.cfg +2/−0
- src/Snap/Snaplet/I18N.hs +6/−5
README.md view
@@ -1,34 +1,21 @@ [](http://travis-ci.org/HaskellCNOrg/snaplet-i18n) -## snaplet-i18n-- 1. create config below into `data/message_en.cfg`--~~~-hello = "Hello"-shanghai = "ShangHai"-~~~+# snaplet-i18n - 2. use tag in heist template+Snaplet for localize messages -~~~-<i18n name="shanghai"></i18n>-<i18nSpan name="shanghai"></i18n>-<i18n name="shanghai">- <a><i18nValue /></a>-</i18n>-~~~+# Samples -**see example at example dir**+ - Check usage at `snaplets/heist/templates/index.tpl`+ - Sample message files `snaplets/i18n/*.cfg` -## Snaplet+# Snaplet - [what is snaplet] [what is snaplet]: http://snapframework.com/docs/tutorials/snaplets-tutorial -## TODO+# TODO - maybe multiple locale support at run time. - use getDataDir to retrieve locale msg. [snaplet tutorial](http://snapframework.com/docs/tutorials/snaplets-tutorial)-
example/snap.hs view
@@ -7,30 +7,18 @@ module Main where -------------------------------------------------------------------------------import Control.Category import Control.Monad import Control.Exception (SomeException, try) import Data.ByteString (ByteString) import Data.Maybe import Prelude hiding ((.)) import Snap-import qualified Data.Configurator as CF-import qualified Data.Configurator.Types as CF-import Snap.Core-import Snap.Http.Server import Snap.Snaplet.Heist import Snap.Snaplet.Config-import Snap.Util.FileServe import System.IO-import qualified Data.ByteString.Char8 as BS-import qualified Data.ByteString.Lazy as LBS import qualified Data.Text as T-import qualified Data.Text.Encoding as T-import qualified Text.XmlHtml as X-import Heist import qualified Heist.Interpreted as I-import Control.Lens-import Text.XmlHtml hiding (render)+import Control.Lens hiding (value) import Snap.Snaplet.I18N @@ -65,7 +53,7 @@ testSplice :: I.Splice AppHandler testSplice = do locale <- liftIO $ getDefaultLocale- --liftIO $ print locale+ liftIO $ print locale I.textSplice $ T.pack "test" index :: AppHandler ()@@ -87,7 +75,7 @@ app :: SnapletInit App App app = makeSnaplet "app" "An snaplet example application." Nothing $ do h <- nestSnaplet "heist" heist $ heistInit "templates"- locale <- liftIO $ getDefaultLocale+ --locale <- liftIO $ getDefaultLocale i <- nestSnaplet "i18n" i18n $ initI18N (Just "zh_CN") addRoutes routes return $ App h i
− example/snaplets/heist/templates/index.tpl
@@ -1,25 +0,0 @@-<!DOCTYPE html> -<html>- <head>- </head>- - <body>- - <h2>Test I18N</h2>- - <label><testSplice /></label>- - <label><i18n name="shanghai"></i18n></label>- <p>- <i18nSpan name="hello" class="test"></i18nSpan>- </p>- <p><i18n name="invalidekey"></i18n></p>- - <p>- <i18n name="shanghai">- <input type="submit" value="${i18nValue}" />- </i18n>- </p>- - </body>-</html>
− example/snaplets/i18n/message-en_US.cfg
@@ -1,2 +0,0 @@-hello = "Hello"-shanghai = "ShangHai"
− example/snaplets/i18n/message-zh_CN.cfg
@@ -1,2 +0,0 @@-hello = "你好"-shanghai = "上海"
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.4+Version: 0.0.5 Description: A light weight i18n snaplet. Synopsis: snaplet-i18n Homepage: https://github.com/HaskellCNOrg/snaplet-i18n@@ -15,13 +15,13 @@ Category: Web Build-type: Simple Stability: Experience-Cabal-version: >=1.6+Cabal-version: >=1.10 Extra-source-files: README.md example/snap.hs- example/snaplets/heist/templates/*.tpl- example/snaplets/i18n/*.cfg+ snaplets/heist/templates/*.tpl+ snaplets/i18n/*.cfg Source-Repository head Type: git@@ -30,6 +30,7 @@ Library Hs-Source-Dirs: src+ default-language: Haskell2010 Exposed-modules: Snap.Snaplet.I18N @@ -39,11 +40,11 @@ base >= 4 && < 5, configurator >= 0.2 && < 0.3, filepath >= 1.2 && < 1.4,- heist >= 0.10 && < 0.11,+ heist >= 0.10 && < 0.14, lens >= 3.7.0.1 && < 3.8,- snap >= 0.10 && < 0.11,+ snap >= 0.10 && < 0.14, snap-loader-static >= 0.9 && < 0.11,- text >= 0.11 && < 0.12,+ text >= 0.11 && < 1.2, xmlhtml >= 0.2 if impl(ghc >= 6.12.0)@@ -52,17 +53,28 @@ else ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -fno-warn-orphans - - -- Modules not exported by this package.- -- Other-modules: - - -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.- -- Build-tools: - ---+Executable demo+ Hs-Source-Dirs: example+ default-language: Haskell2010+ main-is: snap.hs + Build-Depends: + base >= 4 && < 5,+ configurator >= 0.2 && < 0.3,+ filepath >= 1.2 && < 1.4,+ heist >= 0.10 && < 0.14,+ lens >= 3.7.0.1 && < 3.8,+ snap >= 0.10 && < 0.14,+ snap-loader-static >= 0.9 && < 0.11,+ text >= 0.11 && < 1.2,+ xmlhtml >= 0.2, + bytestring >= 0.9 && < 1.0,+ snaplet-i18n + if impl(ghc >= 6.12.0)+ ghc-options: -Wall -fwarn-tabs -funbox-strict-fields+ -fno-warn-unused-do-bind+ else+ ghc-options: -Wall -fwarn-tabs -funbox-strict-fields
+ snaplets/heist/templates/index.tpl view
@@ -0,0 +1,28 @@+<!DOCTYPE html>+<html>+ <head>+ <title>Snaplet-i18n example</title>+ </head>++ <body>++ <h2>Test I18N</h2>++ <label><testSplice /></label>++ <label><i18n name="shanghai"></i18n></label>++ <p>+ <i18nSpan name="hello" class="test"></i18nSpan>+ </p>++ <p><i18n name="invalidekey"></i18n></p>++ <p>+ <i18n name="shanghai">+ <input type="submit" value="${i18nValue}" />+ </i18n>+ </p>++ </body>+</html>
+ snaplets/i18n/message-en_US.cfg view
@@ -0,0 +1,2 @@+hello = "Hello"+shanghai = "ShangHai"
+ snaplets/i18n/message-zh_CN.cfg view
@@ -0,0 +1,2 @@+hello = "你好"+shanghai = "上海"
src/Snap/Snaplet/I18N.hs view
@@ -93,11 +93,12 @@ let i18nConfig = I18NConfig (fromMaybe defaultLocale l) defaultMessageFilePrefix fp <- getSnapletFilePath msg <- liftIO $ readMessageFile fp i18nConfig- addDefaultSplices+ modifyHeistState addDefaultSplices return $ I18N i18nConfig msg- where addDefaultSplices = addSplices [ ("i18n", i18nSplice)- , ("i18nSpan", i18nSpanSplice)- ]+ where addDefaultSplices = I.bindSplices splices+ splices = do+ "i18n" ## i18nSplice+ "i18nSpan" ## i18nSpanSplice -- config dir for current snaplet datadir = Just $ liftM (++ "/resources") getDataDir description = "light weight i18n snaplet"@@ -142,7 +143,7 @@ value <- lift . lookupI18NValue $ getNameAttr input case childElements input of [] -> return [X.TextNode value]- _ -> I.runChildrenWithText [("i18nValue", value)]+ _ -> I.runChildrenWithText ("i18nValue" ## value) -- | Splices. use 'span' html element wrap result. --