haskell-gettext 0.1.1.0 → 0.1.2.0
raw patch · 4 files changed
+25/−15 lines, 4 filesdep −bytestring-triesetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies removed: bytestring-trie
API changes (from Hackage documentation)
+ Data.Gettext: context :: Catalog -> ByteString -> Catalog
Files
- Data/Gettext.hs +24/−9
- Setup.hs +0/−2
- examples/gmodump.hs +0/−2
- haskell-gettext.cabal +1/−2
Data/Gettext.hs view
@@ -34,6 +34,7 @@ gettext, cgettext, ngettext, cngettext, ngettext',+ context, assocs, -- * Utilities for plural forms getHeaders,@@ -51,7 +52,7 @@ import qualified Data.ByteString.Lazy as L import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy.Encoding as TLE-import qualified Data.Trie as Trie+import qualified Data.Map as M import Text.Printf import Data.Gettext.GmoFile@@ -62,7 +63,7 @@ data Catalog = Catalog { gmoSize :: Word32, gmoChoosePlural :: Int -> Int,- gmoData :: Trie.Trie [T.Text] }+ gmoData :: M.Map B.ByteString [T.Text] } instance Show Catalog where show gmo = printf "<GetText data size=%d>" (gmoSize gmo)@@ -76,20 +77,20 @@ -- | Look up for string translation lookup :: B.ByteString -> Catalog -> Maybe [T.Text]-lookup key gmo = Trie.lookup key (gmoData gmo)+lookup key gmo = M.lookup key (gmoData gmo) -- | Get all translation pairs assocs :: Catalog -> [(B.ByteString, [T.Text])]-assocs = Trie.toList . gmoData+assocs = M.assocs . gmoData -- | Obtain headers of the catalog. -- Headers are defined as a translation for empty string. getHeaders :: Catalog -> Maybe Headers getHeaders gmo = getHeaders' (gmoData gmo) -getHeaders' :: Trie.Trie [T.Text] -> Maybe Headers+getHeaders' :: M.Map B.ByteString [T.Text] -> Maybe Headers getHeaders' trie =- case Trie.lookup "" trie of+ case M.lookup "" trie of Nothing -> Nothing Just texts -> either error Just $ parseHeaders (head texts) @@ -97,7 +98,7 @@ getPluralDefinition :: Catalog -> Maybe (Int, Expr) getPluralDefinition gmo = getPluralDefinition' (gmoData gmo) -getPluralDefinition' :: Trie.Trie [T.Text] -> Maybe (Int, Expr)+getPluralDefinition' :: M.Map B.ByteString [T.Text] -> Maybe (Int, Expr) getPluralDefinition' trie = case getHeaders' trie of Nothing -> Nothing@@ -159,11 +160,25 @@ else plural in texts !! idx +-- | Get sub-catalog for specific context+context :: Catalog+ -> B.ByteString -- ^ Context+ -> Catalog+context gmo ctxt =+ let n = B.length ctxt + 1+ prefix = ctxt `B.append` "\4"+ trie =+ M.fromList [(B.drop n key, value) | (key, value) <- M.assocs (gmoData gmo), prefix `B.isPrefixOf` key]+ in Catalog {+ gmoSize = fromIntegral (M.size trie),+ gmoChoosePlural = gmoChoosePlural gmo,+ gmoData = trie }+ -- | Choose plural form index by number choosePluralForm :: Catalog -> Int -> Int choosePluralForm gmo = gmoChoosePlural gmo -choosePluralForm' :: Trie.Trie [T.Text] -> Int -> Int+choosePluralForm' :: M.Map B.ByteString [T.Text] -> Int -> Int choosePluralForm' trie n = case getPluralDefinition' trie of Nothing -> if n == 1 then 0 else 1 -- from GNU gettext implementation, known as 'germanic plural form'@@ -186,5 +201,5 @@ originals = map L.toStrict $ map getOrig fOriginals translations = map getTrans fTranslations - trie = Trie.fromList $ zip originals translations+ trie = M.fromList $ zip originals translations
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
examples/gmodump.hs view
@@ -2,9 +2,7 @@ import Data.Gettext import Control.Monad-import qualified Data.Trie as T import qualified Data.ByteString.Char8 as B8-import qualified Data.ByteString.Lazy.Char8 as L8 import qualified Data.Text.Lazy.IO as TLIO import System.Environment
haskell-gettext.cabal view
@@ -1,5 +1,5 @@ name: haskell-gettext-version: 0.1.1.0+version: 0.1.2.0 synopsis: GetText runtime library implementation in pure Haskell description: This package is pure Haskell implementation of GetText library runtime. It allows you to:@@ -48,7 +48,6 @@ binary >=0.7, bytestring >=0.10, text >= 1.2,- bytestring-trie >=0.2, containers >=0.5, time >=1.4, mtl >= 2.2.1,