Plugin Directory

Changeset 3326912


Ignore:
Timestamp:
07/13/2025 06:01:03 AM (9 months ago)
Author:
vaksin
Message:

0.0.3

  • Add hreflang tags.
  • Add Content-Language header.
Location:
just-translate
Files:
294 added
5 edited

Legend:

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

    r3326797 r3326912  
    3131function wpjt_run(){   
    3232    do_action('wpjt_run');
     33    add_filter('wpjt_setting_locales', function($locales) {
     34        $locales[] = 'en-GB';
     35        return $locales;
     36    });   
     37    add_filter('wpjt_hreflang_code', function($hreflang, $locale_code) {
     38        if($locale_code === 'en-US') {
     39            $hreflang = 'en';
     40        }
     41        return $hreflang;
     42    }, 10, 2);   
    3343}
  • just-translate/trunk/just-translate.php

    r3326797 r3326912  
    22/**
    33 * Plugin Name:       Just Translate
    4  * Description:       Just translate your WordPress
    5  * Version:           0.0.2
     4 * Description:       Automatically captures and translates text strings using a custom translation panel with multi-language support.
     5 * Version:           0.0.3
    66 * Requires at least: 6.5
    77 * Requires PHP:      8.1
  • just-translate/trunk/modules/jt-translator.php

    r3326797 r3326912  
    3131        if ($htmlTag) {
    3232            $htmlTag->setAttribute('lang', $locale->code);
    33         }       
     33        }   
     34       
     35        self::generate_hreflang($dom);
    3436
    3537        $anchors = $dom->getElementsByTagName('a');       
     
    6769        }               
    6870        return $dom->saveHTML();
     71    }
     72
     73    protected static function generate_hreflang(\DOMDocument &$dom){
     74        $head = $dom->getElementsByTagName('head')->item(0);
     75        $path = isset($_SERVER['REQUEST_URI']) ? sanitize_url( wp_unslash($_SERVER['REQUEST_URI']) ) : '';
     76
     77        $hreflang_tag = function($url, $lang) use ($dom) {
     78            $link = $dom->createElement('link');
     79            $link->setAttribute('rel', 'alternate');
     80            $link->setAttribute('href', $url);
     81            $link->setAttribute('hreflang', $lang);
     82            return $link;
     83        };
     84
     85        $locales = [];
     86
     87        // periksa apakah lang codenya lebih dari satu
     88        $spesific_lang_codes = [];
     89        foreach (wpjt_get_locale_codes() as $locale_code) {
     90            $locale = wpjt_get_locale($locale_code);
     91            $locales[] = $locale;
     92            $spesific_lang_codes[ $locale->lang ] = isset( $spesific_lang_codes[ $locale->lang ] ) ? true:false;           
     93        }
     94
     95        foreach ($locales as $locale) {
     96            if($locale->is_source) {
     97                $url = home_url($path);
     98            } else {
     99                $url = home_url('/' . $locale->slug .  $path);
     100            }
     101
     102            $hreflang = $locale->lang; // defalutnya adalah lang code
     103            if( $spesific_lang_codes[$locale->lang] ) { //jika lang code lebih dari satu
     104                $hreflang = $locale->code;
     105                $hreflang = apply_filters('wpjt_hreflang_code', $hreflang, $locale->code);
     106            }
     107
     108            $x_default = $locale->is_source;
     109            if(apply_filters('wpjt_hreflang_default', $x_default, $locale->code)){
     110                $x_default_url = $url;
     111            }
     112
     113            $head->appendChild( $hreflang_tag($url, $hreflang) );
     114        }
     115
     116        if(isset($x_default_url)){
     117            $head->appendChild( $hreflang_tag($x_default_url, 'x-default') );
     118        }
    69119    }
    70120
  • just-translate/trunk/modules/jt.php

    r3326797 r3326912  
    113113        // nanti perlu kondisi tambahan
    114114        ob_start(function($output){
    115             return JT_Translator::translate_html($output, JT_Locale::get_active_code());
     115            $active_code = JT_Locale::get_active_code();
     116            header('Content-Language: ' . $active_code);
     117            return JT_Translator::translate_html($output, $active_code);
    116118        });   
    117119    }   
  • just-translate/trunk/readme.txt

    r3326807 r3326912  
    66Tested up to: 6.8
    77Requires PHP: 8.1
    8 Stable tag: 0.0.
     8Stable tag: 0.0.3
    99License: GPLv2 or later 
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    2323- Filter translated/untranslated strings 
    2424- Bulk delete strings 
     25- Frontend-based translation (theme-agnostic)
     26- SEO friendly
    2527
    2628== Installation ==
     
    6062== Hooks ==
    6163
    62 **1. `wpjt_locale_slug`** 
     64**1. wpjt_locale_slug** 
    6365Filter the URL slug for a given locale.
    6466
     
    7476`
    7577
    76 **2. `wpjt_setting_locales`** 
     78**2. wpjt_setting_locales** 
    7779Add or remove locale codes in the settings panel.
    7880
     
    8587`
    8688
    87 **3. `wpjt_should_skip_string`** 
     89**3. wpjt_should_skip_string** 
    8890Skip specific strings from being translated.
    8991
     
    103105
    104106= Does it support custom post types or themes? =
    105 Yes. The plugin is theme-agnostic and works with custom post types, themes, and most builders that output strings.
     107Yes. The plugin is theme-agnostic and works with custom post types, themes, and almost all builders (please let me know if there are any builders that are incompatible).
    106108
    107109= How do I switch languages? =
     
    109111
    110112== Changelog ==
     113
     114= 0.0.3 =
     115* Add hreflang tags.
     116* Add Content-Language header.
    111117
    112118= 0.0.2 =
     
    118124== Upgrade Notice ==
    119125
    120 = 0.0.2 =
    121 * refactor.
     126= 0.0.3 =
     127* Add hreflang tags and Content-Language header (This is important for SEO).
Note: See TracChangeset for help on using the changeset viewer.