Search in sources :

Example 1 with Translation

use of com.erudika.para.core.Translation in project scoold by Erudika.

the class TranslateController method delete.

@PostMapping("/delete/{id}")
public String delete(@PathVariable String id, HttpServletRequest req, Model model) {
    if (id != null && utils.isAuthenticated(req)) {
        Translation trans = (Translation) pc.read(id);
        Profile authUser = utils.getAuthUser(req);
        if (authUser.getId().equals(trans.getCreatorid()) || utils.isAdmin(authUser)) {
            utils.getLangutils().disapproveTranslation(trans.getLocale(), trans.getId());
            pc.delete(trans);
        }
        if (!utils.isAjaxRequest(req)) {
            return "redirect:" + req.getRequestURI();
        }
    }
    return "base";
}
Also used : Translation(com.erudika.para.core.Translation) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with Translation

use of com.erudika.para.core.Translation in project scoold by Erudika.

the class TranslateController method translate.

@GetMapping({ "/{locale}", "/{locale}/{index}" })
public String translate(@PathVariable String locale, @PathVariable(required = false) String index, HttpServletRequest req, Model model) {
    Locale showLocale = utils.getLangutils().getProperLocale(locale);
    if (showLocale == null || "en".equals(showLocale.getLanguage())) {
        // can't translate default language
        return "redirect:" + languageslink;
    }
    int showIndex = -1;
    List<Translation> translationslist = Collections.emptyList();
    Pager itemcount = utils.getPager("page", req);
    if (!StringUtils.isBlank(index)) {
        showIndex = getIndex(index, langkeys);
        // this is what is currently shown for translation
        translationslist = utils.getLangutils().readAllTranslationsForKey(showLocale.getLanguage(), langkeys.get(showIndex), itemcount);
    }
    String title = utils.getLang(req).get("translate.title") + " - " + showLocale.getDisplayName(showLocale);
    int showLocaleProgress = utils.getLangutils().getTranslationProgressMap().get(showLocale.getLanguage());
    model.addAttribute("path", "translate.vm");
    model.addAttribute("title", title);
    model.addAttribute("showIndex", showIndex);
    model.addAttribute("showLocale", showLocale);
    model.addAttribute("langkeys", langkeys);
    model.addAttribute("deflang", deflang);
    model.addAttribute("showLocaleProgress", showLocaleProgress);
    model.addAttribute("translationslist", translationslist);
    model.addAttribute("itemcount", itemcount);
    return "base";
}
Also used : Locale(java.util.Locale) Translation(com.erudika.para.core.Translation) Pager(com.erudika.para.utils.Pager) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with Translation

use of com.erudika.para.core.Translation in project scoold by Erudika.

the class TranslateController method post.

@PostMapping("/{locale}/{index}")
public String post(@PathVariable String locale, @PathVariable String index, @RequestParam String value, HttpServletRequest req, Model model) {
    Locale showLocale = utils.getLangutils().getProperLocale(locale);
    if (utils.isAuthenticated(req) && showLocale != null && !"en".equals(showLocale.getLanguage())) {
        Set<String> approved = utils.getLangutils().getApprovedTransKeys(showLocale.getLanguage());
        Profile authUser = utils.getAuthUser(req);
        String langkey = langkeys.get(getIndex(index, langkeys));
        boolean isTranslated = approved.contains(langkey);
        if (!StringUtils.isBlank(value) && (!isTranslated || utils.isAdmin(authUser))) {
            Translation trans = new Translation(showLocale.getLanguage(), langkey, StringUtils.trim(value));
            trans.setCreatorid(authUser.getId());
            trans.setAuthorName(authUser.getName());
            trans.setTimestamp(System.currentTimeMillis());
            pc.create(trans);
            model.addAttribute("newtranslation", trans);
        }
        if (!utils.isAjaxRequest(req)) {
            return "redirect:" + translatelink + "/" + showLocale.getLanguage() + "/" + getNextIndex(getIndex(index, langkeys), approved, langkeys);
        }
    }
    return "base";
}
Also used : Locale(java.util.Locale) Translation(com.erudika.para.core.Translation) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with Translation

use of com.erudika.para.core.Translation in project scoold by Erudika.

the class TranslateController method approve.

@PostMapping("/approve/{id}")
public String approve(@PathVariable String id, HttpServletRequest req, Model model) {
    Translation trans = (Translation) pc.read(id);
    if (trans != null && utils.isAuthenticated(req)) {
        if (trans.getApproved()) {
            trans.setApproved(false);
            utils.getLangutils().disapproveTranslation(trans.getLocale(), trans.getId());
        } else {
            trans.setApproved(true);
            utils.getLangutils().approveTranslation(trans.getLocale(), trans.getThekey(), trans.getValue());
            utils.addBadge((Profile) pc.read(trans.getCreatorid()), POLYGLOT, true, true);
        }
        pc.update(trans);
    }
    if (!utils.isAjaxRequest(req)) {
        return "redirect:" + req.getRequestURI();
    }
    return "base";
}
Also used : Translation(com.erudika.para.core.Translation) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

Translation (com.erudika.para.core.Translation)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 Profile (com.erudika.scoold.core.Profile)2 Locale (java.util.Locale)2 Pager (com.erudika.para.utils.Pager)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1