Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-jacob committed Nov 22, 2024
2 parents 60d9a6d + 7b5588f commit d90ca67
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 131 deletions.
7 changes: 5 additions & 2 deletions data.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ function wplng_data_excluded_selector_default() {
'.author.vcard',
'.entry-author .fn',

// Plugin : Query Monitor
// Plugin: Query Monitor
'#query-monitor',
'#query-monitor-main',

// Plugin : SecuPress
// Plugin: SecuPress
'#secupress-donttranslate',

// Plugin: Debug Bar
'#querylist',
);
}

Expand Down
37 changes: 20 additions & 17 deletions inc/admin/slug-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,19 @@ function wplng_slug_save_meta_boxes_data( $post_id ) {
$temp = sanitize_title( $_REQUEST[ $name ] );

if ( empty( $temp ) || $slug_original === $temp ) {
$temp = '[WPLNG_EMPTY]';
$translations[ $key ]['status'] = 'ungenerated';
} else {

if ( $temp !== $translation['translation'] ) {
$temp = str_replace( '\\', '', $temp );
}
$temp = '[WPLNG_EMPTY]';
} elseif ( $temp !== $translation['translation'] ) {
$temp = str_replace( '\\', '', $temp );
}

if ( ! empty( $_POST[ $reviewed ] ) ) {
if ( 'false' !== $_POST[ $reviewed ] ) {
$translations[ $key ]['status'] = time();
} else {
$translations[ $key ]['status'] = 'generated';
}
if ( ! empty( $_POST[ $reviewed ] ) ) {
if ( 'false' !== $_POST[ $reviewed ] ) {
$translations[ $key ]['status'] = time();
} else {
$translations[ $key ]['status'] = 'generated';
}
} else {
$translations[ $key ]['status'] = 'generated';
}

// Check if another slug is translated with the same string
Expand All @@ -412,10 +408,17 @@ function wplng_slug_save_meta_boxes_data( $post_id ) {

foreach ( $saved_slugs as $saved_slug ) {

if ( $slug_original === $saved_slug['source']
|| ! isset( $saved_slug['translations'][ $translation['language_id'] ] )
|| $temp !== $saved_slug['translations'][ $translation['language_id'] ]
) {
if ( $slug_original === $saved_slug['source'] ) {
continue;
}

$saved_slug_translated = $saved_slug['source'];

if ( isset( $saved_slug['translations'][ $translation['language_id'] ] ) ) {
$saved_slug_translated = $saved_slug['translations'][ $translation['language_id'] ];
}

if ( $temp !== $saved_slug_translated ) {
continue;
}

Expand Down
13 changes: 11 additions & 2 deletions inc/hreflang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ function wplng_link_alternate_hreflang() {
$html = PHP_EOL . PHP_EOL;
$language_website = wplng_get_language_website();
$languages_target = wplng_get_languages_target();
$url_original = wplng_get_url_original();
$url_x_default = '';

if ( empty( $language_website ) || empty( $languages_target ) ) {
return;
}

// Get and clear original URL
$url_original = wplng_get_url_original();
$url_original = remove_query_arg(
array( 'wplng-mode', 'wplng-load', 'wplng-nocache' ),
$url_original
);

// Create the starting comment
$html .= '<!-- This website is made multilingual with the wpLingua plugin -->';
$html .= PHP_EOL;
Expand All @@ -52,7 +58,10 @@ function wplng_link_alternate_hreflang() {
// Create alternate link for each target languages
foreach ( $languages_target as $language_target ) {

$url = wplng_get_url_current_for_language( $language_target['id'] );
$url = wplng_url_translate(
$url_original,
$language_target['id']
);

if ( 'en' === $language_target['id'] ) {
$url_x_default = $url;
Expand Down
91 changes: 24 additions & 67 deletions inc/languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,17 @@
*/
function wplng_get_language_website() {

$language = wp_cache_get(
'wplng_get_language_website',
'wplingua'
);
global $wplng_language_website;

if ( ! empty( $language ) ) {
return $language;
if ( null != $wplng_language_website ) {
return $wplng_language_website;
}

$language = wplng_get_language_by_id(
wplng_get_language_website_id()
);

wp_cache_add(
'wplng_get_language_website',
$language,
'wplingua'
);
$wplng_language_website = $language;

return $language;
}
Expand Down Expand Up @@ -193,13 +186,10 @@ function wplng_get_language_name_untranslated( $language ) {
*/
function wplng_get_languages_target_simplified() {

$languages = wp_cache_get(
'wplng_get_languages_target_simplified',
'wplingua'
);
global $wplng_languages_target_simplified;

if ( ! empty( $languages ) ) {
return $languages;
if ( null !== $wplng_languages_target_simplified ) {
return $wplng_languages_target_simplified;
}

$json = get_option( 'wplng_target_languages' );
Expand All @@ -224,11 +214,7 @@ function wplng_get_languages_target_simplified() {
}
}

wp_cache_add(
'wplng_get_languages_target_simplified',
$ordered,
'wplingua'
);
$wplng_languages_target_simplified = $ordered;

return $ordered;
}
Expand All @@ -241,13 +227,10 @@ function wplng_get_languages_target_simplified() {
*/
function wplng_get_languages_target() {

$languages = wp_cache_get(
'wplng_get_languages_target',
'wplingua'
);
global $wplng_languages_target;

if ( ! empty( $languages ) ) {
return $languages;
if ( null !== $wplng_languages_target ) {
return $wplng_languages_target;
}

$languages_target = wplng_get_languages_target_simplified();
Expand All @@ -267,11 +250,7 @@ function wplng_get_languages_target() {
}
}

wp_cache_add(
'wplng_get_languages_target',
$languages_target_clear,
'wplingua'
);
$wplng_languages_target = $languages_target_clear;

return $languages_target_clear;
}
Expand Down Expand Up @@ -306,13 +285,10 @@ function wplng_get_languages_target_ids() {
*/
function wplng_get_language_current_id() {

$id = wp_cache_get(
'wplng_get_language_current_id',
'wplingua'
);
global $wplng_language_current_id;

if ( ! empty( $id ) ) {
return $id;
if ( null !== $wplng_language_current_id ) {
return $wplng_language_current_id;
}

global $wplng_request_uri;
Expand All @@ -330,14 +306,9 @@ function wplng_get_language_current_id() {
|| substr( $current_path, 0, 3 ) === $language . '/'
) {

wp_cache_add(
'wplng_get_language_current_id',
$language,
'wplingua'
);
$wplng_language_current_id = $language;

return $language;
break;
}
}

Expand Down Expand Up @@ -447,13 +418,10 @@ function wplng_is_valid_language_ids( $language_id_list ) {
*/
function wplng_get_languages_all() {

$languages = wp_cache_get(
'wplng_get_languages_all',
'wplingua'
);
global $wplng_languages_all;

if ( ! empty( $languages ) ) {
return $languages;
if ( null !== $wplng_languages_all ) {
return $wplng_languages_all;
}

$languages = wplng_data_languages();
Expand Down Expand Up @@ -510,11 +478,7 @@ function wplng_get_languages_all() {
}
}

wp_cache_add(
'wplng_get_languages_all',
$languages,
'wplingua'
);
$wplng_languages_all = $languages;

return $languages;
}
Expand All @@ -527,13 +491,10 @@ function wplng_get_languages_all() {
*/
function wplng_get_languages_allow() {

$languages = wp_cache_get(
'wplng_get_languages_allow',
'wplingua'
);
global $wplng_languages_allow;

if ( ! empty( $languages ) ) {
return $languages;
if ( null !== $wplng_languages_allow ) {
return $wplng_languages_allow;
}

$languages_alow = wplng_get_api_languages_target();
Expand All @@ -549,11 +510,7 @@ function wplng_get_languages_allow() {
$languages[] = wplng_get_language_by_id( $language_id_alow );
}

wp_cache_add(
'wplng_get_languages_allow',
$languages,
'wplingua'
);
$wplng_languages_allow = $languages;

return $languages;
}
2 changes: 1 addition & 1 deletion inc/slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function wplng_create_slug( $slug ) {
$slug_meta[] = array(
'language_id' => $target_language,
'translation' => $slug,
'status' => 'generated',
'status' => 'ungenerated',
);
}

Expand Down
15 changes: 4 additions & 11 deletions inc/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,10 @@ function wplng_url_is_translatable( $url = '' ) {
*/
function wplng_get_url_exclude_regex() {

$url_exclude = wp_cache_get(
'wplng_get_url_exclude_regex',
'wplingua'
);
global $wplng_url_exclude_regex;

if ( ! empty( $url_exclude ) ) {
return $url_exclude;
if ( null !== $wplng_url_exclude_regex ) {
return $wplng_url_exclude_regex;
}

$url_exclude = array();
Expand Down Expand Up @@ -267,11 +264,7 @@ function wplng_get_url_exclude_regex() {
$url_exclude
);

wp_cache_add(
'wplng_get_url_exclude_regex',
$url_exclude,
'wplingua'
);
$wplng_url_exclude_regex = $url_exclude;

return $url_exclude;
}
Expand Down
12 changes: 10 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://wplingua.com/
Tags: translate, translation, multilingual, localization, language
Requires at least: 6.0
Tested up to: 6.7
Stable tag: 2.1.1
Stable tag: 2.1.2
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -174,9 +174,17 @@ No, not at the moment but in the meantime, you can easily display the language s

== Changelog ==

= 2.1.2 =

* Better plugin translations loading
* Better slug status management
* Optimize cache for wpLingua functions
* Plugin compatibility: Debug Bar
* Clear wpLingua query args in hreflang URLs

= 2.1.1 =

* Added compatibility with wordPress 6.7
* Added compatibility with WordPress 6.7
* Update README and screenshots

= 2.1.0 =
Expand Down
Loading

0 comments on commit d90ca67

Please sign in to comment.