95 lines
2.5 KiB
PHP
95 lines
2.5 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
use Elementor\Controls_Manager;
|
|
// use Elementor\Utils;
|
|
use Elementor\Icons_Manager;
|
|
// use Elementor\Group_Control_Text_Shadow;
|
|
// use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
|
|
// use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
|
|
// use Elementor\Group_Control_Text_Stroke;
|
|
// use Elementor\Group_Control_Typography;
|
|
|
|
class Elementor_Language extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'language';
|
|
}
|
|
|
|
public function get_title() {
|
|
return esc_html__( 'Language', 'elementor-addon' );
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-code';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return [ 'basic' ];
|
|
}
|
|
|
|
public function get_keywords() {
|
|
return [ 'language', 'translate'];
|
|
}
|
|
|
|
protected function register_controls() {
|
|
$this->start_controls_section(
|
|
'section_setting',
|
|
[
|
|
'label' => esc_html__( 'Settings', 'elementor' ),
|
|
'tab' => Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
|
|
if ( ! function_exists( 'pll_the_languages' ) ) {
|
|
echo '<!-- Polylang not active -->';
|
|
return;
|
|
}
|
|
|
|
$languages = pll_the_languages( [
|
|
'raw' => 1,
|
|
] );
|
|
|
|
if ( empty( $languages ) ) {
|
|
return;
|
|
}
|
|
|
|
$current_lang = null;
|
|
foreach ( $languages as $lang ) {
|
|
if ( $lang['current_lang'] ) {
|
|
$current_lang = $lang;
|
|
break;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="elementor-language-switcher">
|
|
<button class="lang-current">
|
|
<img src="<?php echo esc_url( $current_lang['flag'] ); ?>" alt="<?php echo esc_attr( $current_lang['name'] ); ?>">
|
|
<!-- <span><?php echo esc_html( $current_lang['slug'] ); ?></span> -->
|
|
</button>
|
|
|
|
<ul class="lang-dropdown">
|
|
<?php foreach ( $languages as $lang ) :
|
|
if ( $lang['current_lang'] ) continue;
|
|
?>
|
|
<li>
|
|
<a href="<?php echo esc_url( $lang['url'] ); ?>">
|
|
<img src="<?php echo esc_url( $lang['flag'] ); ?>" alt="<?php echo esc_attr( $lang['name'] ); ?>">
|
|
<!-- <span><?php echo esc_html( $lang['slug'] ); ?></span> -->
|
|
</a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
|
|
<?php
|
|
}
|
|
}
|