<?php
/*
 * Software Name: Eorisis Setup
 * Software URI: https://eorisis.com/shop/software/joomla/setup
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace eorisis_setup\framework\install\lib\core\model;
\defined('_JEXEC') or die;

use eorisis_setup\framework\install\lib\core\model\filesystem;

class language
{
	const DEFAULT_TAG = 'en-GB';
	public static $path = '';
	private static $loaded = [];

	// --------------------------------------------------

	public function __construct() {}

	// --------------------------------------------------

	public static function load(string $name) // void
	{
		// Load the default first
		$ini_path = self::$path.'/language/'.self::DEFAULT_TAG.'/'.$name.'.ini';
		$arr = filesystem::ini_to_array($ini_path);
		if ($arr)
		{
			self::add_array($arr);
		}

		$current_tag = \eorisis_setup\framework\install\lib\core\cms\language::current_tag();
		if (self::DEFAULT_TAG == $current_tag)
		{
			return;
		}

		// Load additional language

		$ini_path = self::$path.'/language/'.$current_tag.'/'.$name.'.ini';
		$arr = filesystem::ini_to_array($ini_path);
		if ($arr)
		{
			self::add_array($arr);
		}
	}

	// --------------------------------------------------

	public static function text(string $key)
	{
		return isset(self::$loaded[$key]) ? self::$loaded[$key] : '';
	}

	// --------------------------------------------------

	private static function add_array(array $arr) // void
	{
		self::$loaded = \array_merge(self::$loaded, $arr);
	}
}
