| Portability | portable |
|---|---|
| Stability | experimental |
| Maintainer | eugene.grigoriev@gmail.com |
Text.I18n
Description
Internationalization support for Haskell. Use Text.I18n.Po module.
Plural forms are not yet implemented.
- newtype Msgid = Msgid String
- type Msgstr = String
- newtype Locale = Locale String
- type Context = String
- type I18n a = ReaderT (Locale, L10n, Maybe Context) Identity a
- type L10n = Map Locale (Map (Maybe Context) (Map Msgid [Msgstr]))
- gettext :: PrintfType a => String -> I18n a
- localize :: L10n -> Locale -> I18n a -> a
- withContext :: Maybe Context -> I18n a -> I18n a
- withLocale :: Locale -> I18n a -> I18n a
Type Declarations
type I18n a = ReaderT (Locale, L10n, Maybe Context) Identity aSource
The Internationalization monad built using monad transformers.
Internationalization Monad Functions
gettext :: PrintfType a => String -> I18n aSource
The heart of I18n monad. Based on Text.Printf.printf.
example :: String -> I18n String
example name = do
hello <- gettext "Hello, %s!"
return (hello name)
Arguments
| :: L10n | Structure containing localization data |
| -> Locale | Locale to use |
| -> I18n a | Inernationalized expression |
| -> a | Localized expression |
The top level localization function.
import Text.I18n.Po
import Prelude hiding (putStr,putStrLn)
main = do
(l10n,errors) <- getL10n "dir/to/po" -- directory containing PO files
putStrLn $ localize l10n (Locale "en") (example "Joe")
Arguments
| :: Maybe Context | Context to use |
| -> I18n a | Internationalized expression |
| -> I18n a | New internationalized expression |
Sets a local Context for an internationalized expression.
If there is no translation, then no context version is tried.
example2 :: String -> I18n String example2 = withContext (Just "test") . example
Arguments
| :: Locale | Locale to use |
| -> I18n a | Internationalized expression |
| -> I18n a | New internationalized expression. Note: while this expression is localy localized already, it is to be a part of another internationalized expression. Therefore the final type is internationalized. |
Sets a local Locale for an internationalized expression.
example3 :: String -> I18n String example3 = withLocale (Locale "ru") . example2