From 00115f02d4369aadc1fe5514630eda523e0cc118 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 13 Dec 2009 00:28:41 +0200 Subject: [PATCH] Removed Data.Object.Translate --- Data/Object/Translate.hs | 94 ---------------------------------------- Yesod/Definitions.hs | 3 ++ Yesod/Request.hs | 2 +- Yesod/Response.hs | 8 +--- yesod.cabal | 5 --- 5 files changed, 5 insertions(+), 107 deletions(-) delete mode 100644 Data/Object/Translate.hs diff --git a/Data/Object/Translate.hs b/Data/Object/Translate.hs deleted file mode 100644 index 7ce8c704..00000000 --- a/Data/Object/Translate.hs +++ /dev/null @@ -1,94 +0,0 @@ -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE FlexibleContexts #-} ---------------------------------------------------------- --- --- Module : Data.Object.Translate --- Copyright : Michael Snoyman --- License : BSD3 --- --- Maintainer : Michael Snoyman --- 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 diff --git a/Yesod/Definitions.hs b/Yesod/Definitions.hs index 65a726fd..e3cc3a12 100644 --- a/Yesod/Definitions.hs +++ b/Yesod/Definitions.hs @@ -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 diff --git a/Yesod/Request.hs b/Yesod/Request.hs index 496e6dda..a25ed720 100644 --- a/Yesod/Request.hs +++ b/Yesod/Request.hs @@ -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 diff --git a/Yesod/Response.hs b/Yesod/Response.hs index 14b3a299..753c8649 100644 --- a/Yesod/Response.hs +++ b/Yesod/Response.hs @@ -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) diff --git a/yesod.cabal b/yesod.cabal index 6c9e3538..0c15b70a 100644 --- a/yesod.cabal +++ b/yesod.cabal @@ -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