fastcgi: replace /categories, /languages and /mylanguage with /info.

This commit is contained in:
bjorn
2008-09-17 12:37:34 +00:00
parent 9265be0326
commit 4a2bac3cf2
2 changed files with 17 additions and 16 deletions

View File

@@ -36,9 +36,7 @@ cgiMain pgf =
"/complete" -> return (doComplete pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getLimit "/complete" -> return (doComplete pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getLimit
"/linearize" -> return (doLinearize pgf) `ap` getTree `ap` getTo "/linearize" -> return (doLinearize pgf) `ap` getTree `ap` getTo
"/translate" -> return (doTranslate pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getTo "/translate" -> return (doTranslate pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getTo
"/categories" -> return $ doCategories pgf "/info" -> return (doInfo pgf) `ap` requestAcceptLanguage
"/languages" -> return $ doLanguages pgf
"/mylanguage" -> return (doMyLanguage pgf) `ap` requestAcceptLanguage
_ -> throwCGIError 404 "Not Found" ["Resource not found: " ++ path] _ -> throwCGIError 404 "Not Found" ["Resource not found: " ++ path]
outputJSON json outputJSON json
where where
@@ -102,19 +100,18 @@ doLinearize :: PGF -> PGF.Tree -> Maybe PGF.Language -> JSValue
doLinearize pgf tree mto = showJSON $ map toJSObject doLinearize pgf tree mto = showJSON $ map toJSObject
[[("to",to),("text",text)] | (to,text) <- linearize' pgf mto tree] [[("to",to),("text",text)] | (to,text) <- linearize' pgf mto tree]
doLanguages :: PGF -> JSValue doInfo :: PGF -> Maybe (Accept Language) -> JSValue
doLanguages pgf = showJSON $ map toJSObject doInfo pgf macc = showJSON $ toJSObject
[[("name", showJSON l), [("name", showJSON (PGF.abstractName pgf)),
("languageCode", showJSON $ fromMaybe "" (PGF.languageCode pgf l)), ("userLanguage", showJSON (selectLanguage pgf macc)),
("canParse", showJSON $ PGF.canParse pgf l)] ("categories", showJSON categories),
| l <- PGF.languages pgf] ("languages", showJSON languages)]
where languages = map toJSObject
doCategories :: PGF -> JSValue [[("name", showJSON l),
doCategories pgf = showJSON $ map toJSObject ("languageCode", showJSON $ fromMaybe "" (PGF.languageCode pgf l)),
[[("cat",cat)] | cat <- PGF.categories pgf] ("canParse", showJSON $ PGF.canParse pgf l)]
| l <- PGF.languages pgf]
doMyLanguage :: PGF -> Maybe (Accept Language) -> JSValue categories = map toJSObject [[("cat", cat)] | cat <- PGF.categories pgf]
doMyLanguage pgf macc = showJSON $ toJSObject [("languageName", selectLanguage pgf macc)]
-- * PGF utilities -- * PGF utilities

View File

@@ -170,6 +170,10 @@ public class Translate implements EntryPoint {
} }
toLangBox.addItem(l.getName()); toLangBox.addItem(l.getName());
} }
gf.mylanguage(new GF.MyLanguageCallback() {
}
setStatus("Loaded languages."); setStatus("Loaded languages.");
} }