i18n-0.3: Internationalization for Haskell

Portabilityportable
Stabilityexperimental
Maintainereugene.grigoriev@gmail.com

Text.I18n

Contents

Description

Internationalization support for Haskell. Use Text.I18n.Po module.

Plural forms are not yet implemented.

Synopsis

Type Declarations

newtype Msgid Source

Constructors

Msgid String 

Instances

newtype Locale Source

Constructors

Locale String 

Instances

type I18n a = ReaderT (Locale, L10n, Maybe Context) Identity aSource

The Internationalization monad built using monad transformers.

type L10n = Map Locale (Map (Maybe Context) (Map Msgid [Msgstr]))Source

The Localization structure.

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)

localizeSource

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")

withContextSource

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

withLocaleSource

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