PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / trunk
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar vtrunk
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / core / wpbm-translation.php

wpbm-translation.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar trunk, at core/wpbm-translation.php

234 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @package Booking Manager
4 * @subpackage Translations Functions
5 * @category Functions
6 *
7 * @author wpdevelop
8 * @link https://oplugins.com/
9 * @email info@oplugins.com
10 *
11 * @modified 29.09.2015
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16 ////////////////////////////////////////////////////////////////////////////////
17 // Transaltions ////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////////
19
20 // New in WP 6.2 - firstly loaded transaltion from wp-content/languges and then chek only
21 // use the override_load_textdomain filter to load your text domains manually.
22 // apply_filters( 'override_load_textdomain', bool $override, string $domain, string $mofile )
23
24 /** Check text for active language section
25 *
26 * @param string $content_orig
27 * @return string
28 * Usage:
29 * $text = apply_wpbm_filter('wpbm_check_for_active_language', $text );
30 */
31 function wpbm_check_for_active_language($content_orig){
32
33 $content = $content_orig;
34
35 $languages = array();
36 $content_ex = explode('[lang',$content);
37
38 foreach ($content_ex as $value) {
39
40 if (substr($value,0,1) == '=') {
41
42 $pos_s = strpos($value,'=');
43 $pos_f = strpos($value,']');
44 $key = trim( substr($value, ($pos_s+1), ($pos_f-$pos_s-1) ) );
45 $value_l = trim( substr($value, $pos_f+1 ) );
46 $languages[$key] = $value_l;
47
48 } else
49 $languages['default'] = $value;
50 }
51
52 $locale = wpbm_get_locale();
53 // $locale = 'fr_FR';
54
55 if ( isset( $languages[$locale] ) ) $return_text = $languages[ $locale ];
56 else $return_text = $languages[ 'default' ];
57
58 $return_text = wpbm_check_qtranslate( $return_text, $locale );
59
60 $return_text = wpbm_check_wpml_tags( $return_text, $locale ); //FixIn: 5.4.5.8
61
62 return $return_text;
63 }
64
65
66 /** Register and Translate everything in [wpml]Some Text to translate[/wpml] tags.
67 *
68 * @param string $text
69 * @param string $locale
70 * @return string
71 */
72 function wpbm_check_wpml_tags( $text, $locale='' ) { //FixIn: 5.4.5.8
73
74 if ( $locale == '' ) {
75 $locale = wpbm_get_locale();
76 }
77 if ( strlen( $locale ) > 2 ) {
78 $locale = substr($locale, 0, 2 );
79 }
80
81 $is_tranlsation_exist_s = strpos( $text, '[wpml]' );
82 $is_tranlsation_exist_f = strpos( $text, '[/wpml]' );
83
84 if ( ( $is_tranlsation_exist_s !== false ) && ( $is_tranlsation_exist_f !== false ) ) {
85
86 $shortcode = 'wpml';
87
88 // Find anything between [wpml] and [/wpml] shortcodes. Magic here: [\s\S]*? - fit to any text
89 preg_match_all( '/\[' . $shortcode . '\]([\s\S]*?)\[\/' . $shortcode . '\]/i', $text, $wpml_translations, PREG_SET_ORDER );
90 //debuge( $wpml_translations );
91
92 foreach ( $wpml_translations as $translation ) {
93 $text_to_replace = $translation[0];
94 $translation_to_check = $translation[1];
95
96 if ( function_exists ( 'icl_register_string' ) ){
97
98 if ( false ) { // Depricated functions
99
100 // Help: https://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/
101 icl_register_string('Item Calendar', 'wpbm-' . tag_escape( $translation_to_check ) , $translation_to_check );
102
103 //TODO: Need to execurte this after deactivation of plugin or after updating of some option...
104 //icl_unregister_string ( 'Item Calendar', 'wpbm-' . tag_escape( $translation_to_check ) );
105
106 if ( function_exists ( 'icl_translate' ) ){
107 $translation_to_check = icl_translate ( 'Item Calendar', 'wpbm-' . tag_escape( $translation_to_check ) , $translation_to_check );
108 }
109
110 } else { // WPML Version: 3.2
111
112 // Help info: do_action( 'wpml_register_single_string', string $context, string $name, string $value )
113 // https://wpml.org/wpml-hook/wpml_register_string_for_translation/
114 do_action( 'wpml_register_single_string', 'Item Calendar', 'wpbm-' . tag_escape( $translation_to_check ) , $translation_to_check );
115
116
117 // Help info: apply_filters( 'wpml_translate_single_string', string $original_value, string $context, string $name, string $$language_code )
118 // https://wpml.org/wpml-hook/wpml_translate_single_string/
119 //$translation_to_check = apply_filters( 'wpml_translate_single_string', $translation_to_check, 'Item Calendar', 'wpbm-' . tag_escape( $translation_to_check ) );
120 $language_code = $locale;
121 $translation_to_check = apply_filters( 'wpml_translate_single_string', $translation_to_check, 'Item Calendar', 'wpbm-' . tag_escape( $translation_to_check ), $language_code );
122
123 }
124 }
125 $text = str_replace( $text_to_replace, $translation_to_check, $text );
126 }
127 }
128
129 return $text;
130 }
131
132
133 function wpbm_check_qtranslate( $text, $locale='' ){
134
135 if ($locale == '') {
136 $locale = wpbm_get_locale();
137 }
138 if (strlen($locale)>2) {
139 $locale = substr($locale, 0 ,2);
140 }
141
142 $is_tranlsation_exist = strpos($text, '<!--:'.$locale.'-->');
143
144 if ($is_tranlsation_exist !== false) {
145 $tranlsation_end = strpos($text, '<!--:-->', $is_tranlsation_exist);
146
147 $text = substr($text, $is_tranlsation_exist , ($tranlsation_end - $is_tranlsation_exist ) );
148 }
149
150 return $text;
151 }
152
153
154 function wpbm_load_translation(){
155
156 //$locale = 'fr_FR'; wpbm_load_locale( $locale );
157
158 if ( ! wpbm_load_locale() ) {
159 wpbm_load_locale('en_US');
160 }
161
162 $locale = wpbm_get_locale();
163 }
164 add_action('plugins_loaded', 'wpbm_load_translation',1000);
165
166 /** Overload loading of plugin transaltion files from "wp-content/plugins/languages" -> "wp-content/plugins/plugin_name/languages"
167 *
168 * W:\home\beta\www/wp-content/languages/plugins/booking-manager-it_IT.mo -> W:\home\beta\www\wp-content\plugins\booking-manager/languages/booking-manager-it_IT.mo
169 *
170 * @param string $mofile
171 * @param type $domain
172 * @return string
173 */
174 function wpbm_load_custom_plugin_translation_file( $mofile, $domain ) {
175
176 if ( $domain == 'booking-manager' ) {
177
178 $mofile = WPBM_PLUGIN_DIR . '/languages/' . basename( $mofile );
179 }
180
181 return $mofile;
182 }
183 add_filter( 'load_textdomain_mofile', 'wpbm_load_custom_plugin_translation_file' , 10, 2 );
184
185
186 function wpbm_load_locale( $locale = '' ) {
187
188 if ( empty( $locale ) )
189 $locale = wpbm_get_locale();
190
191 if ( ! empty( $locale ) ) {
192
193 $domain = 'booking-manager';
194 $mofile = WPBM_PLUGIN_DIR . '/languages/' . $domain . '-' . $locale . '.mo';
195
196 if ( file_exists( $mofile ) ) {
197
198 $plugin_rel_path = WPBM_PLUGIN_DIRNAME . '/languages' ;
199 return load_plugin_textdomain( $domain, false, $plugin_rel_path ) ;
200 } else {
201 unload_textdomain( $domain );
202 }
203 }
204
205 return false;
206 }
207
208
209 function wpbm_get_locale() {
210
211 if ( defined( 'WPBM_LOCALE_RELOAD' ) )
212 return WPBM_LOCALE_RELOAD;
213
214 if( function_exists( 'get_user_locale' ) )
215 $locale = is_admin() ? get_user_locale() : get_locale();
216 else
217 $locale = get_locale();
218
219 define( 'WPBM_LOCALE_RELOAD', $locale );
220
221 return $locale;
222
223 }
224
225
226 function wpbm_recheck_plugin_locale( $locale, $plugin_domain = '' ) { //FixIn: 2.0.9.1
227
228 if ( $plugin_domain == 'booking-manager' ) //FixIn: 2.0.9.1
229 if ( defined('WPBM_RELOAD') )
230 return WPBM_RELOAD;
231
232 return $locale;
233 }
234 add_filter( 'plugin_locale', 'wpbm_recheck_plugin_locale', 100, 2 ); // When load_plugin_text_domain is work, its get def locale and not that, we send to it so need to reupdate it