| Portability | portable |
|---|---|
| Stability | experimental |
| Maintainer | eugene.grigoriev@gmail.com |
Text.I18n.Po
Description
Internationalization support for Haskell based on GNU gettext (http://www.gnu.org/software/gettext). This module contains PO parser. PO files are assumed to be in UTF-8 encoding.
Plural forms are not yet implemented.
Text.I18n and Control.Monad.Trans are exported for convenience.
Use System.IO.UTF8 whenever you need to output a localized string.
- newtype Msgid = Msgid String
- type Msgstr = String
- data L10nMode
- newtype Locale = Locale String
- type Context = String
- type I18n a = ReaderT (Locale, L10n, L10nMode, Maybe Context) IO a
- type L10n = Map Locale (Map (Maybe Context) (Map Msgid [Msgstr]))
- getL10n :: FilePath -> IO (L10n, [ParseError])
- localize :: L10n -> Locale -> I18n a -> IO a
- gettext :: PrintfType a => String -> I18n a
- withContext :: Maybe Context -> I18n a -> I18n a
- withLocale :: Locale -> I18n a -> I18n a
- localize' :: L10n -> L10nMode -> Locale -> I18n a -> IO a
- module Control.Monad.Trans
Type Declarations
type I18n a = ReaderT (Locale, L10n, L10nMode, Maybe Context) IO aSource
The Internationalization monad allows the use of IO through liftIO.
PO parsing
Arguments
| :: FilePath | Directory containing PO files. |
| -> IO (L10n, [ParseError]) | Localization structure and a list of parse errors. |
I18n Monad Functions
Arguments
| :: L10n | Structure containing localization data |
| -> Locale | Locale to use |
| -> I18n a | Inernationalized action |
| -> IO a | Localized action |
The top level localization function.
import Text.I18n.Po import qualified System.IO.UTF8 as Utf8 main = do (l10n,errors) <- getL10n "dir/to/po" localize l10n (Locale "en") impl
gettext :: PrintfType a => String -> I18n aSource
The heart of I18n monad. Based on Text.Printf.printf.
impl = do
hello <- gettext "Hello, %s!"
liftIO (Utf8.putStrLn (hello "Joe"))
Arguments
| :: Maybe Context | Context to use |
| -> I18n a | Internationalized action |
| -> I18n a | New internationalized action |
Sets a local Context for an internationalized action.
If there is no translation, then no context version is tried.
impl2 = withContext (Just "test") impl
Arguments
| :: Locale | Locale to use |
| -> I18n a | Internationalized action |
| -> I18n a | New internationalized action. Note: while this action is localy localized already, it is to be a part of another internationalized action. Therefore the final type is internationalized. |
Sets a local Locale for an internationalized action.
impl3 = withLocale (Locale "ru") impl2
Arguments
| :: L10n | Structure containing localization data |
| -> L10nMode | Localization mode |
| -> Locale | Locale to use |
| -> I18n a | Inernationalized action |
| -> IO a | Localized action |
The top level localization function with a mode parameter.
main2 = localize' (Text.I18n.Po.getL10n "dir/to/po")
L10nMust
(Locale "en")
impl
module Control.Monad.Trans