Plugin Directory

Changeset 3338696


Ignore:
Timestamp:
08/04/2025 05:05:30 AM (8 months ago)
Author:
vaksin
Message:

0.0.9

Fix cache by device and add ability to translate link tag url

Location:
just-translate
Files:
297 added
7 edited

Legend:

Unmodified
Added
Removed
  • just-translate/trunk/inc/plugin.php

    r3336773 r3338696  
    33use WPJT\Helper\JT_Util;
    44use WPJT\Modules\JT;
     5use WPJT\Modules\JT_Cache;
    56use WPJT\Modules\JT_Query;
    67use WPJT\Modules\JT_Settings;
     
    1920    add_action( 'init', [JT::class, 'cb_init_action'] );
    2021    add_action( 'template_redirect', [JT::class, 'cb_template_redirect_action'] );   
    21     add_filter( 'document_title_parts', [JT::class, 'cb_document_title_parts_filter'] );
    2222   
    2323    add_action( 'wpjt_load', [JT::class, 'load'] );
     
    4141    JT_Table::do_setup();
    4242    JT_Query::set_initial_settings();
     43    JT_Cache::clear_all();
    4344}
    4445
    4546function wpjt_run(){   
    4647    do_action('wpjt_run');
    47     add_filter('wpjt_setting_locales', function($locales) {
    48         $locales[] = 'en-GB';
    49         return $locales;
    50     });   
    51 
    52     add_filter('wpjt_hreflang_code', function($hreflang, $locale_code) {
    53         if($locale_code === 'en-US') {
    54             $hreflang = 'en';
    55         }
    56         return $hreflang;
    57     }, 10, 2);
    5848}
  • just-translate/trunk/just-translate.php

    r3338634 r3338696  
    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.8
     5 * Version:           0.0.9
    66 * Requires at least: 6.5
    77 * Requires PHP:      8.1
     
    1717if (!defined('ABSPATH')) exit;
    1818
    19 define( 'WPJT_VERSION', '0.0.8' );
     19define( 'WPJT_VERSION', '0.0.9' );
    2020define( 'WPJT_PLUGIN_FILE', __FILE__  );
    2121define( 'WPJT_PATH', plugin_dir_path( WPJT_PLUGIN_FILE ) );
  • just-translate/trunk/modules/jt-cache.php

    r3338634 r3338696  
    9797    protected static function get_device_type() {
    9898        $device_type = function() {
    99             $ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
     99            $ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : '';
    100100            if (preg_match('/ipad|tablet|(android(?!.*mobile))|kindle|silk|playbook|nexus 7|nexus 10|xoom/', $ua)) {
    101101                return 'tablet';
  • just-translate/trunk/modules/jt-translator.php

    r3338467 r3338696  
    3838        }   
    3939       
     40        /** hreflang for SEO */
    4041        self::generate_hreflang($dom);
    4142
     43        /** translate document title */
     44        $title_node = $xpath->query('//title')->item(0);
     45        if ($title_node) {
     46            /** separator default pakai en dash, sesuai dengan bawaan WordPress */
     47            $sep = apply_filters('document_title_separator', "\u{2013}");
     48
     49            $title = $title_node->nodeValue;
     50            $title_parts = explode($sep, $title);
     51            $title_parts = array_map(function($value) use($locale)  {
     52                return JT_String::get_instance($value)->value($locale->code) ?? $value;
     53            }, $title_parts);           
     54            $title = implode($sep, $title_parts);
     55            $title_node->nodeValue = $title;
     56        }       
     57
    4258        // Translate URL
    43         $nodes = $xpath->query('//a[ not ' . self::get_excluded_element() . ']/@href');
     59        $nodes = $xpath->query('(
     60            //a[not(' . self::get_excluded_element() . ')]/@href
     61            |
     62            //link[not(' . self::get_excluded_element() . ')]/@href
     63        )');
     64
    4465        foreach ($nodes as $node) {
    4566            if (trim($node->nodeValue) !== '' && !self::should_skip_string(trim($node->nodeValue))) {
     
    308329    public static function html_translate_http_header(){       
    309330        $active_code = JT_Locale::get_active_code();
     331        $source_code = JT_Locale::get_source_code();
    310332
    311333        $headers = headers_list();
     
    330352            $parts = explode('; ', $link);
    331353            $uri = trim($parts[0], '<>');
     354
     355            /** tidak support REST API jadi remove link yang mengandung /wp-json/ */
     356            if($source_code != $active_code && str_contains($uri, '/wp-json/')) {
     357                continue;
     358            }
     359
    332360            $translated_url = self::translate_url($uri, $active_code);
    333361            header('Link: ' . '<' . $translated_url . '>; ' . implode('; ', array_slice($parts, 1)), false);
  • just-translate/trunk/modules/jt.php

    r3338467 r3338696  
    55use WPJT\Classes\JT_Locale;
    66use WPJT\Classes\JT_Path;
    7 use WPJT\Classes\JT_String;
    8 use WPJT\Helper\JT_Util;
    97
    108/** @package WPJT\Modules */
     
    122120            return $translated_html;
    123121        });
    124     }   
    125 
    126     /**
    127      * Callback for document_title_parts folter hook: https://developer.wordpress.org/reference/hooks/document_title_parts/
    128      * @param mixed $title_parts
    129      * @return mixed
    130      * @throws WP_Exception
    131      */
    132     public static function cb_document_title_parts_filter( $title_parts) {       
    133         foreach($title_parts as $key => $part){
    134             if($key!='page'){
    135                 $title_parts[$key] = JT_String::get_instance($part)->value(JT_Locale::get_active_code()) ?? $title_parts[$key];
    136             }
    137         }
    138         return $title_parts;
    139     }
     122    }
    140123}
  • just-translate/trunk/readme.txt

    r3338634 r3338696  
    66Tested up to: 6.8
    77Requires PHP: 8.1
    8 Stable tag: 0.0.8
     8Stable tag: 0.0.9
    99License: GPLv2 or later 
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    111111
    112112== Changelog ==
     113= 0.0.9 =
     114* Fix cache by device
     115* Add ability to translate link tag url
     116
    113117= 0.0.8 =
    114118* Fix WP_Filesystem Initialization
     
    143147== Upgrade Notice ==
    144148
    145 = 0.0.8 =
    146 * Fix WP_Filesystem Initialization
     149= 0.0.9 =
     150Fix cache by device and add ability to translate link tag url
  • just-translate/trunk/uninstall.php

    r3335930 r3338696  
    11<?php
     2
     3use WPJT\Modules\JT_Cache;
    24use WPJT\Modules\JT_Table;
    35
     
    1315
    1416JT_Table::remove_tables();
     17JT_Cache::clear_all();
Note: See TracChangeset for help on using the changeset viewer.