Portability | portable |
---|---|
Stability | experimental |
Maintainer | eugene.grigoriev@gmail.com |
Internationalization support for Haskell based on GNU gettext (http://www.gnu.org/software/gettext). Use Text.I18n.Po module.
Plural forms are not yet implemented.
- 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]))
- gettext :: PrintfType a => String -> I18n a
- localize :: L10n -> Locale -> I18n a -> IO a
- withContext :: Maybe Context -> I18n a -> I18n a
- withLocale :: Locale -> I18n a -> I18n a
- localize' :: L10n -> L10nMode -> Locale -> I18n a -> IO a
Type Declarations
type I18n a = ReaderT (Locale, L10n, L10nMode, Maybe Context) IO aSource
The Internationalization monad allows the use of IO through liftIO
.
Internationalization Monad Functions
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"))
:: 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
:: 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
:: 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