Skip to content

Commit 37abd10

Browse files
authored
Add Lang Model
1 parent 2e465d8 commit 37abd10

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

App/Models/Lang.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Monster\App\Models;
4+
5+
class Lang
6+
{
7+
private $language;
8+
private $langData;
9+
10+
public function __construct($language = "en")
11+
{
12+
$this->language = $language;
13+
$this->loadLanguageData();
14+
}
15+
16+
public function loadLanguageData()
17+
{
18+
$langFile = __DIR__ . '/../../routes/lang/' . $this->language . '.php';
19+
if (file_exists($langFile)) {
20+
$this->langData = include $langFile;
21+
} else {
22+
throw new \Exception("Language file not found for {$this->language}");
23+
}
24+
}
25+
26+
public function get($key, $variables = [])
27+
{
28+
$value = $this->langData[$key] ?? $key;
29+
30+
foreach ($variables as $variable => $replacement) {
31+
$value = str_replace(':' . $variable, $replacement, $value);
32+
}
33+
34+
return $value;
35+
}
36+
}

0 commit comments

Comments
 (0)