admin
11 years ago
actions.php
11 years ago
class-TCM-check.php
11 years ago
class-TCM-cron.php
11 years ago
class-TCM-form.php
11 years ago
class-TCM-language.php
11 years ago
class-TCM-logger.php
11 years ago
class-TCM-manager.php
11 years ago
class-TCM-options.php
11 years ago
class-TCM-tracking.php
11 years ago
class-TCM-utils.php
11 years ago
core.php
11 years ago
install.php
11 years ago
uninstall.php
11 years ago
class-TCM-language.php
126 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | |
| 4 | class TCM_Language { |
| 5 | var $domain; |
| 6 | function load($domain, $file) { |
| 7 | $this->domain=$domain; |
| 8 | if(!file_exists($file)) { |
| 9 | return; |
| 10 | } |
| 11 | $file=file_get_contents($file); |
| 12 | if($file!=NULL && strlen($file)>0) { |
| 13 | $bundle=array(); |
| 14 | $file=str_replace("\r\n", "\n", $file); |
| 15 | $file=str_replace("\n\n", "\n", $file); |
| 16 | $file=explode("\n", $file); |
| 17 | |
| 18 | foreach($file as $row) { |
| 19 | $index=strpos($row, "="); |
| 20 | if($index===FALSE) continue; |
| 21 | |
| 22 | $k=trim(substr($row, 0, $index)); |
| 23 | $v=trim(substr($row, $index+1)); |
| 24 | $bundle[$k]=$v; |
| 25 | } |
| 26 | |
| 27 | global $wp_session; |
| 28 | $wp_session['LanguageBundle_'.$domain]=$bundle; |
| 29 | } |
| 30 | } |
| 31 | //echo the $tcm->Lang->L result |
| 32 | function P($key, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) { |
| 33 | $what=$this->L($key, $v1, $v2, $v3, $v4, $v5); |
| 34 | echo $what; |
| 35 | } |
| 36 | //verify if the key is defined or not |
| 37 | function H($key) { |
| 38 | global $wp_session; |
| 39 | $bundle=$wp_session['LanguageBundle_'.$this->domain]; |
| 40 | if($bundle==NULL || count($bundle)==0) { |
| 41 | return FALSE; |
| 42 | } |
| 43 | |
| 44 | $result=FALSE; |
| 45 | if(isset($bundle[$key])) { |
| 46 | $result=TRUE; |
| 47 | } elseif(isset($bundle[$key.'1'])) { |
| 48 | $result=TRUE; |
| 49 | } else { |
| 50 | //special way to call this function passing arguments |
| 51 | //WTF_something means key=WTF and something as first argument |
| 52 | if(strpos($result, '_')!==FALSE) { |
| 53 | $what = explode('_', $result); |
| 54 | $array = array(); |
| 55 | $text = ''; |
| 56 | for ($i = 0; $i < count($what); $i++) { |
| 57 | if ($i % 2 == 0) { |
| 58 | $text .= $what[$i]; |
| 59 | } else { |
| 60 | $array[] = $what[$i]; |
| 61 | } |
| 62 | } |
| 63 | if (isset($bundle[$text])) { |
| 64 | $result=TRUE; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | return $result; |
| 69 | } |
| 70 | //read the key from a text file with its translation. Try to translate using __( |
| 71 | function L($key, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) { |
| 72 | global $wp_session; |
| 73 | $bundle=$wp_session['LanguageBundle_'.$this->domain]; |
| 74 | $result = $key; |
| 75 | $args = array($v1, $v2, $v3, $v4, $v5); |
| 76 | |
| 77 | if($bundle==NULL || count($bundle)==0) { |
| 78 | $result=__($result, $this->domain); |
| 79 | } else { |
| 80 | //i use the file to store the translations without writing it inside the code |
| 81 | if (isset($bundle[$key])) { |
| 82 | $result = $bundle[$key]; |
| 83 | $result = __($result, $this->domain); |
| 84 | } elseif (isset($bundle[$key . '1'])) { |
| 85 | $result = ''; |
| 86 | $n = 1; |
| 87 | while (isset($bundle[$key . $n])) { |
| 88 | if ($result != '') { |
| 89 | $result .= '<br/>'; |
| 90 | } |
| 91 | $result .= __($bundle[$key . $n], $this->domain); |
| 92 | ++$n; |
| 93 | } |
| 94 | } else { |
| 95 | //special way to call this function passing arguments |
| 96 | //WTF_something means key=WTF and something as first argument |
| 97 | if (strpos($result, '_') !== FALSE) { |
| 98 | $what = explode('_', $result); |
| 99 | $array = array(); |
| 100 | $text = ''; |
| 101 | for ($i = 0; $i < count($what); $i++) { |
| 102 | if ($i % 2 == 0) { |
| 103 | $text .= $what[$i]; |
| 104 | } else { |
| 105 | $array[] = $what[$i]; |
| 106 | } |
| 107 | } |
| 108 | if (isset($bundle[$text])) { |
| 109 | $result = $bundle[$text]; |
| 110 | $args = $array; |
| 111 | } |
| 112 | } |
| 113 | $result = __($result, $this->domain); |
| 114 | } |
| 115 | } |
| 116 | //here i translate it using WP |
| 117 | foreach($args as $k=>$v) { |
| 118 | $k='{'.$k.'}'; |
| 119 | while(strpos($result, $k)!==FALSE) { |
| 120 | $result=str_replace($k, $v, $result); |
| 121 | } |
| 122 | } |
| 123 | return $result; |
| 124 | } |
| 125 | } |
| 126 |