i18n-0.1: Internationalization for Haskell

Portabilityportable
Stabilityexperimental
Maintainereugene.grigoriev@gmail.com

Text.I18n

Contents

Description

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.

Synopsis

Type Declarations

newtype Msgid Source

Constructors

Msgid String 

Instances

data L10nMode Source

Localization mode. L10nMust will throw an exception if unable to translate whereas L10nMay will just return the original Msgid String. L10nMay is used by localize.

Constructors

L10nMust 
L10nMay 

newtype Locale Source

Constructors

Locale String 

Instances

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

The Internationalization monad allows the use of IO through liftIO.

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.

 impl = do
       hello <- gettext "Hello, %s!"
       liftIO (Utf8.putStrLn (hello "Joe"))

localizeSource

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

withContextSource

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

withLocaleSource

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

localize'Source

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