mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 05:25:42 +07:00
Initial Release v1.0.0: Full feature set with Docker automation, Nginx/Alpine stack
This commit is contained in:
45
app/Helpers/LanguageHelper.php
Normal file
45
app/Helpers/LanguageHelper.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class LanguageHelper
|
||||
{
|
||||
/**
|
||||
* Get list of available languages from public/lang directory
|
||||
*
|
||||
* @return array Array of languages with code and name
|
||||
*/
|
||||
public static function getAvailableLanguages()
|
||||
{
|
||||
$langDir = ROOT . '/public/lang';
|
||||
$languages = [];
|
||||
|
||||
if (!is_dir($langDir)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$files = scandir($langDir);
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') continue;
|
||||
|
||||
if (pathinfo($file, PATHINFO_EXTENSION) === 'json') {
|
||||
$code = pathinfo($file, PATHINFO_FILENAME);
|
||||
|
||||
// Read file to get language name if defined, otherwise use code
|
||||
$content = file_get_contents($langDir . '/' . $file);
|
||||
$data = json_decode($content, true);
|
||||
|
||||
$name = $data['_meta']['name'] ?? strtoupper($code);
|
||||
$flag = $data['_meta']['flag'] ?? '🌐';
|
||||
|
||||
$languages[] = [
|
||||
'code' => $code,
|
||||
'name' => $name,
|
||||
'flag' => $flag
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $languages;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user