Dịch thêm các widget Elementor
Gato AI Translations for Polylang có thể dịch các trang Elementor dựa trên widget.
Plugin đi kèm với hỗ trợ cho tất cả các widget của Elementor và Elementor PRO. Đối với các widget tùy chỉnh hoặc của bên thứ ba, bạn có thể mở rộng hỗ trợ dịch thuật thông qua hook PHP.
Dịch các chuỗi
Để khai báo các thuộc tính có thể dịch bổ sung trên một widget Elementor, hãy sử dụng bộ lọc gatompl:elementor_widget_type_translatable_properties.
Bộ lọc nhận một map [widgetName => properties]. Mục properties có thể chứa:
- Tên điều khiển đơn giản — ví dụ:
'author_name' - Đường dẫn dấu chấm — ví dụ:
'author_avatar.alt'(tương ứng vớisettings.author_avatar.alt) - Trường repeater — được khai báo dưới dạng sub-array
[repeaterName => [...subFields]]
Các loại này có thể kết hợp tự do và việc lồng nhau có thể đạt đến bất kỳ độ sâu nào.
Ví dụ, hook này làm cho:
- Điều khiển đơn giản
author_namevà đường dẫn dấu chấmauthor_avatar.altcó thể dịch được trên widgetblockquote - Trường con
namecủa repeater có thể dịch được bên trong repeaterslidescủa widgetreviews
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;
}
);Cùng một bộ lọc hoạt động cho cả điều khiển đơn giản lẫn trường repeater — không có hook riêng biệt cho repeater.
Dịch các tham chiếu thực thể
Một thuộc tính có thể lưu trữ ID của một thực thể (một bài đăng, thuật ngữ phân loại, mục media hoặc menu) cần được ánh xạ lại sang thực thể tương ứng trong ngôn ngữ đích vào lúc dịch thuật. Hãy sử dụng bộ lọc phù hợp:
| Loại tham chiếu | Bộ lọc |
|---|---|
| Custom post và media | gatompl:elementor_widget_type_custompost_and_media_reference_properties |
| Thuật ngữ phân loại | gatompl:elementor_widget_type_taxonomy_term_reference_properties |
| Menu theo ID | gatompl:elementor_widget_type_menu_reference_by_id_properties |
| Menu theo slug | gatompl:elementor_widget_type_menu_reference_by_slug_properties |
Cấu trúc giống như bộ lọc thuộc tính có thể dịch — tên đơn giản, đường dẫn dấu chấm hoặc sub-array cho repeater.
// 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;
}
);Tìm tên widget và tên thuộc tính
Chạy query GraphQL Translate custom posts và kiểm tra trường elementorData trong phản hồi. Mỗi widget hiển thị widgetType và cây settings của nó — đó là nơi bạn sẽ tìm thấy tên các thuộc tính (bao gồm đường dẫn dấu chấm lồng nhau và trường repeater) cần truyền vào các hook trên.

Xem hướng dẫn Truy xuất dữ liệu page builder để dịch để biết cách chạy query đó.
Nơi tìm ví dụ
Các tích hợp của chính plugin là một tài liệu tham khảo hữu ích. Khám phá tệp này bên trong plugin bạn đã cài đặt:
wp-content/plugins/gato-ai-translations-for-polylang/src/ConditionalOnContext/LicenseIsActive/ConditionalOnModule/Elementor/Constants/WidgetTypes.php