source: trunk/Modules/Translation/LoadNames.php@ 843

Last change on this file since 843 was 843, checked in by chronos, 9 years ago
  • Added: Support for translatable URLs. Now each language can have URL in its language.

This requires to all links inside web to use System->Link function which is responsible for translation.
All links need to be written in english so they can be translated to other language.

File size: 4.8 KB
Line 
1<?php
2
3class PageLoadNames extends Page
4{
5 function ReplaceTranslated($orig,$tran,$Text,$ID,$Group)
6 {
7 $tran_replace = str_replace(' ','&nbsp;',htmlspecialchars($tran));
8 $orig_replace = str_replace(' ','&nbsp;',htmlspecialchars($orig));
9
10 // if (strlen($orig) < strlen($Text)-1) {
11 if ($Group <> '')
12 {
13 $Text = str_replace(' '.$orig,' <span Title="Přelož jako:&nbsp;'.$tran_replace.
14 '" class="edit"><a class="edit" target="_NEW2" href="'.$this->System->Link('/form.php?group='.$Group.'&amp;ID='.$ID).'">'.$orig_replace.'</a></span>',$Text);
15 } else {
16 $Text = str_replace(' '.$orig,' <span Title="Přelož jako:&nbsp;'.$tran_replace.
17 '" class="edit"><a class="edit" target="_NEW2" href="'.$this->System->Link('/'.T('dictionary', 'URL').'/?search='.$tran).'">'.$orig_replace.'</a></span>',$Text);
18 }
19 // }
20 return ($Text);
21 }
22 function ReplaceNotTranslated($orig,$tran,$Text,$ID,$Group)
23 {
24 $orig_replace = str_replace(' ','&nbsp;',htmlspecialchars($orig));
25
26 $Text = str_replace(' '.$orig,' <span title="Kliknutím přeložíš" class="needtran"><a class="needtran" target="_NEW2" href="'.
27 $this->System->Link('/form.php?group='.$Group.'&amp;ID='.$ID).'">'.$orig_replace.'</a></span>',$Text);
28 return ($Text);
29 }
30
31 function ColorNames($Text, $names)
32 {
33 $Text = ' '.$Text;
34 $Text = str_replace('$B$B','$B$B ',$Text);
35
36 $Text = str_replace('$B','<span Title="Znamená odřádkování, překladu zachovej na stejné pozici." class="edit">$B</span>',$Text);
37 $Text = str_replace('$N','<span Title="Znamená jméno hráče, překladu zachovej na stejné pozici." class="edit">$N</span>',$Text);
38 $Text = str_replace('$R','<span Title="Znamená rasu hráče, překladu zachovej na stejné pozici." class="edit">$R</span>',$Text);
39 $Text = str_replace('$C','<span Title="Znamená povolání hráče, překladu zachovej na stejné pozici." class="edit">$C</span>',$Text);
40 $Text = str_replace('$G','<span Title="Vybere oslovení podle pohlaví hráče, překladu zachovej na stejné pozici." class="edit">$G</span>',$Text);
41 $Text = str_replace('$b','<span Title="Znamená odřádkování, překladu zachovej na stejné pozici." class="edit">$B</span>',$Text);
42 $Text = str_replace('$n','<span Title="Znamená jméno hráče, překladu zachovej na stejné pozici." class="edit">$N</span>',$Text);
43 $Text = str_replace('$c','<span Title="Znamená povolání hráče, překladu zachovej na stejné pozici." class="edit">$c</span>',$Text);
44 $Text = str_replace('$r','<span Title="Znamená rasu hráče, překladu zachovej na stejné pozici." class="edit">$R</span>',$Text);
45 $Text = str_replace('$g','<span Title="Vybere oslovení podle pohlaví hráče, překladu zachovej na stejné pozici." class="edit">$G</span>',$Text);
46 foreach($names as $Line) {
47 if (($_GET['ID'] <> $Line[0]) or ($Line[1] <> $_GET['GroupId']))
48 if ($Line[3] <> '') {
49 $Text = $this->ReplaceTranslated($Line[2],$Line[3],$Text,$Line[0],$Line[1]);
50
51 } else {
52 $Text = $this->ReplaceNotTranslated($Line[2],$Line[3],$Text,$Line[0],$Line[1]);
53 }
54 }
55 return $Text;
56 }
57
58 function LoadNames()
59 {
60 global $TranslationTree;
61
62 $Output = '';
63 if(array_key_exists('GroupId', $_GET)) $GroupId = $_GET['GroupId'];
64 else return(ShowMessage(T('GroupId not specified'), MESSAGE_CRITICAL));
65 if(!array_key_exists('ID', $_GET)) return(ShowMessage(T('ID not specified'), MESSAGE_CRITICAL));
66 if(!array_key_exists('Column', $_GET)) return(ShowMessage(T('Column not specified'), MESSAGE_CRITICAL));
67 $Table = $TranslationTree[$GroupId]['TablePrefix'];
68 $DbResult = $this->System->Database->query('SELECT * FROM `'.$Table.'` WHERE `ID` = '.$_GET['ID'].' LIMIT 1');
69 $LineAJ = $DbResult->fetch_assoc();
70 $Column = $_GET['Column'];
71 //$Text = $LineAJ[$TranslationTree[$GroupId]['Items'][$_GET['Item']]];
72 $Text = $LineAJ[$Column];
73 $names = array();
74 if ($this->System->User->Licence(LICENCE_USER))
75 if(($GroupId < 4) or ($GroupId == 10) or ($GroupId == 11))
76 {
77 //<span class="edit">barvou.</span>
78 $names = GetTranslatNames($Text, 0, GetTranslatNamesArray());
79 } else {
80 if(($GroupId == 13)) {
81 $names = GetTranslatNames($Text, 0, array('Dictionary' => 'Text', 'TextGlobalString' => 'Text', 'TextArea' => 'Name', 'TextItemSubClass' => 'Name', 'TextCharacterRace' => 'Name1',),false);
82 } else {
83 $names = GetTranslatNames($Text, 0, GetTranslatNamesArray());
84 }
85 }
86 //$LineAJ[$Column]
87 return ($this->ColorNames(htmlspecialchars($Text),$names));
88 }
89
90 function Show()
91 {
92 $this->RawPage = true;
93 return(str_replace("\n", '<br/>', $this->LoadNames()));
94 }
95}
Note: See TracBrowser for help on using the repository browser.