-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlang.php
More file actions
45 lines (37 loc) · 1.05 KB
/
Copy pathlang.php
File metadata and controls
45 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Language API Endpoint
*
* Returns translations for the specified language
*
* @license GPL-3.0
*/
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
try {
// Get language from query parameter (default: en)
$lang = $_GET['lang'] ?? 'en';
// Sanitize language code (only allow a-z, 2 characters)
if (!preg_match('/^[a-z]{2}$/', $lang)) {
$lang = 'en';
}
// Check if language file exists
$langFile = __DIR__ . '/lang/' . $lang . '.php';
if (!file_exists($langFile)) {
throw new Exception("Language file not found: {$lang}");
}
// Load language file
$translations = require $langFile;
// Response
echo json_encode([
'success' => true,
'lang' => $lang,
'translations' => $translations
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
} catch (Exception $e) {
http_response_code(404);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}