Skip to content

Additional functionality and the Gutenberg support for 'qTranslate-XT' plugin. Customization of language switch buttons.

License

Notifications You must be signed in to change notification settings

picasso/zu-translate

Repository files navigation

Zu Translate: qTranslate-XT on steroids.

WordPress Plugin Version WordPress Plugin: Tested WP Version WordPress Plugin Required PHP Version License

This plugin is not independent. It adds functionality and implements Gutenberg (WordPress Block Editor) support for the qTranslate-XT plugin. Perhaps someday it will be integrated into qTranslate-XT, and perhaps never.

Zu Translate - qTranslate-XT on steroids.

Description

After the WordPress changed the TinyMCE to the Block Editor (Gutenberg), editing the multilingual content significantly complicated. The old algorithms of the qTranslate-XT plugin, which successfully worked before - stopped working. This plugin is an attempt to find a new solution for editing multilingual content in the Block Editor. In addition, there were always nuances that did not suit me in qTranslate-XT plugin. Solutions of these "problems" are also implemented in this plugin. Use it or not - that's your choice.

🎃 Testing this plugin cannot be called comprehensive. Therefore, use it at your own risk.

Features

  • Support for switching language in the Block Editor
  • Synchronize language switch for all editable blocks
  • Ability to add custom blocks to the list supported by this plugin
  • Control of the appearance of buttons to switch language
  • Ability to switch language in the list of posts/pages
  • Support for Quick Edit in the list of posts/pages
  • Supports adding a language switcher to any post or page using a shortcode
  • Ability to use shortcode in the WordPress menu
  • Integrated and tested with WooCommerce plugin

Shortcode attributes

You can configure the language switcher using these attributes:

  • class - additional classes that will be added to the main element: class="my-switcher"
  • as_code - use language codes as the name of the switcher items: as_code=true
  • unsorted - when sorted (default) then the active language will be always on top: unsorted=true
  • post_id - post ID for which you want to create the switcher (default for the current post): post_id=123

If shortcode is used in the menu, use the following template to describe the shortcode:

#location+tag?attribute1=value1&attribute2=value2&linkclass=red_color,bold#
  • location - a position where the result of the shortcode will be inserted. Possible options - after|before|url, that is, before link, after link or instead of the link itself
  • tag - the name of shortcode
  • attribute1, attribute2 - names of attributes of shortcode
  • value1, value2 - attribute values
  • linkclass - a special attribute that sets the class name that will be added to the link (note that if you want to add several classes, you can specify them through the comma)

Examples

  • With language codes and "unsorted":

[zu-lang unsorted=true as_code=true]

  • With custom class for post ID 1209:

[zu-lang class="my-switcher" post_id=1209]

  • In menu with custom class, only language codes, before link and with a special link class:

#before+zu-lang?class=my-switcher&as_code=true&linkclass=none#

Download

Installation

  1. Upload the zu-translate folder to the /wp-content/plugins/ directory.
  2. Activate the plugin using the Plugins menu in your WordPress admin panel.
  3. You can adjust the necessary settings using your WordPress admin panel in Settings > Zu Translate.

Public methods

In order to take advantage of the Gutenberg support implemented in this plugin, plugins and themes can add their custom blocks using the public methods:

  • zutrans_is_multilang()
  • zutrans_register_translated_blocks($blocks)
  • zutrans_get_all_languages($sorted = true)
  • zutrans_convert_text($text, $lang = null, $flags = 0)
  • zutrans_convert_url($url, $lang = null, $flags = 0)

If you are using the Zukit framework, you can use the internal methods of your class - snippets and _snippets.

// for regular theme or plugin
function register_my_blocks() {
    add_action('init', function() {
        if(function_exists('zutrans_register_translated_blocks')) {
            zutrans_register_translated_blocks([
                'myplugin/mega'     => ['title' => 'Mega Block', 'atts' => 'content'],
                'myplugin/super'    => ['title' => 'Super Block', 'atts' => ['text', 'note']],
            ]);
        }
    });
}

// for a theme or plugin that uses the 'Zukit' framework
public function init() {
    if($this->_snippets('is_multilang')) {
        $this->snippets('register_translated_blocks', [
            'myplugin/mega'     => ['title' => 'Mega Block', 'atts' => 'content'],
            'myplugin/super'    => ['title' => 'Super Block', 'atts' => ['text', 'note']],
        ]);
    }
}