| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\Translation; |
| 4 |
use ResponsiveMenu\Models\Option; |
| 5 |
use ResponsiveMenu\Collections\OptionsCollection; |
| 6 |
|
| 7 |
class Translator { |
| 8 |
|
| 9 |
private $translatables = [ |
| 10 |
'menu_to_use', |
| 11 |
'button_title', |
| 12 |
'menu_title', |
| 13 |
'menu_title_link', |
| 14 |
'menu_additional_content' |
| 15 |
]; |
| 16 |
|
| 17 |
public function translate(Option $option) { |
| 18 |
// WPML Support |
| 19 |
$translated = apply_filters('wpml_translate_single_string', $option->getValue(), 'Responsive Menu', $option->getName()); |
| 20 |
|
| 21 |
// Polylang Support |
| 22 |
$translated = function_exists('pll__') ? pll__($translated) : $translated; |
| 23 |
|
| 24 |
return $translated; |
| 25 |
} |
| 26 |
|
| 27 |
public function searchUrl() { |
| 28 |
return function_exists('icl_get_home_url') ? icl_get_home_url() : get_home_url(); |
| 29 |
} |
| 30 |
|
| 31 |
public function saveTranslations(OptionsCollection $options) { |
| 32 |
foreach($this->translatables as $option_name) |
| 33 |
if(isset($options[$option_name])) |
| 34 |
do_action('wpml_register_single_string', 'Responsive Menu', $option_name, $options[$option_name]->getValue()); |
| 35 |
} |
| 36 |
|
| 37 |
public function allowShortcode($text) { |
| 38 |
return do_shortcode($text); |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
|