<commit_before><?php

namespace ASF;

use Silex\Application;

class Language
{
	public $app;
	public $file;
	public $phrases = array();

	public function __construct (Application $app)
	{
		$this->app = $app;

		$this->file = __DIR__ . '/../../src/Languages/' . $this->app['defaults']['language'] . '.json';
		$this->phrases = json_decode(file_get_contents($this->file), true);
	}

	public function phrase ($phrase, $replacements = array())
	{
		if (array_key_exists($phrase, $this->phrases))
		{
			$phrase = nl2br($this->phrases[$phrase]);
		}

		if (count($replacements) > 0)
		{
			$phrase = vsprintf($phrase, $replacements);
		}<commit_msg>added comments to Language class<commit_after><?php

namespace ASF;

use Silex\Application;

/**
 * Replaces the given string with its translated counterpart
 */
class Language
{
	/**
	 * @var object
	 */
	public $app;

	/**
	 * The file containing translated strings
	 * @var string
	 */
	public $file;

	/**
	 * The internal array of strings
	 * @var array
	 */
	public $phrases = array();

	/**
	 * Sets the app instance and loads the language file into an internal array
	 * @param Application $app [description]
	 */
	public function __construct (Application $app)
	{
		$this->app = $app;

		$this->file = __DIR__ . '/../../src/Languages/' . $this->app['defaults']['language'] . '.json';
		$this->phrases = json_decode(file_get_contents($this->file), true);
	}

	/**
	 * Replaces the string with its translation or returns the string
	 * if no translation exists
	 * @param  string $phrase       
	 * @param  array  $replacements An array of key value replacements
	 * @return string The translated string or original string
	 */
	public function phrase ($phrase, $replacements = array())
	{
		if (array_key_exists($phrase, $this->phrases))
		{
			$phrase = nl2br($this->phrases[$phrase]);
		}

		if (count($replacements) > 0)
		{
			$phrase = vsprintf($phrase, $replacements);
		}
{'fraction_non_alphanumeric': 0.15484205075090626, 'fraction_numerical': 0.0020714655618850335, 'mean_word_length': 3.6220095693779903, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '6397276', 'n_tokens_mistral': 675, 'n_tokens_neox': 619, 'n_words': 171}