Refactor: migrate files

This commit is contained in:
Jepp9350
2025-01-29 14:27:44 +01:00
parent 4c74dd7995
commit 707df910b0
142 changed files with 371 additions and 9 deletions
@@ -0,0 +1,58 @@
<?php
namespace classes;
use interfaces\language_pack_i;
class language_packs
{
/**
* The language packs
* @var array
*/
protected array $language_packs = [];
protected string $default_language = 'en_us';
public function __construct()
{
$this->loadLanguagePacks();
}
/**
* Load the language packs
*/
protected function loadLanguagePacks(): void
{
$files = glob('languages/*.php');
foreach ( $files as $file ) {
require_once $file;
$class = 'languages\\' . str_replace('.php', '', basename($file));
$this->language_packs[] = new $class();
}
}
/**
* Get the default language pack
* @return language_pack_i The default language pack
*/
public function getDefaultLanguagePack(): object
{
return $this->getLanguagePack($this->default_language);
}
/**
* Get the language pack for a language
* @param string $language The language code of the language pack
* @return language_pack_i The language pack
*/
public function getLanguagePack(string $language): object
{
foreach ( $this->language_packs as $language_pack ) {
if ($language_pack->getLanguage() === $language) {
return $language_pack;
}
}
return $this->getLanguagePack($this->default_language);
}
}