Plugin Directory

Changeset 3337063


Ignore:
Timestamp:
07/31/2025 08:39:36 AM (8 months ago)
Author:
vaksin
Message:

0.0.6

  • Fix internal link recognition when no scheme or host is specified
  • Code refactoring
Location:
just-translate
Files:
296 added
7 edited

Legend:

Unmodified
Added
Removed
  • just-translate/trunk/admin/settings.php

    r3336773 r3337063  
    22
    33use WPJT\Classes\JT_Locale;
    4 use WPJT\Modules\JT_Table;
    54
    65function wpjt_translation_settings_page() { 
    7     JT_Table::setup_tables();
    86    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
    97        if (!isset($_POST['wpjt_settings_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['wpjt_settings_nonce'])), 'wpjt_settings_action')) {
  • just-translate/trunk/classes/jt-path.php

    r3335930 r3337063  
    1111    protected readonly string $path, $rslash;
    1212    protected readonly array $slugs;
     13
    1314    protected array $paths;
     15    protected array $translateds;
    1416
    1517    public function __construct(string $path) {
     
    9799                    foreach($this->slugs as $i=>$slug){
    98100                        $tranlated_slug = JT_Query::get_source_slug($slug, $target_locale->code, $this->locale_code);
    99                         $slugs[$i] = $tranlated_slug ?: $slug;
     101                        if(!$tranlated_slug){
     102                            $this->translateds[$target_locale->code] = false;
     103                            $slugs[$i] = $slug;
     104                        } else {
     105                            $slugs[$i] = $tranlated_slug;
     106                        }
    100107                    }
    101108                    $translated_path = trim(implode('/', $slugs), '/');
     
    111118                    foreach($this->slugs as $i=>$slug){
    112119                        $tranlated_slug = JT_Query::get_target_slug($slug, JT_Locale::get_source_code(), $target_locale->code);
    113                         $slugs[$i] = $tranlated_slug ?: $slug;
     120                        if(!$tranlated_slug){
     121                            $this->translateds[$target_locale->code] = false;
     122                            $slugs[$i] = $slug;
     123                        } else {
     124                            $slugs[$i] = $tranlated_slug;
     125                        }
    114126                    }
    115127                    $translated_path = $target_locale->slug . '/' . trim(implode('/', $slugs), '/');
     
    123135        return $this->paths[$target_locale->code];
    124136    }
     137   
     138    public function is_translated(string $target_locale_code): bool{
     139        $target_locale = wpjt_get_locale($target_locale_code ?? $this->locale_code);
     140        if(!$target_locale) return false;
     141
     142        if(!isset($this->translateds[$target_locale->code])) {
     143            /** logic cek translated atau tidak ada di dalam value function
     144             * value function hanya mendeteksi jika not translated
     145             * jika function sudah dipanggil namun variable belum diset artinya translated
     146            */
     147            $this->value($target_locale->code);
     148            if(!isset($this->translateds[$target_locale->code])) {
     149                $this->translateds[$target_locale->code] = true;
     150            }
     151        }
     152
     153        return $this->translateds[$target_locale->code];
     154    }   
    125155}
  • just-translate/trunk/helper/jt-util.php

    r3335930 r3337063  
    228228    }
    229229
     230    public static function is_internal_link( $link ) {       
     231        $parsed = wp_parse_url(strtolower( $link ) );
     232        if(array_key_exists('scheme', $parsed) && array_key_exists('host', $parsed)){
     233            /** Ikut logic WP
     234             * ref: https://developer.wordpress.org/reference/functions/wp_is_internal_link/
     235             */
     236            return in_array( $parsed['host'], wp_internal_hosts(), true );
     237        } else {
     238            /** jika scheme dan host kosong anggap internal link */
     239            return true;
     240        }
     241    }   
     242
    230243    public static function debug($var, bool $exit=false){
    231244        // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r  --  used only on development mode
    232         // if(!defined('WPJT_DEV_MODE')) define('WPJT_DEV_MODE', false);
    233         // if(!WPJT_DEV_MODE) return;
     245        if(!defined('WPJT_DEV_MODE')) define('WPJT_DEV_MODE', false);
     246        if(!WPJT_DEV_MODE) return;
    234247       
    235248        echo '<pre>';       
  • just-translate/trunk/just-translate.php

    r3336773 r3337063  
    33 * Plugin Name:       Just Translate
    44 * Description:       Automatically captures and translates text strings using a custom translation panel with multi-language support.
    5  * Version:           0.0.5
     5 * Version:           0.0.6
    66 * Requires at least: 6.5
    77 * Requires PHP:      8.1
     
    1717if (!defined('ABSPATH')) exit;
    1818
    19 define( 'WPJT_VERSION', '0.0.5' );
     19define( 'WPJT_VERSION', '0.0.6' );
    2020define( 'WPJT_PLUGIN_FILE', __FILE__  );
    2121define( 'WPJT_PATH', plugin_dir_path( WPJT_PLUGIN_FILE ) );
  • just-translate/trunk/modules/jt-translator.php

    r3336773 r3337063  
    44use WPJT\Classes\JT_Path;
    55use WPJT\Classes\JT_String;
     6use WPJT\Helper\JT_Util;
    67
    78class JT_Translator {
     
    250251     */
    251252    public static function translate_url(string $url, string $locale_code): string{       
    252         // ini nanti diubah kalau ada translate URL
    253         if(!wp_is_internal_link($url)){
     253        /** saat ini hanya mentranslate internal link
     254         * untuk translate external link nanti menyusul insya Allah
     255         */
     256        if(!JT_Util::is_internal_link($url)){
    254257            return $url;
    255258        }
  • just-translate/trunk/modules/jt.php

    r3336773 r3337063  
    66use WPJT\Classes\JT_Path;
    77use WPJT\Classes\JT_String;
     8use WPJT\Helper\JT_Util;
    89
    910/** @package WPJT\Modules */
     
    3839        if(!in_array($o_path->locale_code, JT_Locale::get_codes())) return;
    3940
     41        /** redirect canical */
     42        if(!$o_path->is_translated(JT_Locale::get_source_code())){
     43            $redirect_path = JT_Path::get_instance($o_path->value(JT_Locale::get_source_code()));
     44            if($redirect_path->is_translated($o_path->locale_code)) {
     45                wp_redirect(home_url($redirect_path->value($o_path->locale_code) . $query)); exit;
     46            }
     47        }
     48
    4049        /** set REQUEST_URI dan PATH_INFO sesuai dengan source path agar dikenali oleh WP request */
    41         $source_path = $o_path->value(JT_Locale::get_source_code());       
     50        $source_path = $o_path->value(JT_Locale::get_source_code());
    4251        $_SERVER['REQUEST_URI'] = $source_path . $query;
    4352        $_SERVER['PATH_INFO'] = $source_path;
  • just-translate/trunk/readme.txt

    r3336773 r3337063  
    66Tested up to: 6.8
    77Requires PHP: 8.1
    8 Stable tag: 0.0.5
     8Stable tag: 0.0.6
    99License: GPLv2 or later 
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    111111
    112112== Changelog ==
    113 = 0.0.5 =
    114 * improve perfomance (cache the translated html)
     113= 0.0.6 =
     114* Fix internal link recognition when no scheme or host is specified
    115115* Code refactoring
    116116
     
    132132== Upgrade Notice ==
    133133
    134 = 0.0.5 =
    135 * improve perfomance (cache the translated html)
     134= 0.0.6 =
     135* Fix internal link recognition when no scheme or host is specified
    136136* Code refactoring
Note: See TracChangeset for help on using the changeset viewer.