Files
api/services/nginx/app/traits/language_pack_t.php
T
2025-01-29 14:27:44 +01:00

67 lines
1.7 KiB
PHP

<?php
namespace traits;
trait language_pack_t
{
/**
* The language code of the language pack e.g. en_us
* @var string
*/
public string $language; // The language code of the language pack e.g. en_us
/**
* The translations of the language pack
* @var array
*/
protected array $translations = []; // The translations of the language pack
/**
* Get the translation of a string
* @param string $string The string to translate
* @return string The translated string
*/
public function translate(string $string): string
{
return $this->translations[$string] ?? $string;
}
/**
* Get the language code of the language pack
* @return string The language code of the language pack
*/
public function getLanguage(): string
{
return $this->language;
}
/**
* Set the language code of the language pack
* @param string $language The language code of the language pack
*/
public function setLanguage(string $language): void
{
$this->language = $language;
}
/**
* Add multiple translations to the language pack
* @param array $strings The strings to translate
*/
public function addTranslations(array $strings): void
{
foreach ( $strings as $string => $translation ) {
$this->addTranslation($string, $translation);
}
}
/**
* Add a translation to the language pack
* @param string $string The string to translate
*/
public function addTranslation(string $string, string $translation): void
{
$this->translations[$string] = $translation;
}
}