21require
'../../../../../../main.inc.php';
31if ($user->socid > 0) {
36require_once DOL_DOCUMENT_ROOT .
'/admin/tools/ui/class/documentation.class.php';
39$langs->load(
'uxdocumentation');
43$group =
'ExperimentalUx';
44$experimentName =
'UxDolibarrContextLangsTool';
46$experimentAssetsPath = $documentation->baseUrl .
'/experimental/experiments/dolibarr-context/assets/';
48 '/includes/ace/src/ace.js',
49 '/includes/ace/src/ext-statusbar.js',
50 '/includes/ace/src/ext-language_tools.js',
51 $experimentAssetsPath .
'/dolibarr-context.umd.js',
52 $experimentAssetsPath .
'/dolibarr-tool.langs.js',
53 $experimentAssetsPath .
'/dolibarr-tool.seteventmessage.js',
58$documentation->docHeader($langs->trans($experimentName, $group), $js, $css);
61$documentation->view = [$group,
'UxDolibarrContext', $experimentName];
64$documentation->showSidebar(); ?>
66 Dolibarr.setContextVars(<?php print json_encode([
67 'DOL_VERSION' => DOL_VERSION,
68 'MAIN_LANG_DEFAULT' => $langs->getDefaultLang(),
69 'DOL_LANG_INTERFACE_URL' =>
dol_buildpath(
'admin/tools/ui/experimental/experiments/dolibarr-context/langs-tool-interface.php', 1),
72<div
class=
"doc-wrapper">
74 <?php $documentation->showBreadCrumb(); ?>
76 <div
class=
"doc-content-wrapper">
78 <h1
class=
"documentation-title"><?php echo $langs->trans($experimentName); ?></h1>
80 <?php $documentation->showSummary(); ?>
82 <div
class=
"documentation-section">
83 <h2
id=
"titlesection-basicusage" class=
"documentation-title">Introduction</h2>
86 The Dolibarr
Context Langs Tool is a powerful JavaScript utility to manage translations and locales dynamically.<br/>
87 It allows you to load translation domains,
set the current language, clear cache, and retrieve translated strings in your scripts.
92 <div
class=
"documentation-section">
93 <h2
id=
"titlesection-setup-contextvars" class=
"documentation-title">
Setup Context Variables</h2>
95 Before
using the tool, you should declare the necessary context variables on your page.<br/>
96 These variables allow the tool to know the current Dolibarr version, the
default language, and the
interface URL used to fetch translations.
99 However, like the
setEventMessage tool, the Langs tool is a core tool and is always loaded by Dolibarr.<br/>
100 Therefore, in most cases, you do not need to set these variables manually, as they are already defined.
102 <div class=
"documentation-example">
107 'Dolibarr.setContextVars(<?php print json_encode([',
108 ' \'DOL_VERSION\' => DOL_VERSION,',
109 ' \'MAIN_LANG_DEFAULT\' => $langs->getDefaultLang(),',
110 ' \'DOL_LANG_INTERFACE_URL\' => dol_buildpath(\'admin/tools/ui/experimental/experiments/dolibarr-context/langs-tool-interface.php\',1),',
114 echo $documentation->showCode($lines,
'php');
119 <div
class=
"documentation-section">
120 <h2
id=
"titlesection-basic-usage" class=
"documentation-title">Basic Usage</h2>
122 The main features of the Langs tool are:
125 <li>Load translations
for a specific domain with caching</li>
126 <li>Set or change the current locale</li>
127 <li>Clear cached translations</li>
128 <li>Retrieve a translated
string by key</li>
133 <div
class=
"documentation-example">
137 'document.addEventListener(\'Dolibarr:Ready\', async function(e) {',
139 ' if(Dolibarr.checkToolExist(\'langs\')){ // not mandatory because langs tool will be a core tool',
142 ' Dolibarr.tools.langs.load(\'uxdocumentation\'); // will use cache but need to load lang in new local',
145 ' document.getElementById(\'clearCache\').addEventListener(\'click\', async function(e) {',
146 ' await Dolibarr.tools.langs.clearCache();',
147 ' const txt = Dolibarr.tools.langs.trans(\'CacheCleared\');',
148 ' Dolibarr.tools.setEventMessage(txt);',
151 ' // SET lang in fr_FR',
152 ' document.getElementById(\'setlangFr\').addEventListener(\'click\', async function(e) {',
153 ' await Dolibarr.tools.langs.setLocale(\'fr_FR\');',
154 ' const txt = Dolibarr.tools.langs.trans(\'LangsLocalChangedTo\', \'fr_FR\');',
155 ' Dolibarr.tools.setEventMessage(txt);',
158 ' // SET lang in en_US',
159 ' document.getElementById(\'setlangEn\').addEventListener(\'click\', async function(e) {',
160 ' await Dolibarr.tools.langs.setLocale(\'en_US\');',
161 ' const txt = Dolibarr.tools.langs.trans(\'LangsLocalChangedTo\', \'en_US\');',
162 ' Dolibarr.tools.setEventMessage(txt);',
165 ' // pop a message in current lang',
166 ' document.getElementById(\'popmessage\').addEventListener(\'click\', async function(e) {',
167 ' const txt = Dolibarr.tools.langs.trans(\'ContextLangToolTest\');',
168 ' Dolibarr.tools.setEventMessage(txt);',
174 echo $documentation->showCode($lines,
'php');
176 print implode(
"\n", $lines);
178 <p>1. Set the current lang</p>
180 <
button id=
"setlangFr" class=
"button">Set lang in french</
button>
181 <
button id=
"setlangEn" class=
"button">Set lang in english</
button>
182 <
button id=
"clearCache" class=
"button">Clear cache</
button>
185 <p>2. Pop translated message</p>
187 <
button id=
"popmessage" class=
"button">pop message</
button>
206$documentation->docFooter();
Class to manage UI documentation.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getNonce()
Return a random string to be used as a nonce value for js.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.