https://wiki.uniformserver.com/index.php?title=US_Tray_Menu_2:_Language_support&feed=atom&action=historyUS Tray Menu 2: Language support - Revision history2024-03-28T08:18:42ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=US_Tray_Menu_2:_Language_support&diff=4258&oldid=prevRic: New page: {{Nav US Tray Menu 2}} '''''US Tray Menu 2 Language support''''' == Introduction == Real purpose of creating a new tray menu is multi-language support. WinBinder makes this easy. Our tray ...2010-06-27T13:37:54Z<p>New page: {{Nav US Tray Menu 2}} '''''US Tray Menu 2 Language support''''' == Introduction == Real purpose of creating a new tray menu is multi-language support. WinBinder makes this easy. Our tray ...</p>
<p><b>New page</b></p><div>{{Nav US Tray Menu 2}}<br />
'''''US Tray Menu 2 Language support'''''<br />
== Introduction ==<br />
Real purpose of creating a new tray menu is multi-language support.<br />
WinBinder makes this easy. Our tray menu's configuration file is saved, as a UTF-8 file hence is inherently multilingual.<br />
<br />
An interesting dilemma! Mentioned on the [[US Tray Menu 2: Implementation | previous page]] are pop-up message boxes. These were hard coded with a specific language, even worse embedded within our scripts.<br />
<br />
Other than being lazy there is no real excuse for this. Although it was not possible to implement on a old version of UniTray we now have a real opportunity to move forward. Uniform Server already has a structure in place for Apanel that supports a multilingual implementation.<br />
<br />
This page looks at applying that solution to our new tray menu.<br />
<br />
== Example ==<br />
Following small code extract demonstrates language support<br />
<br />
'''''[[#top | Top]]'''''<br />
=== Hard coded example ===<br />
The following code displays Apanel in the default browser. If Apache is not running and a user clicks menu item an alert pop-up is generated. Text displayed is hard coded within the nested if statments.<br />
<br />
<pre><br />
//== Command cmd_apanel<br />
if($command_array[0] == "cmd_apanel"){ // Intercept command<br />
if(apache_running()){ // Is Apache running<br />
$cmd = "php.exe -n unitray_info.php 1" ; // Cmd to run hidden<br />
run_cmd_hidden($cmd); // Run command<br />
}<br />
else{ // No:<br />
$str = "To enable and run this menu item\n";<br />
$str .= "please start Apache server.";<br />
wb_message_box (NULL, $str, "Unavailable"); <br />
}<br />
}<br />
//== End command cmd_apanel<br />
</pre><br />
String “str” can be translate and file saved in UTF-8 format.<br />
<br />
This makes sense for a small number of strings. Translating a large number of strings scattered across several scripts is very inconvenient.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
=== Common language script ===<br />
Solution is to relocate all strings into a common script. This removes tedium of finding all strings to be translate.<br />
<br />
Common script contains a single array '''''$TM''''' (TrayMenu) with the following format:<br />
<pre><br />
<?php<br />
<br />
$TM = array(<br />
'title' => 'Uniform Server',<br />
<br />
//-----------------------------------------------------------------------------<br />
// Apanel Menu Item<br />
//-----------------------------------------------------------------------------<br />
<br />
'cmd_apanel-title' => 'Apanel Unavailable',<br />
'cmd_apanel-str' => '<br />
要启用并运行此菜单项<br />
请启动Apache服务器.',<br />
<br />
//-----------------------------------------------------------------------------<br />
// Add new sections as required<br />
//-----------------------------------------------------------------------------<br />
<br />
); //END <br />
?><br />
</pre><br />
The above shows a small section original English version was:<br />
<pre><br />
//-----------------------------------------------------------------------------<br />
// Apanel Menu Item<br />
//-----------------------------------------------------------------------------<br />
<br />
'cmd_apanel-title' => 'Apanel Unavailable',<br />
'cmd_apanel-str' => '<br />
To enable and run this menu item<br />
please start Apache server.',<br />
</pre><br />
<br />
=== Target language array ===<br />
With the language script in place all that is required is to targets elements contained in the language array.<br />
<br />
For example original script is modified to target strings in the language array as shown below:<br />
<pre><br />
//== Command cmd_apanel<br />
if($command_array[0] == "cmd_apanel"){ // Intercept command<br />
if(apache_running()){ // Is Apache running<br />
$cmd = "php.exe -n unitray_info.php 1" ; // Cmd to run hidden<br />
run_cmd_hidden($cmd); // Run command<br />
}<br />
else{ // No:<br />
wb_message_box (NULL, $TM['cmd_apanel-str'], $TM['cmd_apanel-title']); <br />
}<br />
}<br />
//== End command cmd_apanel<br />
</pre><br />
Language file location: UniServer\unicon\tray_menu_2\lang\'''English.php'''<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
<br />
== Implementation ==<br />
<br />
OK! That file (English.php) would be hard coded making it difficult for language switching at a later date.<br />
<br />
Instead of using file English.php use a generic name such as lang.php. Hard coding this has the advantage that any file translated can be renamed to lang.php.<br />
<br />
Advantage we have file English.php for reference, translators can copy this and save with an appropriate name.<br />
<br />
Switching is easy, delete file lang.php copy and rename one of the translated files to lang.php. This can be done either manually or; automatically by providing a menu with a list of language options.<br />
<br />
'''''[[#top | Top]]'''''<br />
== Summary ==<br />
Adding language support is not difficult especially at the coding stage.<br />
<br />
Essentially that covers modifications required to convert our static menu into a dynamic version.<br />
<br />
[[US Tray Menu 2: cmd problem | '''Next page''']] is a slight digression if covers dreaded command window pop-ups<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric