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