@@ 40-59 (lines=20) @@ | ||
37 | * |
|
38 | * @return array |
|
39 | **/ |
|
40 | public static function addNames($codes) |
|
41 | { |
|
42 | // Read and decode JSON |
|
43 | $json_data = json_decode(file_get_contents(__DIR__.'/languages.json'), true); |
|
44 | ||
45 | $array = []; |
|
46 | ||
47 | // Generate an array with $code as key and $code language as value |
|
48 | foreach ($codes as $code) { |
|
49 | $lang_name = 'Unknoun'; |
|
50 | foreach ($json_data as $lang_data) { |
|
51 | if ($lang_data['code'] == $code) { |
|
52 | $lang_name = $lang_data['name']; |
|
53 | } |
|
54 | } |
|
55 | $array[$code] = $lang_name; |
|
56 | } |
|
57 | ||
58 | return $array; |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * Add names to an array of language codes as [$language => $code]. |
|
@@ 68-87 (lines=20) @@ | ||
65 | * |
|
66 | * @return array |
|
67 | **/ |
|
68 | public static function addCodes($langs) |
|
69 | { |
|
70 | // Read and decode JSON |
|
71 | $json_data = json_decode(file_get_contents(__DIR__.'/languages.json'), true); |
|
72 | ||
73 | $array = []; |
|
74 | ||
75 | // Generate an array with $lang as key and $lang code as value |
|
76 | foreach ($langs as $lang) { |
|
77 | $code = 'unk'; |
|
78 | foreach ($json_data as $lang_data) { |
|
79 | if ($lang_data['name'] == $lang) { |
|
80 | $code = $lang_data['code']; |
|
81 | } |
|
82 | } |
|
83 | $array[$lang] = $code; |
|
84 | } |
|
85 | ||
86 | return $array; |
|
87 | } |
|
88 | ||
89 | /** |
|
90 | * Returns the url to set up language and return back. |