mirror of
https://github.com/tips-of-mine/GLPI-Plugin-CVE-Prototype.git
synced 2025-06-27 22:58:45 +02:00
78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* GLPI CVE Plugin - Language Definition
|
|
* Handles plugin language loading
|
|
*/
|
|
|
|
if (!defined('GLPI_ROOT')) {
|
|
die("Sorry. You can't access this file directly");
|
|
}
|
|
|
|
// Translation function for the plugin
|
|
function plugin_cve_gettext($text) {
|
|
return $text;
|
|
}
|
|
|
|
// Translation function with plurals
|
|
function plugin_cve_gettextn($singular, $plural, $number) {
|
|
if ($number > 1) {
|
|
return $plural;
|
|
}
|
|
return $singular;
|
|
}
|
|
|
|
/**
|
|
* Get the available languages for the plugin
|
|
*
|
|
* @return array
|
|
*/
|
|
function plugin_cve_getLanguages() {
|
|
return [
|
|
'en_GB' => 'English',
|
|
'fr_FR' => 'Français',
|
|
'de_DE' => 'Deutsch',
|
|
'it_IT' => 'Italiano',
|
|
'pl_PL' => 'Polski',
|
|
'es_ES' => 'Español',
|
|
'pt_PT' => 'Português'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin localization
|
|
*
|
|
* @param string $hook_param Hook parameter
|
|
* @return void
|
|
*/
|
|
function plugin_cve_load_language($hook_param) {
|
|
global $CFG_GLPI;
|
|
|
|
// Get user language
|
|
$user_language = Session::getLanguage();
|
|
|
|
// Path to plugin locales
|
|
$langpath = PLUGIN_CVE_DIR . '/locales/';
|
|
|
|
// Available languages for the plugin
|
|
$languages = plugin_cve_getLanguages();
|
|
|
|
// If user language is not available, fallback to English
|
|
if (!array_key_exists($user_language, $languages)) {
|
|
$user_language = 'en_GB';
|
|
}
|
|
|
|
// Load .mo file for the selected language
|
|
$mofile = $langpath . $user_language . '.mo';
|
|
|
|
// Check if the file exists
|
|
if (file_exists($mofile)) {
|
|
// Load the translation
|
|
load_plugin_textdomain('cve', false, $mofile);
|
|
} else {
|
|
// Try to fallback to English
|
|
$mofile = $langpath . 'en_GB.mo';
|
|
if (file_exists($mofile)) {
|
|
load_plugin_textdomain('cve', false, $mofile);
|
|
}
|
|
}
|
|
} |