mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-16 06:13:47 +02:00
Added basic panel translation functions
This commit is contained in:
parent
5cc5c72ea4
commit
9608234596
6 changed files with 37 additions and 3 deletions
|
@ -8,6 +8,8 @@ use Slim\Handlers\Strategies\RequestResponseArgs;
|
||||||
use Slim\Views\Twig;
|
use Slim\Views\Twig;
|
||||||
use Slim\Views\TwigMiddleware;
|
use Slim\Views\TwigMiddleware;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
use Gettext\Loader\PoLoader;
|
||||||
|
use Gettext\Translations;
|
||||||
|
|
||||||
if (session_status() == PHP_SESSION_NONE) {
|
if (session_status() == PHP_SESSION_NONE) {
|
||||||
session_start();
|
session_start();
|
||||||
|
@ -42,6 +44,22 @@ $routeParser = $app->getRouteCollector()->getRouteParser();
|
||||||
|
|
||||||
require_once __DIR__ . '/database.php';
|
require_once __DIR__ . '/database.php';
|
||||||
|
|
||||||
|
$desiredLanguage = 'en_US'; // Default language
|
||||||
|
|
||||||
|
// Check for a URL parameter
|
||||||
|
if (isset($_GET['lang'])) {
|
||||||
|
$desiredLanguage = $_GET['lang'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$languageFile = '../lang/' . $desiredLanguage . '/messages.po';
|
||||||
|
if (!file_exists($languageFile)) {
|
||||||
|
$desiredLanguage = 'en_US'; // Fallback
|
||||||
|
$languageFile = '../lang/en_US/messages.po';
|
||||||
|
}
|
||||||
|
|
||||||
|
$loader = new PoLoader();
|
||||||
|
$translations = $loader->loadFile($languageFile);
|
||||||
|
|
||||||
$container->set('router', function () use ($routeParser) {
|
$container->set('router', function () use ($routeParser) {
|
||||||
return $routeParser;
|
return $routeParser;
|
||||||
});
|
});
|
||||||
|
@ -62,7 +80,7 @@ $container->set('flash', function() {
|
||||||
return new \Slim\Flash\Messages;
|
return new \Slim\Flash\Messages;
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->set('view', function ($container) {
|
$container->set('view', function ($container) use ($translations) {
|
||||||
$view = Twig::create(__DIR__ . '/../resources/views', [
|
$view = Twig::create(__DIR__ . '/../resources/views', [
|
||||||
'cache' => false,
|
'cache' => false,
|
||||||
]);
|
]);
|
||||||
|
@ -76,6 +94,17 @@ $container->set('view', function ($container) {
|
||||||
} else {
|
} else {
|
||||||
$view->getEnvironment()->addGlobal('screen_mode', 'light');
|
$view->getEnvironment()->addGlobal('screen_mode', 'light');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$translateFunction = new TwigFunction('__', function ($text) use ($translations) {
|
||||||
|
// Find the translation
|
||||||
|
$translation = $translations->find(null, $text);
|
||||||
|
if ($translation) {
|
||||||
|
return $translation->getTranslation();
|
||||||
|
}
|
||||||
|
// Return the original text if translation not found
|
||||||
|
return $text;
|
||||||
|
});
|
||||||
|
$view->getEnvironment()->addFunction($translateFunction);
|
||||||
|
|
||||||
//route
|
//route
|
||||||
$route = new TwigFunction('route', function ($name) {
|
$route = new TwigFunction('route', function ($name) {
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
"imefisto/psr-swoole-native": "^1.1",
|
"imefisto/psr-swoole-native": "^1.1",
|
||||||
"chubbyphp/chubbyphp-static-file": "^1.2",
|
"chubbyphp/chubbyphp-static-file": "^1.2",
|
||||||
"lasserafn/php-initial-avatar-generator": "^4.2",
|
"lasserafn/php-initial-avatar-generator": "^4.2",
|
||||||
"mevdschee/php-crud-api": "^2.14"
|
"mevdschee/php-crud-api": "^2.14",
|
||||||
|
"gettext/gettext": "^5.7"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
2
cp/lang/en_US/messages.po
Normal file
2
cp/lang/en_US/messages.po
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
msgid "Dashboard"
|
||||||
|
msgstr "Dashboard"
|
BIN
cp/lang/uk_UA/messages.mo
Normal file
BIN
cp/lang/uk_UA/messages.mo
Normal file
Binary file not shown.
2
cp/lang/uk_UA/messages.po
Normal file
2
cp/lang/uk_UA/messages.po
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
msgid "Dashboard"
|
||||||
|
msgstr "Панель керування"
|
|
@ -14,7 +14,7 @@
|
||||||
Overview
|
Overview
|
||||||
</div>
|
</div>
|
||||||
<h2 class="page-title">
|
<h2 class="page-title">
|
||||||
Dashboard
|
{{ __('Dashboard') }}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<!-- Page title actions -->
|
<!-- Page title actions -->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue