snap-language: Language handling for Snap

[ bsd3, library, web ] [ Propose Tags ] [ Report a vulnerability ]

Language handling for Snap.

Support for determining the client's prefered language using the Accept-Language header or using suffixes to the requested URI.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5
Change log CHANGELOG.md
Dependencies attoparsec (>=0.13.0.1 && <0.14), base (>=4.8 && <5), bytestring (>=0.10.6.0 && <0.11), containers (>=0.5.6.2 && <0.7), snap-core (>=0.9.8.0 && <1.1) [details]
License BSD-3-Clause
Author Petter Bergman
Maintainer jon.petter.bergman@gmail.com
Category Web
Home page https://github.com/jonpetterbergman/snap-accept-language
Bug tracker https://github.com/jonpetterbergman/snap-accept-language/issues
Source repo head: git clone http://github.com/jonpetterbergman/snap-accept-language
this: git clone http://github.com/jonpetterbergman/snap-accept-language(tag v0.1.0.5)
Uploaded by petterb at 2019-05-15T06:36:41Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3718 total (15 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-05-15 [all 1 reports]

Readme for snap-language-0.1.0.5

[back to package description]

snap-language

Language handling for Snap.

Support for determining the client's prefered language using the Accept-Language header or using suffixes to the requested URI.

Try this example:

{-# LANGUAGE OverloadedStrings #-}

module Simple where

import Snap.Http.Server
import Snap.Core
import Data.Map
import Control.Applicative

import Snap.Language

data Lang = SV | EN deriving Eq

table :: RangeMapping Lang
table = fromList [("sv-SE",SV),("en-GB",EN)]

getLanguage :: Snap Lang
getLanguage = 
  getSuffixLanguage table <|> 
  getAcceptLanguage table <|> 
  return EN

test :: IO ()
test = quickHttpServe $ do
  lang <- getLanguage
  dir "hello" $ handler lang

handler :: Lang -> Snap ()
handler EN = writeBS "hello"
handler SV = writeBS "hej"

You can now access /hello and you will get an answer depending on your Accept-Language header.

Or you can access /hello.en-GB or /hello.sv-SE directly.