The main issue with current plugins and themes is that they fail to localize all their pieces driving most developers to look for alternatives that would instead push them to duplicate websites. But we, as software engineers, know that most of the time reusability is king and to achieve it we need to get back to the roots: be simple (use gettext) and precise (help the theme or plugin author to internationalize).
Here is what I patched this weekend in the Divi plugin. I hope the Divi team will read this and incorporate these fixes (or alike). There are so many people looking for answers to these problems and at the end the solution is not simple for them (as they have to go out there and purchase yet another plugin) neither precise (as no patch is offered to work with these themes and plugins as they are without the need to add a Wordpress translation plugin).
I am all for the use of translation plugins but one size does not fit all and being able to control your own destiny is sometimes (arguably all times) very important.
For those Wordpress Divi users that want to control their own destiny here are the patches needed to make some of the most common Wordpress Divi modules fully localized:
- Divi Tabs module: The tab title is not internationalized. To fix it file includes/builder/module/Tabs.php needs to use esc_html__ on each value of each $tab_title array inside function get_tabs_nav()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
public function get_tabs_nav() { global $et_pb_tab_titles; global $et_pb_tab_classes; $tabs = ''; $i = 0; if ( ! empty( $et_pb_tab_titles ) ) { foreach ( $et_pb_tab_titles as $tab_title ){ // The below block is necessary to internationalize the tab titles foreach ($tab_title as $key=>&$value){ $value = esc_html__($value, 'et_builder'); } // End of tab titles internationalization block unset($value); - Divi Button Module:
The button title is not internationalized. To fix it, file includes/builder/module/Button.php, function render() should assign to button_text the i18n value using the esc_html__() function:
- Divi Blurb Module:
The Blurb title is not internationalized. To fix it, file includes/builder/module/Blurb.php, function render() should assign to the blurb title the i18n value using the esc_html__() function (and others because for this case the actual plain text title is a protected member of an object):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
... if ( '' !== $title ) { $title = sprintf( '<%1$s class="et_pb_module_header">%2$s</%1$s>', et_pb_process_header_level( $header_level, 'h4' ), et_core_esc_previously( $title ) ); // starts blurb i18n patch $plain_source_title = strip_tags( $title ); $plain_target_title = esc_html__($plain_source_title, 'et_builder'); $title = str_replace ($plain_source_title, $plain_target_title, $title); // ends blurb i18n patch } ... - Divi Post Title Module: The Post Title title is not internationalized. To fix it, file includes/builder/module/PortTitle.php, function render() should assign to $post_title the i18n value using the esc_html__() function:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
... if ( $multi_view->has_value( 'title', 'on' ) ) { if ( is_et_pb_preview() && isset( $_POST['post_title'] ) && wp_verify_nonce( $_POST['et_pb_preview_nonce'], 'et_pb_preview_nonce' ) ) { $post_title = sanitize_text_field( wp_unslash( $_POST['post_title'] ) ); } else { $post_title = esc_html( et_builder_get_current_title() ); } $post_title = esc_html__($post_title, 'et_builder'); // post title i18n fix ...
Full Disclosure: I work for Protranslating but the opinions expressed in all of my posts are not necessarily those of my employer.
No comments:
Post a Comment