Removed Data.Object.Translate
This commit is contained in:
parent
da3953c10c
commit
00115f02d4
@ -1,94 +0,0 @@
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
---------------------------------------------------------
|
||||
--
|
||||
-- Module : Data.Object.Translate
|
||||
-- Copyright : Michael Snoyman
|
||||
-- License : BSD3
|
||||
--
|
||||
-- Maintainer : Michael Snoyman <michael@snoyman.com>
|
||||
-- Stability : Stable
|
||||
-- Portability : portable
|
||||
--
|
||||
-- Objects which can be translated into different languages.
|
||||
---------------------------------------------------------
|
||||
module Data.Object.Translate
|
||||
( -- * Types
|
||||
Language
|
||||
, TranslatedString
|
||||
, Translator
|
||||
, TranslateObject
|
||||
, TranslateKeyObject
|
||||
-- * Type classes
|
||||
, CanTranslate (..)
|
||||
-- * Utilities for objects
|
||||
, translateObject
|
||||
, translateKeyObject
|
||||
-- * Specialized functions
|
||||
, toTranslateObject
|
||||
, fromTranslateObject
|
||||
) where
|
||||
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Control.Monad.Attempt
|
||||
import Data.Object.Text
|
||||
|
||||
-- | Should usually be the well established I18N translation code. Examples
|
||||
-- include en, en_US, es, and so on. If you use these common codes, you will
|
||||
-- have easy interop with other systems.
|
||||
type Language = String
|
||||
type TranslatedString = Text
|
||||
|
||||
-- | Given a list of destination languages (ordered by preference), generate
|
||||
-- a translated string. Must return some value.
|
||||
type Translator = [Language] -> TranslatedString
|
||||
|
||||
-- | Usually you do not need to translate both keys and values, so this should
|
||||
-- be the more common type.
|
||||
type TranslateObject = Object Text Translator
|
||||
|
||||
-- | For the occassions when you really need to translate everything.
|
||||
type TranslateKeyObject = Object Translator Translator
|
||||
|
||||
-- | Anything which can be translated into a different language.
|
||||
--
|
||||
-- Minimal complete definition: translate or (tryTranslate and
|
||||
-- defaultTranslate).
|
||||
class CanTranslate a where
|
||||
translate :: a -> Translator
|
||||
translate a [] = defaultTranslate a
|
||||
translate a (lang:langs) =
|
||||
fromMaybe (translate a langs) $ tryTranslate a lang
|
||||
|
||||
tryTranslate :: a -> Language -> Maybe TranslatedString
|
||||
tryTranslate a = Just . translate a . return
|
||||
|
||||
defaultTranslate :: a -> TranslatedString
|
||||
defaultTranslate a = translate a []
|
||||
|
||||
instance CanTranslate Text where
|
||||
translate = const
|
||||
|
||||
-- | Generate a 'TextObject' with the translation of the
|
||||
-- original based on the language list supplied.
|
||||
translateObject :: [Language]
|
||||
-> TranslateObject
|
||||
-> TextObject
|
||||
translateObject langs = fmap ($ langs)
|
||||
|
||||
-- | Same as 'translateObject', but translate the keys as well as the values.
|
||||
translateKeyObject :: [Language]
|
||||
-> TranslateKeyObject
|
||||
-> TextObject
|
||||
translateKeyObject langs = mapKeysValues ($ langs) ($ langs)
|
||||
|
||||
-- | 'toObject' specialized for 'TranslateObject's
|
||||
toTranslateObject :: ToObject a TranslatedString Translator
|
||||
=> a -> TranslateObject
|
||||
toTranslateObject = toObject
|
||||
|
||||
-- | 'fromObject' specialized for 'TranslateObject's
|
||||
fromTranslateObject :: FromObject a TranslatedString Translator
|
||||
=> TranslateObject
|
||||
-> Attempt a
|
||||
fromTranslateObject = fromObject
|
||||
@ -18,6 +18,7 @@ module Yesod.Definitions
|
||||
, toVerb
|
||||
, Resource
|
||||
, Approot (..)
|
||||
, Language
|
||||
) where
|
||||
|
||||
import qualified Hack
|
||||
@ -37,3 +38,5 @@ type Resource = [String]
|
||||
-- programatically, but due to ambiguities in different ways of doing URL
|
||||
-- rewriting for (fast)cgi applications, it should be supplied by the user.
|
||||
newtype Approot = Approot { unApproot :: String }
|
||||
|
||||
type Language = String
|
||||
|
||||
@ -50,11 +50,11 @@ import qualified Hack
|
||||
import Data.Function.Predicate (equals)
|
||||
import Yesod.Constants
|
||||
import Yesod.Utils
|
||||
import Yesod.Definitions
|
||||
import Control.Applicative (Applicative (..))
|
||||
import Web.Encodings
|
||||
import Data.Time.Calendar (Day, fromGregorian)
|
||||
import Data.Char (isDigit)
|
||||
import Data.Object.Translate (Language)
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
|
||||
-- $param_overview
|
||||
|
||||
@ -28,7 +28,6 @@ module Yesod.Response
|
||||
, Content
|
||||
, ToContent (..)
|
||||
, runContent
|
||||
, translateContent
|
||||
-- * Abnormal responses
|
||||
, ErrorResult (..)
|
||||
, getHeaders
|
||||
@ -46,9 +45,9 @@ module Yesod.Response
|
||||
#endif
|
||||
) where
|
||||
|
||||
import Yesod.Definitions
|
||||
import Data.Time.Clock
|
||||
import Data.Object.Text
|
||||
import Data.Object.Translate
|
||||
import Data.Object.Instances
|
||||
import qualified Data.ByteString as SBS
|
||||
import qualified Data.ByteString.Lazy as LBS
|
||||
@ -94,11 +93,6 @@ instance ToContent Text where
|
||||
toContent = Text . convertSuccess
|
||||
instance ToContent ([Language] -> String) where
|
||||
toContent f = TransText $ convertSuccess . f
|
||||
instance ToContent Translator where
|
||||
toContent f = TransText $ convertSuccess . f
|
||||
|
||||
translateContent :: CanTranslate t => t -> Content
|
||||
translateContent t = toContent $ translate t
|
||||
|
||||
type RepT m = (ContentType, m Content)
|
||||
|
||||
|
||||
@ -17,10 +17,6 @@ flag buildtests
|
||||
default: False
|
||||
|
||||
library
|
||||
if flag(buildtests)
|
||||
Buildable: False
|
||||
else
|
||||
Buildable: True
|
||||
build-depends: base >= 4 && < 5,
|
||||
old-locale >= 1.0.0.1 && < 1.1,
|
||||
time >= 1.1.3 && < 1.2,
|
||||
@ -60,7 +56,6 @@ library
|
||||
Yesod.Yesod
|
||||
Data.Object.Html
|
||||
Data.Object.Instances
|
||||
Data.Object.Translate
|
||||
Hack.Middleware.MethodOverride
|
||||
Hack.Middleware.ClientSession
|
||||
Hack.Middleware.Jsonp
|
||||
|
||||
Loading…
Reference in New Issue
Block a user