Changeset 3028672
- Timestamp:
- 01/30/2024 10:24:45 AM (2 years ago)
- Location:
- translate-words/trunk
- Files:
-
- 3 edited
-
includes/frontend.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
translate-wp-words.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
translate-words/trunk/includes/frontend.php
r2755276 r3028672 23 23 $replace = array_column( $overrides, 'overwrite' ); 24 24 25 if ( empty( $keys ) || empty( $replace ) ) { 26 return $translated_string; 27 } 28 29 /** 30 * We perform two replacements here: first case-sensitive, then case-insensitive. 31 * 32 * The reason for this two-step process is to handle scenarios where we have 33 * translations that are identical except for their case. By doing a case-sensitive 34 * replacement first, we ensure that these translations are correctly replaced 35 * with their exact matches. 36 * 37 * After the case-sensitive replacement, we perform a case-insensitive replacement 38 * to catch any remaining translations that were not matched in the first step due 39 * to case differences. 40 * 41 * This process ensures that we prioritize exact matches while still providing 42 * a fallback for any remaining matches, regardless of case. 43 * 44 * It's important to maintain this two-step process to handle all possible 45 * translation scenarios correctly. Therefore, do not remove or alter this 46 * replacement strategy without a thorough understanding of its implications. 47 */ 48 25 49 /** 26 50 * Do a case sensitive replacement. … … 28 52 * but with different cases. 29 53 */ 30 $translated_string = str_replace( $keys, $replace, $translated_string ); 54 $search_keys = array_map( 55 function( $key ) { 56 return '/\b' . preg_quote( $key, '/' ) . '\b/'; 57 }, 58 $keys 59 ); 60 61 $translated_string = preg_replace( $search_keys, $replace, $translated_string ); 31 62 32 63 /** … … 35 66 * backwards compatability. 36 67 */ 37 $translated_string = str_ireplace( $keys, $replace, $translated_string ); 68 $search_keys = array_map( 69 function( $key ) { 70 return '/\b' . preg_quote( $key, '/' ) . '\b/i'; 71 }, 72 $keys 73 ); 74 75 $translated_string = preg_replace( $search_keys, $replace, $translated_string ); 38 76 39 77 return $translated_string; -
translate-words/trunk/readme.txt
r2874825 r3028672 3 3 Tags: gettext, ngettext, string translations, translate 4 4 Requires at least: 4.9.0 5 Tested up to: 6. 2.05 Tested up to: 6.5.0 6 6 Stable tag: trunk 7 7 Requires PHP: 7.0 … … 44 44 == Changelog == 45 45 46 = 1.2.5 - 30th January 2024 = 47 * Tweak replacements to only replace whole words and not the middle of words. 48 46 49 = 1.2.4 - 4th March 2023 = 47 50 * Fix PHP 8.2 error. -
translate-words/trunk/translate-wp-words.php
r2874822 r3028672 3 3 * Plugin Name: Translate Words 4 4 * Description: Thanks to this plugin you can translate all the strings of your portal through the admin panel. 5 * Version: 1.2. 45 * Version: 1.2.5 6 6 * Author: Ben Gillbanks 7 7 * Author URI: https://www.binarymoon.co.uk/
Note: See TracChangeset
for help on using the changeset viewer.