Changeset 3313568
- Timestamp:
- 06/18/2025 03:21:45 AM (10 months ago)
- Location:
- ai-translate-for-polylang
- Files:
-
- 8 added
- 2 edited
-
tags/1.1.2 (added)
-
tags/1.1.2/ai-translate-polylang.php (added)
-
tags/1.1.2/inc (added)
-
tags/1.1.2/inc/open-ai (added)
-
tags/1.1.2/inc/open-ai/OpenAi.php (added)
-
tags/1.1.2/inc/open-ai/Url.php (added)
-
tags/1.1.2/inc/settingslib.php (added)
-
tags/1.1.2/readme.txt (added)
-
trunk/ai-translate-polylang.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ai-translate-for-polylang/trunk/ai-translate-polylang.php
r3292957 r3313568 4 4 Plugin URI: https://wordpress.org/plugins/ai-translate-polylang/ 5 5 Description: Add auto AI translation caperbility to Polylang 6 Version: 1.1. 16 Version: 1.1.2 7 7 Author: James Low 8 8 Author URI: http://jameslow.com … … 70 70 array('id'=>'ai_translate_openai_key', 'type'=>'string', 'title'=>'OpenAI API Key', 'description'=>''), 71 71 array('id'=>'ai_translate_openai_org', 'type'=>'string', 'title'=>'OpenAI Organization', 'description'=>'(Optional)'), 72 array('id'=>'ai_translate_openai_model', 'type'=>'s elect', 'title'=>'OpenAI Model', 'default'=>self::$OPENAI_MODEL, 'values'=>array(72 array('id'=>'ai_translate_openai_model', 'type'=>'string', 'title'=>'OpenAI Model', 'default'=>self::$OPENAI_MODEL, 'values'=>array( 73 73 'gpt-4o', 74 74 'gpt-4o-mini', … … 79 79 array('id'=>'ai_translate_claude', 'type'=>'title', 'title'=>'Claude', 'description'=>''), 80 80 array('id'=>'ai_translate_claude_key', 'type'=>'string', 'title'=>'Claude API Key', 'description'=>''), 81 array('id'=>'ai_translate_claude_model', 'type'=>'s elect', 'title'=>'OpenAI Model', 'default'=>self::$CLAUDE_MODEL, 'values'=>array(81 array('id'=>'ai_translate_claude_model', 'type'=>'string', 'title'=>'OpenAI Model', 'default'=>self::$CLAUDE_MODEL, 'values'=>array( 82 82 'claude-3-5-sonnet-20240620', 83 83 'claude-3-opus-20240229', … … 87 87 array('id'=>'ai_translate_gemini', 'type'=>'title', 'title'=>'Gemini', 'description'=>''), 88 88 array('id'=>'ai_translate_gemini_key', 'type'=>'string', 'title'=>'Gemini API Key', 'description'=>''), 89 array('id'=>'ai_translate_gemini_model', 'type'=>'s elect', 'title'=>'Gemini Model', 'default'=>self::$GEMINI_MODEL, 'values'=>array(89 array('id'=>'ai_translate_gemini_model', 'type'=>'string', 'title'=>'Gemini Model', 'default'=>self::$GEMINI_MODEL, 'values'=>array( 90 90 'gemini-2.0-flash', 91 91 'gemini-1.5-flash', … … 202 202 return $data; 203 203 } 204 public static function translate_post($post_id, $to, $status = 'publish' ) {204 public static function translate_post($post_id, $to, $status = 'publish', $overwrite = false) { 205 205 $from = pll_get_post_language($post_id); 206 206 $translation = pll_get_post($post_id, $to); 207 if (!$translation || get_post_status($translation) !== false) {207 if (!$translation || get_post_status($translation) === false || $overwrite) { 208 208 $post = get_post($post_id); 209 209 210 210 self::$author = $post->post_author; 211 211 add_filter('wp_insert_post_data', array(static::class, 'wp_insert_post_data'), '99', 2); 212 // Create a new post with the same content 213 $new_post_id = wp_insert_post([ 214 'post_status' => 'draft', 215 'post_type' => $post->post_type, 216 'post_author' => $post->post_author, //Wordpress overrides author to 0, hence hook 217 'post_date' => $post->post_date, 218 'post_date_gmt' => $post->post_date_gmt, 219 'post_modified' => $post->post_modified, 220 'post_modified_gmt' => $post->post_modified_gmt 221 ]); 222 223 // Set the language for the new post first in case something goes wrong 224 pll_set_post_language($new_post_id, $to); 212 if (!$translation) { 213 // Create a new post with the same content 214 $translation = wp_insert_post([ 215 'post_status' => 'draft', 216 'post_title' => $post->post_title." ($to)", 217 'post_content' => ' ', 218 'post_type' => $post->post_type, 219 'post_author' => $post->post_author, //Wordpress overrides author to 0, hence hook 220 'post_date' => $post->post_date, 221 'post_date_gmt' => $post->post_date_gmt, 222 'post_modified' => $post->post_modified, 223 'post_modified_gmt' => $post->post_modified_gmt 224 ]); 225 // Set the language for the new post first in case something goes wrong 226 pll_set_post_language($translation, $to); 227 } 225 228 226 229 wp_update_post(array( 227 'ID' => $ new_post_id,230 'ID' => $translation, 228 231 'post_title' => self::translate($post->post_title, $to, $from), 229 232 'post_content' => self::translate($post->post_content, $to, $from), … … 242 245 $value = self::translate($value, $to, $from); 243 246 } 244 add_post_meta($ new_post_id, $key, $value);247 add_post_meta($translation, $key, $value); 245 248 } 246 249 } … … 256 259 } 257 260 } 258 wp_set_post_categories($ new_post_id, $translated_category_ids);261 wp_set_post_categories($translation, $translated_category_ids); 259 262 260 263 // Get the translated term IDs for tags … … 267 270 } 268 271 } 269 wp_set_post_tags($ new_post_id, $translated_tag_ids);272 wp_set_post_tags($translation, $translated_tag_ids); 270 273 271 274 // Link the new translation with the original post 272 275 pll_save_post_translations([ 273 $to => $ new_post_id,276 $to => $translation, 274 277 pll_get_post_language($post_id) => $post_id, 275 278 ]); 276 return $new_post_id; 277 } else { 278 return null; 279 } 279 } 280 return $translation; 280 281 } 281 282 -
ai-translate-for-polylang/trunk/readme.txt
r3292957 r3313568 4 4 Tags: language, translate, multilingual, translation, polylang 5 5 Requires at least: 3.0 6 Tested up to: 6. 6.17 Stable tag: 1.1.16 Tested up to: 6.8.1 7 Stable tag: trunk 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 33 33 34 34 == Changelog == 35 36 = 1.1.2 = 37 * Change AI model to text string, so you can choose your own model 38 * Fix internal translate function for scripting 39 * Add option to overwrite on internal translate function 35 40 36 41 = 1.1.1 =
Note: See TracChangeset
for help on using the changeset viewer.