<commit_before>package controllers

import core.ThemeAware
import organization.CMS
import play.api.Play.current
import play.templates.groovy.GroovyTemplates
import play.api.mvc._
import extensions.{Extensions, ConfigurationException}
import com.mongodb.casbah.commons.MongoDBObject
import org.bson.types.ObjectId
import models._
import play.api.data.Form
import play.api.i18n.{Lang, Messages}
import play.api.{Logger, Play}

/**
 *
 * @author <NAME> <<EMAIL>>
 */


trait ApplicationController extends Controller with GroovyTemplates with ThemeAware with Logging with Extensions {

  // ~~~ i18n

  private val LANG = "lang"

  implicit def getLang(implicit request: RequestHeader) = request.session.get(LANG).getOrElse(theme.defaultLanguage)

  override implicit def lang(implicit request: RequestHeader): Lang = Lang(getLang)

  def getLanguages = Lang.availables.map(l => (l.language, Messages("locale." + l.language)))

  def ApplicationAction[A](action: Action[A]): Action[A] = {
    Themed {
      Action(action.parser) {
        implicit request: Request[A] => {

          val langParam = request.queryString.get(LANG)

          val requestLanguage = if (langParam.isDefined) {
            Logger("CultureHub").debug("Setting language from parameter to " + langParam.get(0))
            langParam.get(0)
          } else if (request.session.get(LANG).isEmpty) {
            // if there is no language for this cookie / user set, set the default one from the PortalTheme
            Logger("CultureHub").debug("Setting language from theme to " + theme.defaultLanguage)
            theme.defaultLanguage
          } else {
            Logger("CultureHub").debug("Setting language from session to " + request.session(LANG))
            request.session(LANG)
          }

          val languageChanged = request.session.get(LANG) != Some(requestLanguage)

          // just to be clear, this is a feature of the play2 groovy template engine to override the language. due to our
          // action composition being applied after the template has been rendered, we need to pass it in this way
          renderArgs +=(__LANG, requestLanguage)

          val r = action(request).asInstanceOf[PlainResult]
          if (languageChanged) {
            composeSession(r, Session(Map(LANG -> getLang)))
          } else {
            r
          }
        }
      }
    }
  }
<commit_msg>Fixed a compile issue in the DelvingControllers<commit_after>package controllers

import core.ThemeAware
import organization.CMS
import play.api.Play.current
import play.templates.groovy.GroovyTemplates
import play.api.mvc._
import extensions.{Extensions, ConfigurationException}
import com.mongodb.casbah.commons.MongoDBObject
import org.bson.types.ObjectId
import models._
import play.api.data.Form
import play.api.i18n.{Lang, Messages}
import play.api.{Logger, Play}

/**
 *
 * @author <NAME> <<EMAIL>>
 */


trait ApplicationController extends Controller with GroovyTemplates with ThemeAware with Logging with Extensions {

  // ~~~ i18n

  private val LANG = "lang"

  implicit def getLang(implicit request: RequestHeader) = request.session.get(LANG).getOrElse(theme.defaultLanguage)

  override implicit def lang(implicit request: RequestHeader): Lang = Lang(getLang)

  def getLanguages = Lang.availables.map(l => (l.language, Messages("locale." + l.language)))

  def ApplicationAction[A](action: Action[A]): Action[A] = {
    Themed {
      Action(action.parser) {
        implicit request: Request[A] => {

          val langParam = request.queryString.get(LANG)

          val requestLanguage = if (langParam.isDefined) {
            Logger("CultureHub").debug("Setting language from parameter to " + langParam.get(0))
            langParam.get(0)
          } else if (request.session.get(LANG).isEmpty) {
            // if there is no language for this cookie / user set, set the default one from the PortalTheme
            Logger("CultureHub").debug("Setting language from theme to " + theme.defaultLanguage)
            theme.defaultLanguage
          } else {
            Logger("CultureHub").debug("Setting language from session to " + request.session(LANG))
            request.session(LANG)
          }

          val languageChanged = request.session.get(LANG) != Some(requestLanguage)

          // just to be clear, this is a feature of the play2 groovy template engine to override the language. due to our
          // action composition being applied after the template has been rendered, we need to pass it in this way
          renderArgs += (LANG, requestLanguage) // todo find out why there was a __ in front of __LANG

          val r = action(request).asInstanceOf[PlainResult]
          if (languageChanged) {
            composeSession(r, Session(Map(LANG -> getLang)))
          } else {
            r
          }
        }
      }
    }
  }

{'fraction_non_alphanumeric': 0.09872480460715755, 'fraction_numerical': 0.002879473467708762, 'mean_word_length': 2.931285367825384, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5322515', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1302, 'n_words': 383}