<commit_before><?php
/*
	PufferPanel - A Game Server Management Panel
	Copyright (c) 2015 <NAME>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see http://www.gnu.org/licenses/.
 */
namespace PufferPanel\Core;
use \Exception;

/**
 * PufferPanel Core Language Class
 */
class Language extends User {

	/**
	 * @param string $language
	 */
	protected $language;

	/**
	 * @param array $loaded
	 */
	protected $loaded;

	/**
	 * Constructor class for Language
	 */
	public function __construct() {

		if(!$this->getData('language')) {
			$this->language = (isset($_COOKIE['pp_language']) && !empty($_COOKIE['pp_language'])) ? $_COOKIE['pp_language'] : Settings::config()->default_language;
		} else {
			$this->language = $this->getData('language');
		}

		if(!file_exists(APP_DIR.'languages/'.$this->language.'.json')) {
			throw new Exception('Unable to load the required language file! '.APP_DIR.'languages/'.$this->language.'.json');
		}

		$this->loaded = json_decode(file_get_contents(APP_DIR.'languages/'.$this->language.'.json'), true);

	}

	/**
	 * Returns the language value associated with a key. Graceful fallback to English if translated version doesn't exist.
	 *
	 * @param string $template The language key.
	 * @return string
	 */
	public function render($template) {

		if(!array_key_exists($template, $this->loaded)) {

			$load_english = json_decode(file_get_contents(APP_DIR.'languages/en_US.json'), true);<commit_msg>If no language ever set, default to en_US Fixes cases where the db isn't set up right, and we don't have a language<commit_after><?php
/*
	PufferPanel - A Game Server Management Panel
	Copyright (c) 2015 <NAME>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see http://www.gnu.org/licenses/.
 */
namespace PufferPanel\Core;
use \Exception;

/**
 * PufferPanel Core Language Class
 */
class Language extends User {

	/**
	 * @param string $language
	 */
	protected $language;

	/**
	 * @param array $loaded
	 */
	protected $loaded;

	/**
	 * Constructor class for Language
	 */
	public function __construct() {

		if(!$this->getData('language')) {
			$this->language = (isset($_COOKIE['pp_language']) && !empty($_COOKIE['pp_language'])) ? $_COOKIE['pp_language'] : Settings::config()->default_language;
		} else {
			$this->language = $this->getData('language');
		}

        if(!$this->language) {
            $this->language = 'en_US';
        }

		if(!file_exists(APP_DIR.'languages/'.$this->language.'.json')) {
			throw new Exception('Unable to load the required language file! '.APP_DIR.'languages/'.$this->language.'.json');
		}

		$this->loaded = json_decode(file_get_contents(APP_DIR.'languages/'.$this->language.'.json'), true);

	}

	/**
	 * Returns the language value associated with a key. Graceful fallback to English if translated version doesn't exist.
	 *
	 * @param string $template The language key.
	 * @return string
	 */
	public function render($template) {

		if(!array_key_exists($template, $this->loaded)) {

			$load_english = json_decode(file_get_contents(APP_DIR.'languages/en_US.json'), true);
{'fraction_non_alphanumeric': 0.12201014737859386, 'fraction_numerical': 0.0024160425223483935, 'mean_word_length': 4.048780487804878, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7422593', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1168, 'n_words': 414}