การขยาย
การขยายการแปล Elementor widgets เพิ่มเติม

การแปล Elementor widgets เพิ่มเติม

Gato AI Translations for Polylang สามารถแปลหน้า Elementor ที่ใช้ widget ได้

ปลั๊กอินมาพร้อมกับ รองรับ Elementor และ Elementor PRO widgets ทั้งหมด สำหรับ widgets แบบกำหนดเองหรือของบุคคลที่สาม คุณสามารถขยายการรองรับการแปลผ่าน PHP hooks ได้

การแปลข้อความ

ในการประกาศ properties ที่แปลได้เพิ่มเติมบน Elementor widget ให้ใช้ filter gatompl:elementor_widget_type_translatable_properties

filter จะรับ map แบบ [widgetName => properties] โดย entry ของ properties สามารถมี:

  • ชื่อ control แบบ flat — เช่น 'author_name'
  • Dot-paths — เช่น 'author_avatar.alt' (แปลเป็น settings.author_avatar.alt)
  • Repeater fields — ประกาศเป็น sub-array [repeaterName => [...subFields]]

สิ่งเหล่านี้สามารถผสมได้อย่างอิสระ และการซ้อนสามารถลึกได้ในทุกระดับ

ตัวอย่างเช่น hook นี้ทำให้:

  • control แบบ flat author_name และ dot-path author_avatar.alt แปลได้บน widget blockquote
  • sub-field ของ repeater ชื่อ name แปลได้ภายใน repeater slides ของ widget reviews
add_filter(
    'gatompl:elementor_widget_type_translatable_properties',
    static function (array $translatableProperties): array {
        $translatableProperties['blockquote'][] = 'author_name';
        $translatableProperties['blockquote'][] = 'author_avatar.alt';
        $translatableProperties['reviews']['slides'][] = 'name';
        return $translatableProperties;
    }
);

filter เดียวกันนี้ทำงานได้ทั้ง controls แบบ simple และ repeater fields — ไม่มี hook แยกต่างหากสำหรับ repeaters

การแปล entity references

property สามารถเก็บ entity ID (โพสต์ taxonomy term รายการสื่อ หรือเมนู) ที่ควรถูก remap ไปยัง entity ของภาษาเป้าหมายที่สอดคล้องกันในเวลาแปล ใช้ filter ที่ตรงกัน:

ประเภท referenceFilter
Custom posts และ mediagatompl:elementor_widget_type_custompost_and_media_reference_properties
Taxonomy termsgatompl:elementor_widget_type_taxonomy_term_reference_properties
เมนูตาม IDgatompl:elementor_widget_type_menu_reference_by_id_properties
เมนูตาม sluggatompl:elementor_widget_type_menu_reference_by_slug_properties

รูปแบบเหมือนกับ filter ของ translatable-properties — ชื่อแบบ flat, dot-paths หรือ sub-arrays สำหรับ repeaters

// Custom post / media reference
add_filter(
    'gatompl:elementor_widget_type_custompost_and_media_reference_properties',
    static function (array $properties): array {
        $properties['featured-post'][] = 'post_id';
        $properties['gallery']['items'][] = 'image_id';
        return $properties;
    }
);
 
// Taxonomy term reference
add_filter(
    'gatompl:elementor_widget_type_taxonomy_term_reference_properties',
    static function (array $properties): array {
        $properties['related-category'][] = 'category_id';
        return $properties;
    }
);
 
// Menu reference by ID
add_filter(
    'gatompl:elementor_widget_type_menu_reference_by_id_properties',
    static function (array $properties): array {
        $properties['menu-picker'][] = 'menu_id';
        return $properties;
    }
);
 
// Menu reference by slug
add_filter(
    'gatompl:elementor_widget_type_menu_reference_by_slug_properties',
    static function (array $properties): array {
        $properties['menu-picker'][] = 'menu_slug';
        return $properties;
    }
);

การค้นหาชื่อ widget และชื่อ property

รัน GraphQL query Translate custom posts และตรวจสอบ field elementorData ในการตอบกลับ แต่ละ widget แสดง widgetType และ tree ของ settings — นั่นคือที่ที่คุณจะพบชื่อ property (รวมถึง dot-paths แบบซ้อนและ repeater fields) ที่คุณต้องส่งไปยัง hooks ข้างต้น

การตรวจสอบ elementorData ใน Translate custom posts GraphQL response
การตรวจสอบ elementorData ใน Translate custom posts GraphQL response

ดูคู่มือ การดึงข้อมูล page builder เพื่อแปล สำหรับวิธีรัน query นั้น

แหล่งตัวอย่าง

การรวมของปลั๊กอินเองเป็น reference ที่มีประโยชน์ สำรวจไฟล์นี้ภายในปลั๊กอินที่คุณติดตั้ง:

  • wp-content/plugins/gato-ai-translations-for-polylang/src/ConditionalOnContext/LicenseIsActive/ConditionalOnModule/Elementor/Constants/WidgetTypes.php