-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | GetText runtime library implementation in pure Haskell -- -- This package is pure Haskell implementation of GetText library -- runtime. It allows you to: -- -- -- -- Support for plural form selection expressions is fully implemented. -- -- This package is however relatively low-level and may be not very nice -- to use in applications. So it can be used as a backend for some more -- user-friendly "translation framework". -- -- This package has the following advantages comparing to hgettext: -- -- @package haskell-gettext @version 0.1.2.0 module Data.Gettext.GmoFile -- | This structure describes the binary structure of Gettext -- .mo/.gmo file. data GmoFile GmoFile :: Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> [(Word32, Word32)] -> [(Word32, Word32)] -> ByteString -> GmoFile -- | Magic number (must be 0x950412de or 0xde120495) [fMagic] :: GmoFile -> Word32 -- | File revision [fRevision] :: GmoFile -> Word32 -- | Number of text pairs in the file [fSize] :: GmoFile -> Word32 -- | Offset of original strings [fOriginalOffset] :: GmoFile -> Word32 -- | Offset of translations [fTranslationOffset] :: GmoFile -> Word32 -- | Size of hash table [fHashtableSize] :: GmoFile -> Word32 -- | Offset of hash table [fHashtableOffset] :: GmoFile -> Word32 -- | Original strings - sizes and offsets [fOriginals] :: GmoFile -> [(Word32, Word32)] -- | Translations - sizes and offsets [fTranslations] :: GmoFile -> [(Word32, Word32)] -- | All file data - used to access strings by offsets [fData] :: GmoFile -> ByteString -- | Data.Binary parser for GmoFile structure parseGmo :: Get GmoFile instance GHC.Classes.Eq Data.Gettext.GmoFile.GmoFile instance GHC.Show.Show Data.Gettext.GmoFile.GmoFile -- | This module contains definitions for plural form selection expressions -- AST, and an evaluator function for such expressions. module Data.Gettext.Plural -- | Supported binary operations data BinOp Equals :: BinOp NotEquals :: BinOp Greater :: BinOp NotGreater :: BinOp Less :: BinOp NotLess :: BinOp And :: BinOp Or :: BinOp Xor :: BinOp Mod :: BinOp Plus :: BinOp Minus :: BinOp Multiply :: BinOp Divide :: BinOp -- | Plural form selection expression AST data Expr -- | The n variable N :: Expr -- | Literal number Literal :: Int -> Expr -- | Ternary operator (... ? ... : ...) If :: Expr -> Expr -> Expr -> Expr -- | Unary arithmetic negation (as in -1). Negate :: Expr -> Expr -- | Unary logic negation (as in ! (n == 1)) Not :: Expr -> Expr -- | Binary operation Binary :: BinOp -> Expr -> Expr -> Expr -- | Evaluate the expression eval :: Expr -> Int -> Int instance GHC.Show.Show Data.Gettext.Plural.Expr instance GHC.Classes.Eq Data.Gettext.Plural.Expr instance GHC.Show.Show Data.Gettext.Plural.BinOp instance GHC.Classes.Eq Data.Gettext.Plural.BinOp -- | This module contains parsers for: -- -- -- -- These parsers are already used by main module; but they can be useful -- for other libraries working with gettext's files. module Data.Gettext.Parsers -- | Catalog header, i.e. one Name: Value line in po file type Header = (Text, Text) -- | List of catalog headers type Headers = [Header] -- | Parse catalog headers. NB: for now this function does not use Parsec. parseHeaders :: Text -> Either String Headers -- | Parse plural form selection definition. Return value is (number of -- possible plural forms; selection expression). parsePlural :: Headers -> Either String (Int, Expr) -- | Parsec parser for catalog headers pHeaders :: Parser Headers -- | Parse plural form selection expression. Note: this parses only part -- which goes after plural=. pExpr :: Parser Expr -- | Parse plural form selection definition. This parses the whole value of -- Plural-Forms header, starting from nplurals=. pPlural :: Parser (Int, Expr) -- | This is the main module of haskell-gettext package. For most -- cases, it is enough to import only this module. Other modules of the -- package might be useful for other libraries working with gettext's -- files. -- -- Simple example of usage of this module is: -- --
--   {-# LANGUAGE OverloadedStrings #-}
--   module Main where
--   
--   import qualified Data.Text.Lazy as T
--   import qualified Text.Lazy.IO as TLIO
--   import Text.Printf
--   
--   import Data.Gettext
--   
--   main :: IO ()
--   main = do
--     catalog <- loadCatalog "locale/ru/messages.mo"
--     TLIO.putStrLn $ gettext catalog "Simple translated message"
--     let n = 78
--     let template = ngettext catalog "There is %d file" "There are %d files" n
--     printf (T.unpack template) n
--   
module Data.Gettext -- | This structure describes data in Gettext's .mo/.gmo file in -- ready-to-use format. data Catalog -- | Load gettext file loadCatalog :: FilePath -> IO Catalog -- | Look up for string translation lookup :: ByteString -> Catalog -> Maybe [Text] -- | Translate a string. Original message must be defined in po -- file in msgid line. gettext :: Catalog -> ByteString -> Text -- | Translate a string within specific context. cgettext :: Catalog -> ByteString -> ByteString -> Text -- | Translate a string and select correct plural form. Original single -- form must be defined in po file in msgid line. -- Original plural form must be defined in po file in -- msgid_plural line. ngettext :: Catalog -> ByteString -> ByteString -> Int -> Text -- | Translate a string and select correct plural form, within specific -- context Original single form must be defined in po file in -- msgid line. Original plural form must be defined in -- po file in msgid_plural line. cngettext :: Catalog -> ByteString -> ByteString -> ByteString -> Int -> Text -- | Variant of ngettext for case when for some reason there is -- only msgid defined in po file, and no -- msgid_plural, but there are some msgstr[n]. ngettext' :: Catalog -> ByteString -> Int -> Text -- | Get sub-catalog for specific context context :: Catalog -> ByteString -> Catalog -- | Get all translation pairs assocs :: Catalog -> [(ByteString, [Text])] -- | Obtain headers of the catalog. Headers are defined as a translation -- for empty string. getHeaders :: Catalog -> Maybe Headers -- | Get plural forms selection definition. getPluralDefinition :: Catalog -> Maybe (Int, Expr) -- | Choose plural form index by number choosePluralForm :: Catalog -> Int -> Int -- | Data.Binary parser for GmoFile structure parseGmo :: Get GmoFile -- | Prepare the data parsed from file for lookups. unpackGmoFile :: GmoFile -> Catalog instance GHC.Show.Show Data.Gettext.Catalog