PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 2.0.5
Tracking Code Manager v2.0.5
trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / classes / utils / Language.php
tracking-code-manager / includes / classes / utils Last commit date
Cron.php 4 years ago Ecommerce.php 4 years ago Language.php 4 years ago Logger.php 4 years ago MobileDetect.php 4 years ago Options.php 4 years ago Plugin.php 4 years ago Properties.php 4 years ago Tracking.php 4 years ago Utils.php 4 years ago
Language.php
113 lines
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class TCMP_Language {
5 var $domain;
6 var $bundle;
7
8 function __construct() {
9 $this->bundle=new TCMP_Properties();
10 }
11 function load($domain, $file) {
12 $this->domain=$domain;
13 $this->bundle->load($file);
14 }
15 //echo the $ec->Lang->L result
16 function P($key, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
17 $what=$this->L($key, $v1, $v2, $v3, $v4, $v5);
18 echo $what;
19 }
20 //verify if the key is defined or not
21 function H($key) {
22 if($this->bundle==NULL || !$this->bundle->hasKeys()) {
23 return FALSE;
24 }
25
26 $result=FALSE;
27 if($this->bundle->existsKey($key)) {
28 $result=TRUE;
29 } elseif($this->bundle->existsKey($key.'1')) {
30 $result=TRUE;
31 } else {
32 //special way to call this function passing arguments
33 //WTF_something means key=WTF and something as first argument
34 $s=strpos($result, '_');
35 if ($s!==FALSE) {
36 $text=substr($result, 0, $s);
37 $value=substr($result, $s + 1);
38 $e=strrpos($value, '_');
39 if ($e!==FALSE) {
40 $text.=substr($value, $e + 1);
41 $value=substr($value, 0, $e);
42 }
43 if ($this->bundle->existsKey($text)) {
44 $result=TRUE;
45 }
46 }
47 }
48 return $result;
49 }
50 //read the key from a text file with its translation. Try to translate using __(
51 function L($key, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
52 global $tcmp;
53 $result=$key;
54 $args=array($v1, $v2, $v3, $v4, $v5);
55
56 if($this->bundle==NULL || !$this->bundle->hasKeys()) {
57 $result=__($result, $this->domain);
58 } else {
59 //i use the file to store the translations without writing it inside the code
60 if ($this->bundle->existsKey($key)) {
61 $result=$this->bundle->getString($key);
62 $result=__($result, $this->domain);
63 } elseif ($this->bundle->existsKey($key.'1')) {
64 $result='';
65 $n=1;
66 while ($this->bundle->existsKey($key.$n)) {
67 if ($result != '') {
68 $result .= '<br/>';
69 }
70 $result .= __($this->bundle->getString($key . $n), $this->domain);
71 ++$n;
72 }
73 } else {
74 //special way to call this function passing arguments
75 //WTF_something means key=WTF and something as first argument
76 $s=strpos($result, '_');
77 if ($s!==FALSE) {
78 $text=substr($result, 0, $s);
79 $value=substr($result, $s + 1);
80 $e=strrpos($value, '_');
81 if ($e!==FALSE) {
82 $text .= substr($value, $e + 1);
83 $value=substr($value, 0, $e);
84 }
85 if ($this->bundle->existsKey($text)) {
86 $result=$this->bundle->getString($text);
87 $args=array($value);
88 }
89 }
90 $result=__($result, $this->domain);
91 }
92 }
93 if($result==$key) {
94 $this->bundle->pushString($key, '');
95 }
96 //here i translate it using WP
97 foreach($args as $k=>$v) {
98 $k='{'.$k.'}';
99 while(strpos($result, $k)!==FALSE) {
100 $result=str_replace($k, $v, $result);
101 }
102 }
103 foreach($args as $k=>$v) {
104 $k='{dt:'.$k.'}';
105 $v=$tcmp->Utils->formatSmartDatetime($v);
106 while(strpos($result, $k)!==FALSE) {
107 $result=str_replace($k, $v, $result);
108 }
109 }
110 return $result;
111 }
112 }
113