Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language handling for Snap.
Support for determining the client's prefered language using the Accept-Language header or using suffixes to the requested URI.
- type RangeMapping a = Map String a
- getAcceptLanguage :: MonadSnap m => RangeMapping a -> m a
- getSuffixLanguage :: MonadSnap m => RangeMapping a -> m a
- switchSuffixLanguage :: Eq a => RangeMapping a -> ByteString -> Maybe a -> ByteString
- setContentLanguage :: (Eq a, MonadSnap m) => RangeMapping a -> a -> m ()
Documentation
type RangeMapping a = Map String a Source #
A mapping from language ranges as defined in rfc2616 to languages in your own representation.
For example:
data Language = EN | SV deriving Eq mapping :: RangeMapping Language mapping = Map.fromList [("en-gb",EN),("sv-se",SV)]
getAcceptLanguage :: MonadSnap m => RangeMapping a -> m a Source #
Attempt to find a suitable language according to the Accept-Language header of the request.
This handler will call pass if it cannot find a suitable language.
getSuffixLanguage :: MonadSnap m => RangeMapping a -> m a Source #
Attempt to find a suitable language according to a suffix in the request URI corresponding to a language range.
Will call pass if it cannot find a suitable language.
If a match is found, the suffix will be removed from the URI in the request, so that you can later match on your resource as usual and not worry about suffixes.
For example, with the following requested URI:
/resource.en-gb?param=value
getSuffixLanguage
with our previously defined mapping will return EN
and rqPathInfo
will be changed to:
/resource?param=value
:: Eq a | |
=> RangeMapping a | |
-> ByteString | The URI. |
-> Maybe a | The language to be appended to the URI, or Nothing to remove language suffix. |
-> ByteString |
Change, or remove, the language suffix of an URI.
setContentLanguage :: (Eq a, MonadSnap m) => RangeMapping a -> a -> m () Source #
Set the Content-Language header in the response.