<commit_before><?php

class Locale {
	
	private static $locales = array();
	
	public static function load($lang=null){
		if(!$lang){
			$lang = self::getLanguage();
		}
		$cachekey = "locale:" . $lang;
		$locale = Cache::load($cachekey);
		if(!is_array($locale)){
			// No cache available -> load from database
			$sql = new SqlManager();
			$sql->setQuery("SELECT * FROM locale WHERE language = {{lang}}");
			$sql->bindParam('{{lang}}', $lang, "int");
			$sql->execute();
			$locale = array();
			while($res = $sql->fetch()){
				self::$locales[$lang][$res['code']] = $res['text'];
			}
			// Save loaded locales into cache file for later use 
			Cache::save($cachekey,$locale);
		}
	}
	
	public static function get($code, $lang=null, $defaultvalue=null){
		// Get specific locale value by given key
		if(!$lang){
			$lang = self::getLanguage();
		}
		self::load($lang);
		// If not found, create new locale with default value
		if(!isset(self::$locales[$lang][$code]) && !is_null($defaultvalue)){
			self::save($code, $defaultvalue, $lang);
			self::$locales[$lang][$code] = $defaultvalue;
		}
		return self::$locales[$lang][$code];
	}
	
	public static function save($code, $value, $lang=null){
		// Save specific locale value by given key<commit_msg>FIX fallback value for new locales<commit_after><?php

class Locale {
	
	private static $locales = array();
	
	public static function load($lang=null){
		if(!$lang){
			$lang = self::getLanguage();
		}
		$cachekey = "locale:" . $lang;
		$locale = Cache::load($cachekey);
		if(!is_array($locale)){
			// No cache available -> load from database
			$sql = new SqlManager();
			$sql->setQuery("SELECT * FROM locale WHERE language = {{lang}}");
			$sql->bindParam('{{lang}}', $lang, "int");
			$sql->execute();
			$locale = array();
			while($res = $sql->fetch()){
				self::$locales[$lang][$res['code']] = $res['text'];
			}
			// Save loaded locales into cache file for later use 
			Cache::save($cachekey,$locale);
		}
	}
	
	public static function get($code, $lang=null, $defaultvalue=null){
		// Get specific locale value by given key
		if(!$lang){
			$lang = self::getLanguage();
		}
		self::load($lang);
		// If not found, create new locale with default value
		if(!isset(self::$locales[$lang][$code])){
			if(!is_null($defaultvalue)){
				self::save($code, $defaultvalue, $lang);
			}
			self::$locales[$lang][$code] = $defaultvalue;
		}
		return self::$locales[$lang][$code];
	}
	
	public static function save($code, $value, $lang=null){
		// Save specific locale value by given key
{'fraction_non_alphanumeric': 0.19448818897637796, 'fraction_numerical': 0.0, 'mean_word_length': 4.196319018404908, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7214324', 'n_tokens_mistral': 931, 'n_tokens_neox': 827, 'n_words': 210}