Safe Haskell | None |
---|---|
Language | Haskell2010 |
This is the main module of the localize
package.
It contains definitions of general use and reexport generally required internal modules.
Synopsis
- __ :: Localized m => TranslationSource -> m Text
- __n :: (Localized m, MonadFail m, VarContainer c) => TranslationSource -> TranslationSource -> Int -> c -> m Text
- __f :: (Localized m, MonadFail m, VarContainer c) => TranslationSource -> c -> m Text
- translate :: Localized m => TranslationSource -> m Text
- translateN :: Localized m => TranslationSource -> TranslationSource -> Int -> m Text
- translateNFormat :: (Localized m, MonadFail m, VarContainer vars) => TranslationSource -> TranslationSource -> Int -> vars -> m Text
- lookup :: Translations -> LanguageId -> TranslationSource -> Text
- withTranslation :: Localized m => (b -> r) -> (Catalog -> Maybe Context -> b -> r) -> b -> m r
- module Text.Localize.Types
- module Text.Localize.Load
- module Text.Localize.Locale
Documentation
This is the main module of the localize
package. In most cases, you have to import only
this module. In specific cases, you may also want to import Text.Localize.IO or Text.Localize.State.
All functions exported by localize
package work with any instance of the
Localized
type class. There are two simple examples of this type class
implementation provided in separate modules (IO and State); however, in
complex applications it may be more convinient to implement Localized
instance for the monadic stack you already have.
Example of usage is:
import qualified Data.Text as T import qualified Data.Text.Lazy.IO as TLIO import Text.Localize newtype MyMonad a = MyMonad {unMyMonad :: ... } deriving (Monad) instance Localized MyMonad where ... runMyMonad :: Translations -> MyMonad a -> IO a runMyMonad = ... hello :: T.Text -> MyMonad () hello name = do liftIO $ TLIO.putStrLn =<< __ "Your name: " liftIO $ hFlush stdout name <- liftIO $ TLIO.getLine greeting <- __f "Hello, {}!" (Single name) liftIO $ TLIO.putStrLn greeting main :: IO () main = do translations <- locateTranslations $ linuxLocation "hello" runMyMonad translations hello
See also working examples under examples/
directory.
__n :: (Localized m, MonadFail m, VarContainer c) => TranslationSource -> TranslationSource -> Int -> c -> m Text Source #
Short alias for translateNFormat
.
__f :: (Localized m, MonadFail m, VarContainer c) => TranslationSource -> c -> m Text Source #
Short alias for translateFormat
.
Basic functions
:: Localized m | |
=> TranslationSource | Single form in original language |
-> TranslationSource | Plural form in original language |
-> Int | Number |
-> m Text |
Translate a string, taking plural forms into account.
:: (Localized m, MonadFail m, VarContainer vars) | |
=> TranslationSource | Single form of formatting string in original language |
-> TranslationSource | Plural form of formatting string in original language |
-> Int | Number |
-> vars | Substitution variables |
-> m Text |
Translate a string, taking plural forms into account, and substitute variables into it. Data.Text.Format.Heavy.format syntax is used.
lookup :: Translations -> LanguageId -> TranslationSource -> Text Source #
Look up for translation. Returns source string if translation not found.
:: Localized m | |
=> (b -> r) | Function to be executed if there is no translation for current language loaded. |
-> (Catalog -> Maybe Context -> b -> r) | Function to be executed on current catalog. |
-> b -> m r | Function lifted into |
Execute function depending on current translation catalog and context.
Reexports
module Text.Localize.Types
module Text.Localize.Load
module Text.Localize.Locale