From f112607ac3044467407099a78b7e73312dbf5e73 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Wed, 29 Apr 2020 20:09:46 +1200 Subject: [PATCH] Read as a percentage, that's more international. eSpeak can trivially localize this to it's various locales. --- src/SpeechStyle.hs | 13 +++++++++++-- useragent.css | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/SpeechStyle.hs b/src/SpeechStyle.hs index c53fd7b..15598f1 100644 --- a/src/SpeechStyle.hs +++ b/src/SpeechStyle.hs @@ -6,7 +6,9 @@ import Data.CSS.Syntax.Tokens import Data.CSS.Style import Data.Text as Txt import Data.Scientific (toRealFloat) -import Data.Maybe (isJust, catMaybes) +import Data.Maybe (isJust, catMaybes, fromMaybe) + +import Text.Read (readMaybe) -- to parse into a more international textual representation. data Unit' = Unit' Text Float data SpeechStyle = SpeechStyle { @@ -180,11 +182,18 @@ parseCue [Ident "none"] = Just NoCue parseCue _ = Nothing isCue = isJust . parseCue --- ParsingUtils parseStrings (String txt:toks) = append txt <$> parseStrings toks +parseStrings (Function "-rhaps-percentage":String num:String denom:RightParen:toks) = + append (pack $ show frac) <$> parseStrings toks + where + frac :: Int + frac = round (readNum num / readNum denom * 100) + readNum :: Text -> Float + readNum = fromMaybe (0.0) . readMaybe . unpack parseStrings [] = Just "" parseStrings _ = Nothing +-- ParsingUtils cssUnit n "khz" = Unit' "hz" (cssFloat n*1000) cssUnit n unit = Unit' unit $ cssFloat n cssFloat :: NumericValue -> Float diff --git a/useragent.css b/useragent.css index 4612665..8378e21 100644 --- a/useragent.css +++ b/useragent.css @@ -86,8 +86,7 @@ q, blockquote {voice-family: female 2} cite {voice-stress: reduce} dialog {speak: never} dialog[open] {speak: always} kbd {speak-as: spell-out} -progress {content: attr(value) " of " attr(max)} -progress:lang(hu) {content: attr(value) " a " attr(max) "-ból"} /* FIXME depending on number of vowels, should be -ből */ +progress {content: -rhaps-percentage(attr(value) attr(max)) "%"} sub {voice-rate: x-fast} sup {voice-rate: fast} var {voice-rate: slow} -- 2.30.2