Skip to content

Commit

Permalink
use snaplet file path
Browse files Browse the repository at this point in the history
  • Loading branch information
freizl committed Dec 29, 2012
1 parent b2fbbff commit dac53a2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
12 changes: 8 additions & 4 deletions snaplet-i18n.cabal
Expand Up @@ -33,12 +33,16 @@ Library
Exposed-modules:
Snap.Snaplet.I18N

Other-modules: Paths_snaplet_i18n

Build-Depends:
base >= 4 && < 5,
snap >= 0.9.1 && < 0.10,
snap-core == 0.9.0,
xmlhtml == 0.2.0,
heist == 0.8.1,
snap == 0.9.*,
snap-core == 0.9.*,
snap-loader-dynamic == 0.9.*,
snap-loader-static == 0.9.*,
xmlhtml >= 0.2,
heist >= 0.8.1 && < 0.9,
bytestring >= 0.9 && < 1.0,
data-lens-template >= 2.1 && < 2.2,
data-lens >= 2.0 && < 2.1,
Expand Down
18 changes: 10 additions & 8 deletions src/Snap/Snaplet/I18N.hs
Expand Up @@ -16,12 +16,12 @@ import qualified Data.Configurator.Types as Config
import Data.Lens.Common
import Data.Maybe
import qualified Data.Text as T
import System.Directory
import System.FilePath.Posix
import Text.Templating.Heist
import Text.XmlHtml hiding (render)
import qualified Text.XmlHtml as X

import Paths_snaplet_i18n
import Snap
import Snap.Snaplet.Heist

Expand All @@ -39,7 +39,7 @@ defaultLocale = "en_US"
-- | ?? could be multiple message files
--
defaultMessageFilePrefix :: MessageFile
defaultMessageFilePrefix = "data/message"
defaultMessageFilePrefix = "message"

data I18NConfig = I18NConfig { _getLocale :: Locale
-- ^ locale, default "en"
Expand Down Expand Up @@ -90,13 +90,17 @@ lookupI18NValue key = do
initI18NSnaplet :: (HasHeist b, HasI18N b)
=> Maybe Locale -- ^ Locale, default to @defaultLocale@
-> SnapletInit b I18NSnaplet
initI18NSnaplet l = makeSnaplet "I18NSnaplet" "" Nothing $ do
initI18NSnaplet l = makeSnaplet "i18n" description datadir $ do
let i18nConfig = I18NConfig (fromMaybe defaultLocale l) defaultMessageFilePrefix
msg <- liftIO $ readMessageFile i18nConfig
fp <- getSnapletFilePath
msg <- liftIO $ readMessageFile fp i18nConfig
addDefaultSplices
return $ I18NSnaplet i18nConfig msg
where addDefaultSplices = addSplices [ ("i18n", liftHeist i18nSplice)
, ("i18nSpan", liftHeist i18nSpanSplice)]
-- config dir for snaplet
datadir = Just $ liftM (++ "/resources") getDataDir
description = "light weight i18n snaplet"

-------------------------------------------------------
--
Expand All @@ -105,10 +109,8 @@ initI18NSnaplet l = makeSnaplet "I18NSnaplet" "" Nothing $ do
-- server will not be able to start up if dir doesnt exists.
-- Thus, no additional validation check so far.
--
readMessageFile :: I18NConfig -> IO I18NMessage
--IO Config.Config
readMessageFile config = do
base <- getCurrentDirectory
readMessageFile :: FilePath -> I18NConfig -> IO I18NMessage
readMessageFile base config = do
let fullname = base </> file config
fmap I18NMessage (Config.load [Config.Required fullname])
where
Expand Down

0 comments on commit dac53a2

Please sign in to comment.