3 namespace WPML\PB\Elementor\LanguageSwitcher;
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Core\Schemes\Color as SchemeColor;
11 /** @var Widget $widget */
14 public function setTarget( Widget $widget ) {
15 $this->widget = $widget;
19 public function getName() {
20 return 'wpml-language-switcher';
24 public function getTitle() {
25 return __( 'WPML Language Switcher', 'sitepress' );
29 public function getIcon() {
34 public function getCategories() {
41 * Used to add new controls to any element type. For example, external
42 * developers use this method to register controls in a widget.
44 * Should be inherited and register new controls using `add_control()`,
45 * `add_responsive_control()` and `add_group_control()`, inside control
46 * wrappers like `start_controls_section()`, `start_controls_tabs()` and
47 * `start_controls_tab()`.
49 public function registerControls() {
51 $this->widget->start_controls_section(
54 'label' => __( 'Content', 'sitepress' ),
55 'type' => Controls_Manager::SECTION,
56 'tab' => Controls_Manager::TAB_CONTENT,
60 $this->widget->add_control(
63 'label' => __('Language switcher type', 'sitepress'),
64 'type' => Controls_Manager::SELECT,
65 'default' => 'custom',
67 'custom' => __( 'Custom', 'sitepress' ),
68 'footer' => __( 'Footer', 'sitepress' ),
69 'post_translations' => __( 'Post Translations', 'sitepress' ),
74 $this->widget->add_control(
77 'label' => __( 'Display Flag', 'sitepress' ),
78 'type' => Controls_Manager::SWITCHER,
84 $this->widget->add_control(
87 'label' => __( 'Show Active Language - has to be ON with Dropdown', 'sitepress' ),
88 'type' => Controls_Manager::SWITCHER,
94 $this->widget->add_control(
95 'native_language_name',
97 'label' => __( 'Native language name', 'sitepress' ),
98 'type' => Controls_Manager::SWITCHER,
104 $this->widget->add_control(
105 'language_name_current_language',
107 'label' => __( 'Language name in current language', 'sitepress' ),
108 'type' => Controls_Manager::SWITCHER,
114 $this->widget->end_controls_section();
116 $this->widget->start_controls_section(
119 'label' => __( 'Style', 'sitepress' ),
120 'tab' => Controls_Manager::TAB_STYLE,
123 $this->widget->start_controls_tabs( 'style_tabs' );
125 $this->widget->start_controls_tab(
128 'label' => __( 'Normal', 'sitepress' ),
132 $this->widget->add_group_control(
133 Group_Control_Typography::get_type(),
135 'name' => 'switcher_typography',
136 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item',
140 $this->widget->add_control(
141 'switcher_text_color',
143 'label' => __( 'Text Color', 'sitepress' ),
144 'type' => Controls_Manager::COLOR,
146 'type' => SchemeColor::get_type(),
147 'value' => SchemeColor::COLOR_3,
151 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link,
152 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a' => 'color: {{VALUE}}',
157 $this->widget->add_control(
160 'label' => __( 'Background Color', 'sitepress' ),
161 'type' => Controls_Manager::COLOR,
164 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link,
165 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a' => 'background-color: {{VALUE}}',
170 $this->widget->end_controls_tab();
172 $this->widget->start_controls_tab(
175 'label' => __( 'Hover', 'sitepress' ),
178 $this->widget->add_group_control(
179 Group_Control_Typography::get_type(),
181 'name' => 'switcher_hover_typography',
182 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item:hover,
183 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item.wpml-ls-item__active,
184 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item.highlighted,
185 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item:focus',
189 $this->widget->add_control(
190 'switcher_hover_color',
192 'label' => __( 'Text Color', 'sitepress' ),
193 'type' => Controls_Manager::COLOR,
195 'type' => SchemeColor::get_type(),
196 'value' => SchemeColor::COLOR_4,
199 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a:hover,
200 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a:focus,
201 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown .wpml-ls-current-language:hover>a,
202 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link:hover,
203 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link.wpml-ls-link__active,
204 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link.highlighted,
205 {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link:focus' => 'color: {{VALUE}}',
210 $this->widget->end_controls_tab();
212 $this->widget->end_controls_tabs();
214 $this->widget->end_controls_section();
216 $this->widget->start_controls_section(
219 'label' => __( 'Language Flag', 'sitepress' ),
220 'tab' => Controls_Manager::TAB_STYLE,
222 'display_flag' => [ 1 ],
227 $this->widget->add_control(
230 'label' => __( 'Margin', 'sitepress' ),
231 'type' => Controls_Manager::DIMENSIONS,
232 'size_units' => [ 'px', '%', 'em' ],
234 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-flag' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
239 $this->widget->end_controls_section();
241 $this->widget->start_controls_section(
242 'post_translation_text',
244 'label' => __( 'Post Translation Text', 'sitepress' ),
245 'tab' => Controls_Manager::TAB_STYLE,
247 'style' => [ 'post_translations' ],
252 $this->widget->add_group_control(
253 Group_Control_Typography::get_type(),
255 'name' => 'post_translation_typography',
256 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations',
260 $this->widget->add_control(
261 'post_translation_color',
263 'label' => __( 'Text Color', 'sitepress' ),
264 'type' => Controls_Manager::COLOR,
266 'type' => SchemeColor::get_type(),
267 'value' => SchemeColor::COLOR_3,
271 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'color: {{VALUE}}',
276 $this->widget->add_control(
277 'post_translation_bg_color',
279 'label' => __( 'Background Color', 'sitepress' ),
280 'type' => Controls_Manager::COLOR,
283 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'background-color: {{VALUE}}',
288 $this->widget->add_control(
289 'post_translation_padding',
291 'label' => __( 'Padding', 'sitepress' ),
292 'type' => Controls_Manager::DIMENSIONS,
293 'size_units' => [ 'px', '%', 'em' ],
295 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
300 $this->widget->add_control(
301 'post_translation_margin',
303 'label' => __( 'Margin', 'sitepress' ),
304 'type' => Controls_Manager::DIMENSIONS,
305 'size_units' => [ 'px', '%', 'em' ],
307 '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
312 $this->widget->end_controls_section();
319 * Generates the final HTML on the frontend.
321 public function render() {
322 $settings = $this->widget->get_settings_for_display();
324 $this->widget->add_render_attribute('wpml-elementor-ls', 'class', [
329 'display_link_for_current_lang' => $settings['link_current'],
330 'flags' => $settings['display_flag'],
331 'native' => $settings['native_language_name'],
332 'translated' => $settings['language_name_current_language'],
333 'type' => $settings['style'],
336 if ( 'custom' === $settings['style'] ) {
337 //forcing in dropdown case
338 $args['display_link_for_current_lang'] = 1;
341 echo "<div " . $this->widget->get_render_attribute_string('wpml-elementor-ls') . ">";
342 do_action('wpml_language_switcher', $args);