2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.lang.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class TplAppLang
12 *
13 * This class provides methods to generate and manage language-related menu items and actions
14 * within the Bearsampp application. It includes functionalities for creating language switch
15 * actions and processing language menus.
16 */
18{
19 // Constant for the language menu identifier
20 const MENU = 'lang';
21
22 /**
23 * Processes and generates the language menu.
24 *
25 * This method generates the language menu for the application, including the available
26 * languages and the actions to be taken when a language is selected.
27 *
28 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
29 *
30 * @return array The generated language menu and actions.
31 */
32 public static function process()
33 {
34 global $bearsamppLang;
35
36 return TplApp::getMenu($bearsamppLang->getValue(Lang::LANG), self::MENU, get_called_class());
37 }
38
39 /**
40 * Generates the language menu items and associated actions.
41 *
42 * This method creates menu items for each available language and defines the actions to be taken
43 * when a language menu item is selected. It uses the global language object to retrieve the list
44 * of available languages and the current language.
45 *
46 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
47 *
48 * @return string The generated language menu items and actions.
49 */
50 public static function getMenuLang()
51 {
52 global $bearsamppLang;
53 $items = '';
54 $actions = '';
55
56 foreach ($bearsamppLang->getList() as $lang) {
57 $tplSwitchLang = TplApp::getActionMulti(
58 Action::SWITCH_LANG, array($lang),
59 array(ucfirst($lang), $lang == $bearsamppLang->getCurrent() ? TplAestan::GLYPH_CHECK : ''),
60 false, get_called_class()
61 );
62
63 // Item
64 $items .= $tplSwitchLang[TplApp::SECTION_CALL] . PHP_EOL;
65
66 // Action
67 $actions .= PHP_EOL . $tplSwitchLang[TplApp::SECTION_CONTENT] . PHP_EOL;
68 }
69
70 return $items . $actions;
71 }
72
73 /**
74 * Generates the action to switch the application language.
75 *
76 * This method creates the action string for switching the application language. It includes
77 * commands to reload the application after the language switch. The action string is used to
78 * define what happens when the switch language action is triggered.
79 *
80 * @param string $lang The language code to switch to.
81 *
82 * @return string The generated action string for switching the language.
83 */
84 public static function getActionSwitchLang($lang)
85 {
86 return TplApp::getActionRun(Action::SWITCH_LANG, array($lang)) . PHP_EOL .
88 }
89}
global $bearsamppLang
const SWITCH_LANG
const LANG
static getActionSwitchLang($lang)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
const SECTION_CALL
const SECTION_CONTENT
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
static getMenu($caption, $menu, $class)