Plugin Directory

Changeset 3338675


Ignore:
Timestamp:
08/04/2025 03:55:56 AM (8 months ago)
Author:
mvpis
Message:

Updates and Performance Improvements

Location:
fluentc-translation
Files:
124 added
3 edited

Legend:

Unmodified
Added
Removed
  • fluentc-translation/trunk/fluentc_wordpress_plugin.php

    r3337568 r3338675  
    77 * Plugin URI: https://www.fluentc.ai
    88 * Description: A plugin that enables website owners to easily install the FluentC Translation on their WordPress site.
    9  * Version: 2.7.4
     9 * Version: 2.7.5
    1010 * Author: FluentC
    1111 * Author URI: https://www.fluentc.ai
     
    1717define( 'FLUENTC_DIR', __DIR__ );
    1818define( 'FLUENTC_SLUG', 'fluentc_translation' );
    19 define( 'FLUENTC_TRANSLATION_VERSION', "2.7.4" );
     19define( 'FLUENTC_TRANSLATION_VERSION', "2.7.5" );
    2020define( 'POLYLANG_VERSION', "2.5.2" );
    2121define( 'FLUENTC_TRANSLATION_PLUGIN_DIR', plugin_dir_path(__FILE__) );
  • fluentc-translation/trunk/readme.txt

    r3337568 r3338675  
    55Requires at least: 4.6
    66Tested up to: 6.8.1
    7 Stable tag: 2.7.4
     7Stable tag: 2.7.5
    88Requires PHP: 7.3
    99License: GPLv2 or later
  • fluentc-translation/trunk/src/models/class-fluentc-links-model.php

    r3267615 r3338675  
    1616        $this->options = $this->initialize_options();
    1717    }
     18
     19
     20    /**
     21 * Adds a language code to a URL.
     22 *
     23 * @since 2.5.0
     24 *
     25 * @param string $url The URL to modify.
     26 * @param string $language_code Optional. The two-letter language code to add.  Defaults to the current language.
     27 * @param bool $add_params Optional. Whether to add the language code as a URL parameter or in the path. Defaults to false.
     28 * @param bool $force_url Optional. Whether to always add the language code, even if it's already present. Defaults to false.
     29 *
     30 * @return string The modified URL with the language code added, or an empty string if the input URL is empty.
     31 */
     32function add_language_to_link( $url, $language_code = null, $add_params = false, $force_url = false ) {
     33
     34    if ( empty( $url ) ) {
     35        return '';
     36    }
     37
     38    // Determine the language code if not provided.
     39    if ( null === $language_code ) {
     40        $language_code = fluentc_get_current_language();
     41    }
     42
     43    // If no language code is available, return the original URL
     44    if ( empty( $language_code ) ) {
     45        return $url;
     46    }
     47
     48    // Check if the language code is already present in the URL.
     49    $url_with_lang = false;
     50
     51    if ( $add_params ) {
     52        // Check for parameter format.
     53        $pattern = '#\?lang=[' . $language_code . ']#i';
     54        if ( preg_match( $pattern, $url ) ) {
     55            $url_with_lang = true;
     56        } else {
     57            // Add the parameter.
     58            $url = add_query_arg( 'lang', $language_code, $url );
     59            $url_with_lang = true;
     60        }
     61
     62    } else { // Add to path.
     63        // Check for path format.
     64        $pattern = '#/' . $language_code . '/#i';
     65        if ( preg_match( $pattern, $url ) ) {
     66            $url_with_lang = true;
     67        } else {
     68            // Add the language code to the path.
     69            $url = trailingslashit( $url . '/' . $language_code );
     70            $url_with_lang = true;
     71        }
     72    }
     73
     74    if ( ! $force_url && $url_with_lang ) {
     75        return $url;
     76    } else {
     77        return $url;
     78    }
     79
     80}
     81
    1882    /**
    1983 * Extract language code from the current URL
Note: See TracChangeset for help on using the changeset viewer.