<commit_before>package jsmessages.api

import play.api.i18n._
import play.api.Application
import org.apache.commons.lang3.StringEscapeUtils.escapeEcmaScript
import play.api.templates.JavaScript

/**
 * Can generate a JavaScript function computing localized messages of a Play application
 * @param app Play application to use
 */
class JsMessages(implicit app: Application) {

  /**
   * All the messages of the application, as a map of (lang -> map(key -> message)).
   *
   * The default implementation returns the Play! application messages. Override this lazy val to supply additional messages.
   */
  lazy val allMessages: Map[String, Map[String, String]] = Messages.messages
  
  /**
   * The application’s messages to use by default, as a map of (key -> message).
   * Data is already ECMAScript-escaped.
   */
  private val defaultMessagesEscaped: Map[String, String] =
    escapeMap(Messages.messages.get("default.play").getOrElse(Map.empty)) ++
    escapeMap(Messages.messages.get("default").getOrElse(Map.empty))

  /**
   * The messages defined in the given Play application `app`, for all languages, as a map of (lang -> map(key -> message))
   * with addition of default messages and Play Framework messages.
   */
  lazy val allMessagesEscaped: Map[String, Map[String, String]] = Messages.messages.mapValues(escapeMap)

  /**
   *  Nearly JSON formated string of allMessages.
   */
  private val allMessagesString: String = formatAllMap(allMessagesEscaped)

  /**
   * Cache to memorize computed messages for each available lang
   * Computation consists of merging default messages, default Play messages,
   * messages for the language of the lang and messages of the lang itself.
   */
  private val messagesCache: Map[String, Map[String, String]] = for ((lang, msgs) <- allMessagesEscaped) yield {
    val maybeCountry = if (lang.contains("-")) Some(lang.split("-")(0)) else None

    lang -> (
      defaultMessagesEscaped ++
      maybeCountry.flatMap(country => allMessagesEscaped.get(country)).getOrElse(Map.empty) ++
      msgs
    )
  }
<commit_msg>use only allMessages as message source<commit_after>package jsmessages.api

import play.api.i18n.Lang
import play.api.Application
import org.apache.commons.lang3.StringEscapeUtils.escapeEcmaScript
import play.api.templates.JavaScript

/**
 * Can generate a JavaScript function computing localized messages of a Play application
 * @param app Play application to use
 */
class JsMessages(implicit app: Application) {

  /**
   * All the messages of the application, as a map of (lang -> map(key -> message)).
   *
   * The default implementation returns the Play! application messages. Override this lazy val to supply additional messages.
   */
  lazy val allMessages: Map[String, Map[String, String]] = play.api.i18n.Messages.messages
  
  /**
   * The messages defined in the given Play application `app`, for all languages, as a map of (lang -> map(key -> message))
   * with addition of default messages and Play Framework messages.
   */
  private val allMessagesEscaped: Map[String, Map[String, String]] = allMessages.mapValues(escapeMap)

  /**
   *  Nearly JSON formated string of allMessages.
   */
  private val allMessagesString: String = formatAllMap(allMessagesEscaped)

  /**
   * Cache to memorize computed messages for each available lang
   * Computation consists of merging default messages, default Play messages,
   * messages for the language of the lang and messages of the lang itself.
   */
  private val messagesCache: Map[String, Map[String, String]] = for ((lang, msgs) <- allMessagesEscaped) yield {
    val maybeCountry = if (lang.contains("-")) Some(lang.split("-")(0)) else None

    lang -> (
      allMessagesEscaped.get("default.play").getOrElse(Map.empty) ++
      allMessagesEscaped.get("default").getOrElse(Map.empty) ++
      maybeCountry.flatMap(country => allMessagesEscaped.get(country)).getOrElse(Map.empty) ++
      msgs
    )
  }

{'fraction_non_alphanumeric': 0.10357052418333755, 'fraction_numerical': 0.0025322866548493288, 'mean_word_length': 3.9313358302122348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '1214706', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1076, 'n_words': 366}