File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments