Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controler/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once __DIR__ . '/functions/tirage.php';
require_once __DIR__ . '/functions/consommation.php';
require_once __DIR__ . '/functions/utilities.php';
require_once __DIR__ . '/functions/translation.php';

// Définir le mode développement
define('DEVELOPMENT_MODE', true);
Expand Down
170 changes: 170 additions & 0 deletions controler/functions/translation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
/**
* Module de traduction pour l'application Duplicator
*
* Ce module gère la traduction des textes de l'interface utilisateur
* en français et en anglais.
*/

// Configuration des langues supportées
define('SUPPORTED_LANGUAGES', ['fr', 'en']);
define('DEFAULT_LANGUAGE', 'fr');

// Variable globale pour la langue actuelle
$current_language = DEFAULT_LANGUAGE;

// Charger la langue depuis la session ou les paramètres
if (session_status() === PHP_SESSION_NONE) {
session_start();
}

if (isset($_GET['lang']) && in_array($_GET['lang'], SUPPORTED_LANGUAGES)) {
$current_language = $_GET['lang'];
$_SESSION['language'] = $current_language;
} elseif (isset($_SESSION['language']) && in_array($_SESSION['language'], SUPPORTED_LANGUAGES)) {
$current_language = $_SESSION['language'];
} else {
// Détecter la langue du navigateur
$browser_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'fr', 0, 2);
if (in_array($browser_lang, SUPPORTED_LANGUAGES)) {
$current_language = $browser_lang;
}
$_SESSION['language'] = $current_language;
}

// Tableau des traductions
$translations = [];

/**
* Charger les traductions depuis les fichiers de langue
*
* @param string $lang Code de la langue (fr, en)
* @return array Tableau des traductions
*/
function load_translations(string $lang): array
{
global $translations;

$lang_file = __DIR__ . "/../../lang/{$lang}.php";

if (file_exists($lang_file)) {
$translations = include $lang_file;
} else {
// Fallback vers le français si la langue n'existe pas
$fallback_file = __DIR__ . "/../../lang/fr.php";
if (file_exists($fallback_file)) {
$translations = include $fallback_file;
} else {
$translations = [];
}
}

return $translations;
}

/**
* Fonction de traduction principale
*
* @param string $key Clé de traduction
* @param array $params Paramètres pour le remplacement (optionnel)
* @return string Texte traduit
*/
function _($key, array $params = []): string
{
global $current_language, $translations;

// Charger les traductions si pas encore fait
if (empty($translations)) {
$translations = load_translations($current_language);
}

// Récupérer la traduction
$translation = $translations[$key] ?? $key;

// Remplacer les paramètres si fournis
if (!empty($params)) {
foreach ($params as $param_key => $param_value) {
$translation = str_replace("{{$param_key}}", $param_value, $translation);
}
}

return $translation;
}

/**
* Obtenir la langue actuelle
*
* @return string Code de la langue actuelle
*/
function get_current_language(): string
{
global $current_language;
return $current_language;
}

/**
* Obtenir la liste des langues supportées
*
* @return array Liste des codes de langue
*/
function get_supported_languages(): array
{
return SUPPORTED_LANGUAGES;
}

/**
* Obtenir le nom de la langue en français
*
* @param string $lang_code Code de la langue
* @return string Nom de la langue
*/
function get_language_name(string $lang_code): string
{
$names = [
'fr' => 'Français',
'en' => 'English'
];

return $names[$lang_code] ?? $lang_code;
}

/**
* Générer l'URL pour changer de langue
*
* @param string $lang_code Code de la langue
* @return string URL complète
*/
function get_language_url(string $lang_code): string
{
$current_url = $_SERVER['REQUEST_URI'];
$parsed_url = parse_url($current_url);

// Supprimer le paramètre lang existant
if (isset($parsed_url['query'])) {
parse_str($parsed_url['query'], $query_params);
unset($query_params['lang']);
} else {
$query_params = [];
}

// Ajouter le nouveau paramètre lang
$query_params['lang'] = $lang_code;

// Reconstruire l'URL
$new_query = http_build_query($query_params);
$new_url = $parsed_url['path'];
if (!empty($new_query)) {
$new_url .= '?' . $new_query;
}

return $new_url;
}

// Charger les traductions au chargement du module
load_translations($current_language);

// Log de l'initialisation
if (function_exists('log_info')) {
log_info("Module de traduction initialisé - Langue: {$current_language}", 'translation.php');
}
?>
120 changes: 120 additions & 0 deletions lang/en.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
/**
* English translation file for Duplicator
*
* This file contains all English translations
* for the application user interface.
*/

return [
// Navigation and header
'nav.previous' => 'Previous',
'nav.duplicator' => 'Duplicator.',
'nav.pdf_tools' => 'PDF Tools',
'nav.new_print' => 'New Print',
'nav.change_report' => 'Change Report',
'nav.help_tutorials' => 'Help & Tutorials',
'nav.statistics' => 'Statistics',
'nav.administration' => 'Administration',

// PDF Tools
'tools.impose' => 'Impose',
'tools.impose.description' => 'Create an A3 booklet',
'tools.unimpose' => 'Unimpose',
'tools.unimpose.description' => 'Transform a booklet into normal pages',
'tools.impose_tracts' => 'Tract Imposition',
'tools.impose_tracts.description' => 'Duplicate and optimize your tracts',
'tools.images_to_pdf' => 'Images → PDF',
'tools.images_to_pdf.description' => 'Convert PNG/JPG to PDF A3/A4',
'tools.pdf_to_images' => 'PDF → Images',
'tools.pdf_to_images.description' => 'Extract pages as PNG',
'tools.riso_separator' => 'Riso Separator',
'tools.riso_separator.description' => 'Separate colors for multi-drum',
'tools.fill_rate' => 'Fill Rate',
'tools.fill_rate.description' => 'Calculate ink usage percentage',

// Home page
'home.welcome' => 'Welcome duplicator',
'home.multi_machine_print' => 'Multi-Machine Print',
'home.multi_machine_print.description' => 'Record your print on all available machines and optimize your prints!',
'home.useful_info' => 'Useful Information',
'home.mailing_list' => 'Subscribe to the Mailing List',
'home.email_placeholder' => 'email',

// Administration
'admin.title' => 'Administration',
'admin.machines.title' => 'Machine Management',
'admin.machines.manage' => 'Machine Management',
'admin.machines.manage.description' => 'Duplicators and photocopiers',
'admin.changes.manage' => 'Change Management',
'admin.changes.manage.description' => 'Ink, master, toner',
'admin.prices.manage' => 'Price Management',
'admin.prices.manage.description' => 'Rates and consumables',
'admin.prints.manage' => 'Print Management',
'admin.prints.manage.description' => 'View and modify prints',

'admin.content.title' => 'Content Management',
'admin.help.manage' => 'Help Management',
'admin.help.manage.description' => 'Help by machine',
'admin.news.manage' => 'News Management',
'admin.news.manage.description' => 'News and information',
'admin.stats.manage' => 'Statistics Management',
'admin.stats.manage.description' => 'Statistics texts and messages',
'admin.emails.manage' => 'Email Management',
'admin.emails.manage.description' => 'Mailing list',

'admin.security.title' => 'Security',
'admin.passwords.manage' => 'Password Management',
'admin.passwords.manage.description' => 'Security and access',
'admin.database.manage' => 'Database Management',
'admin.database.manage.description' => 'Creation, backup, restoration',

'admin.back_home' => 'Back to Home',

// Password management
'passwords.title' => 'Password Management',
'passwords.change.title' => 'Change Password',
'passwords.current' => 'Current password:',
'passwords.new' => 'New password:',
'passwords.confirm' => 'Confirm new password:',
'passwords.min_length' => 'Minimum 6 characters',
'passwords.change_button' => 'Change Password',
'passwords.info.title' => 'Information',
'passwords.security' => 'Security:',
'passwords.security.stored' => 'Password is stored securely',
'passwords.security.bcrypt' => 'Uses bcrypt hashing',
'passwords.security.old_deleted' => 'Old passwords deleted',
'passwords.recommendations' => 'Recommendations:',
'passwords.recommendations.length' => 'Use at least 8 characters',
'passwords.recommendations.mix' => 'Mix letters, numbers and symbols',
'passwords.recommendations.avoid' => 'Avoid common passwords',
'passwords.navigation.title' => 'Navigation',
'passwords.back_admin' => 'Back to Administration',

// Error messages
'error.title' => 'An error occurred',
'error.message' => 'Sorry, an unexpected error occurred while processing your request.',
'error.technical_details' => 'Technical Details',
'error.file' => 'File:',
'error.line' => 'Line:',
'error.stack_trace' => 'Stack trace:',
'error.url' => 'URL:',
'error.what_to_do' => 'What would you like to do?',
'error.back_home' => 'Back to Home',
'error.previous_page' => 'Previous Page',
'error.reload' => 'Reload Page',

// Footer
'footer.coded_with_love' => 'Coded with ❤️ for Duplicator. Source:',
'footer.github' => 'GitHub',

// Validation messages
'validation.passwords_not_match' => 'The new passwords do not match.',
'validation.password_too_short' => 'The new password must contain at least 6 characters.',
'validation.passwords_not_match_realtime' => 'The passwords do not match.',

// Languages
'language.french' => 'Français',
'language.english' => 'English',
'language.selector' => 'Language',
];
Loading