pLocale :: X.Element -> ElementParser Locale
pLocale node = do
  let attr = getAttributes node
  lang <- case lookupAttribute "lang" attr of
            Nothing -> return Nothing
            Just l  -> either parseFailure (return . Just) $ parseLang l
  let styleOpts = mconcat . map getAttributes $
                      getChildren "style-options" node
  let addDateElt e m =
        case e of
          Element (EDate _ dateType _ _) _ -> M.insert dateType e m
          _ -> error "pDate returned an element other than EDate"
  dateElts <- foldr addDateElt mempty <$> mapM pDate (getChildren "date" node)
  let termNodes = concatMap (getChildren "term") (getChildren "terms" node)
  terms <- foldM parseTerm mempty termNodes
  return $
    Locale
    { localeLanguage               = lang
    , localePunctuationInQuote     = (== "true") <$>
               lookupAttribute "punctuation-in-quote" styleOpts
    , localeLimitDayOrdinalsToDay1 = (== "true") <$>
               lookupAttribute "limit-day-ordinals-to-day-1" styleOpts
    , localeDate                   = dateElts
    , localeTerms                  = terms
    }
pLocale :: X.Element -> ElementParser Locale
pLocale node = do
  let attr = getAttributes node
  lang <- case lookupAttribute "lang" attr of
            Nothing -> return Nothing
            Just l  -> either parseFailure (return . Just) $ parseLang l
  let styleOpts = mconcat . map getAttributes $
                      getChildren "style-options" node
  let addDateElt e m =
        case e of
          Element (EDate _ dateType _ _) _ -> M.insert dateType e m
          _ -> error "pDate returned an element other than EDate"
  dateElts <- foldr addDateElt mempty <$> mapM pDate (getChildren "date" node)
  let termNodes = concatMap (getChildren "term") (getChildren "terms" node)
  terms <- foldM parseTerm mempty termNodes
  return $
    Locale
    { localeLanguage               = lang
    , localePunctuationInQuote     = (== "true") <$>
               lookupAttribute "punctuation-in-quote" styleOpts
    , localeLimitDayOrdinalsToDay1 = (== "true") <$>
               lookupAttribute "limit-day-ordinals-to-day-1" styleOpts
    , localeDate                   = dateElts
    , localeTerms                  = terms
    }
pLocale node = do
  let attr = getAttributes node
  lang <- case lookupAttribute "lang" attr of
            Nothing -> return Nothing
            Just l  -> either parseFailure (return . Just) $ parseLang l
  let styleOpts = mconcat . map getAttributes $
                      getChildren "style-options" node
  let addDateElt e m =
        case e of
          Element (EDate _ dateType _ _) _ -> M.insert dateType e m
          _ -> error "pDate returned an element other than EDate"
  dateElts <- foldr addDateElt mempty <$> mapM pDate (getChildren "date" node)
  let termNodes = concatMap (getChildren "term") (getChildren "terms" node)
  terms <- foldM parseTerm mempty termNodes
  return $
    Locale
    { localeLanguage               = lang
    , localePunctuationInQuote     = (== "true") <$>
               lookupAttribute "punctuation-in-quote" styleOpts
    , localeLimitDayOrdinalsToDay1 = (== "true") <$>
               lookupAttribute "limit-day-ordinals-to-day-1" styleOpts
    , localeDate                   = dateElts
    , localeTerms                  = terms
    }