Nâng cao
Nâng caoLệnh WP-CLI

Lệnh WP-CLI

Các lệnh WP-CLI sau đây có sẵn để dịch các custom post, thuật ngữ phân loại (tags và categories), mục phương tiện, menu và người dùng.

Các lệnh WP-CLI chạy mà không có người dùng đăng nhập theo mặc định. Để có đủ quyền tạo các mục dịch, bạn phải chạy lệnh với ngữ cảnh người dùng, thông qua tùy chọn --user:

wp gatotranslate post 123 --user=admin

wp gatotranslate post

Dịch các custom post (bài viết, trang, loại bài viết tùy chỉnh).

Cách dùng

wp gatotranslate post <ids> [options]

Tham số

Tham sốMô tả
<ids>Danh sách ID bài viết cần dịch, phân cách bằng dấu phẩy hoặc dấu cách

Tùy chọn

Nếu không được cung cấp, các tùy chọn sẽ được đặt theo giá trị trong Cài đặt plugin.

Tùy chọnMô tảGiá trị có thể
--translate-slugs=<bool>Có dịch slug hay khôngtrue, false
--default-provider=<provider>Nhà cung cấp dịch thuật mặc địnhchatgpt, claude, deepl, gemini, google_translate, deepseek, mistral, openrouter, self_hosted_llm
--status-to-update=<status>Trạng thái bài viết phải có để được cập nhậtdraft, pending, publish, private, future, any
--status-when-translated=<status>Trạng thái bài viết sẽ có sau khi dịchdraft, pending, publish, private, current (tức là không thay đổi trạng thái), same-as-origin (tức là sao chép trạng thái từ bài viết gốc)
--copy-date=<bool>Có sao chép ngày từ bài viết gốc hay khôngtrue, false
--language-providers=<providers>Chuỗi JSON ánh xạ nhà cung cấp theo ngôn ngữChuỗi JSON với mã ngôn ngữ là khóa, và giá trị là tên nhà cung cấp, hoặc "none" (để tắt ngôn ngữ đó), hoặc "default" (để dùng nhà cung cấp mặc định)
--tasks=<tasks>Danh sách tác vụ cần thực hiện, phân cách bằng dấu phẩytranslate-content, translate-entity-relationships, replace-internal-links
--parts=<parts>Danh sách phần nội dung cần sửa đổi, phân cách bằng dấu phẩyproperties (tiêu đề, slug và trích đoạn), content (nội dung bài viết), meta (trường tùy chỉnh)
--porcelainChỉ xuất thông tin thiết yếu, phù hợp để phân tích bằng scriptKhông yêu cầu giá trị (flag)
--fail-if-log-notificationsThất bại nếu có thông báo nhật ký được thêm trong quá trình thực thiKhông yêu cầu giá trị (flag)
--process-failedChỉ xử lý các bản dịch thất bạiKhông yêu cầu giá trị (flag)

Ví dụ

# Translate post with ID 123
wp gatotranslate post 123 --user=admin
 
# Translate posts with IDs 123, 456, and 789
wp gatotranslate post 123,456,789 --user=admin
 
# Translate posts with IDs 123 and 456
wp gatotranslate post "123 456" --user=admin
 
# Translate post replicating the status and date of the original post
wp gatotranslate post 123 --user=admin --status-when-translated=same-as-origin --copy-date=true
 
# Translate post using ChatGPT as default provider
wp gatotranslate post 123 --user=admin --default-provider=chatgpt
 
# Translate post with a specific provider for each language
wp gatotranslate post 123 --user=admin --language-providers='{"es":"chatgpt","fr":"deepl"}'
 
# Translate post disabling a specific language
wp gatotranslate post 123 --user=admin --language-providers='{"de":"none"}'
 
# Translate only post properties (title, slug, and excerpt)
wp gatotranslate post 123 --user=admin --parts=properties
 
# Translate only post content and meta
wp gatotranslate post 123 --user=admin --parts=content,meta
 
# Only update the entity relationships for the target language
wp gatotranslate post 123 --user=admin --tasks=translate-entity-relationships
 
# Re-run translations for previously failed posts/languages only
wp gatotranslate post "123 456" --user=admin --process-failed

wp gatotranslate term

Dịch các thuật ngữ phân loại (categories, tags, phân loại tùy chỉnh).

Cách dùng

wp gatotranslate term <ids> [options]

Tham số

Tham sốMô tả
<ids>Danh sách ID thuật ngữ cần dịch, phân cách bằng dấu phẩy hoặc dấu cách

Tùy chọn

Tùy chọnMô tảGiá trị có thể
--translate-slugs=<bool>Có dịch slug hay khôngtrue, false
--default-provider=<provider>Nhà cung cấp dịch thuật mặc địnhchatgpt, claude, deepl, gemini, google_translate, deepseek, mistral, openrouter, self_hosted_llm
--language-providers=<providers>Chuỗi JSON ánh xạ nhà cung cấp theo ngôn ngữChuỗi JSON với mã ngôn ngữ là khóa, và giá trị là tên nhà cung cấp, hoặc "none" (để tắt ngôn ngữ đó), hoặc "default" (để dùng nhà cung cấp mặc định)
--tasks=<tasks>Danh sách tác vụ cần thực hiện, phân cách bằng dấu phẩytranslate-content, translate-entity-relationships
--parts=<parts>Danh sách phần nội dung cần sửa đổi, phân cách bằng dấu phẩyproperties (tên, slug), content (mô tả), meta (trường tùy chỉnh)
--porcelainChỉ xuất thông tin thiết yếu, phù hợp để phân tích bằng scriptKhông yêu cầu giá trị (flag)
--fail-if-log-notificationsThất bại nếu có thông báo nhật ký được thêm trong quá trình thực thiKhông yêu cầu giá trị (flag)
--process-failedChỉ xử lý các bản dịch thất bạiKhông yêu cầu giá trị (flag)

Ví dụ

# Translate term with ID 1
wp gatotranslate term 1 --user=admin
 
# Translate terms with IDs 1, 2, and 3
wp gatotranslate term 1,2,3 --user=admin
 
# Translate term 1 disabling slug translation, and using OpenRouter as default provider
wp gatotranslate term 1 --user=admin --translate-slugs=false --default-provider=openrouterr
 
# Translate term 1 with a specific provider for each language
wp gatotranslate term 1 --user=admin --language-providers='{"es":"chatgpt","fr":"deepl"}'
 
# Translate disabling a specific language
wp gatotranslate term 1 --user=admin --language-providers='{"de":"none"}'
 
# Translate only term name and slug
wp gatotranslate term 1 --user=admin --parts=properties
 
# Translate only term description and meta
wp gatotranslate term 1 --user=admin --parts=content,meta
 
# Only update the entity relationships for the target language
wp gatotranslate term 1 --user=admin --tasks=translate-entity-relationships
 
# Re-run translations for previously failed terms/languages only
wp gatotranslate term 1,2,3 --user=admin --process-failed

wp gatotranslate media

Dịch các mục phương tiện (tệp đính kèm).

Cách dùng

wp gatotranslate media <ids> [options]

Tham số

Tham sốMô tả
<ids>Danh sách ID phương tiện cần dịch, phân cách bằng dấu phẩy hoặc dấu cách

Tùy chọn

Tùy chọnMô tảGiá trị có thể
--translate-slugs=<bool>Có dịch slug hay khôngtrue, false
--default-provider=<provider>Nhà cung cấp dịch thuật mặc địnhchatgpt, claude, deepl, gemini, google_translate, deepseek, mistral, openrouter, self_hosted_llm
--language-providers=<providers>Chuỗi JSON ánh xạ nhà cung cấp theo ngôn ngữChuỗi JSON với mã ngôn ngữ là khóa, và giá trị là tên nhà cung cấp, hoặc "none" (để tắt ngôn ngữ đó), hoặc "default" (để dùng nhà cung cấp mặc định)
--tasks=<tasks>Danh sách tác vụ cần thực hiện, phân cách bằng dấu phẩytranslate-content, translate-entity-relationships, replace-internal-links
--parts=<parts>Danh sách phần nội dung cần sửa đổi, phân cách bằng dấu phẩyproperties (tiêu đề, slug), content (văn bản thay thế, chú thích và mô tả), meta (trường tùy chỉnh)
--porcelainChỉ xuất thông tin thiết yếu, phù hợp để phân tích bằng scriptKhông yêu cầu giá trị (flag)
--fail-if-log-notificationsThất bại nếu có thông báo nhật ký được thêm trong quá trình thực thiKhông yêu cầu giá trị (flag)
--process-failedChỉ xử lý các bản dịch thất bạiKhông yêu cầu giá trị (flag)

Ví dụ

# Translate media item with ID 10
wp gatotranslate media 10 --user=admin
 
# Translate media items with IDs 10, 11, 12
wp gatotranslate media 10,11,12 --user=admin
 
# Translate media item with a specific provider for each language
wp gatotranslate media 10 --user=admin --language-providers='{"es":"chatgpt","fr":"deepl"}'
 
# Translate disabling specific languages
wp gatotranslate media 10 --user=admin --language-providers='{"de":"none","zh":"none"}'
 
# Translate only media title and slug
wp gatotranslate media 10 --user=admin --parts=properties
 
# Translate only media content (alt text, caption, and description) and meta
wp gatotranslate media 10 --user=admin --parts=content,meta
 
# Only update the entity relationships for the target language
wp gatotranslate media 10 --user=admin --tasks=translate-entity-relationships
 
# Re-run translations for previously failed media items/languages only
wp gatotranslate media 10,11,12 --user=admin --process-failed

wp gatotranslate menu

Dịch các menu.

Chỉ các menu trong ngôn ngữ gốc mới được dịch. Vì Polylang không lưu trữ ngôn ngữ cho các menu, thông tin này được xác định từ các vị trí menu được gán.

Việc dịch chỉ được kích hoạt cho một menu nếu:

  • Menu có ít nhất một vị trí đã được gán
  • Không có vị trí nào trong số đó dành cho ngôn ngữ dịch

Cách dùng

wp gatotranslate menu <ids> [options]

Tham số

Tham sốMô tả
<ids>Danh sách ID menu cần dịch, phân cách bằng dấu phẩy hoặc dấu cách

Tùy chọn

Tùy chọnMô tảGiá trị có thể
--default-provider=<provider>Nhà cung cấp dịch thuật mặc địnhchatgpt, claude, deepl, gemini, google_translate, deepseek, mistral, openrouter, self_hosted_llm
--language-providers=<providers>Chuỗi JSON ánh xạ nhà cung cấp theo ngôn ngữChuỗi JSON với mã ngôn ngữ là khóa, và giá trị là tên nhà cung cấp, hoặc "none" (để tắt ngôn ngữ đó), hoặc "default" (để dùng nhà cung cấp mặc định)
--porcelainChỉ xuất thông tin thiết yếu, phù hợp để phân tích bằng scriptKhông yêu cầu giá trị (flag)
--fail-if-log-notificationsThất bại nếu có thông báo nhật ký được thêm trong quá trình thực thiKhông yêu cầu giá trị (flag)

Ví dụ

# Translate menu with ID 5
wp gatotranslate menu 5 --user=admin
 
# Translate menus with IDs 5, 6, and 7
wp gatotranslate menu 5,6,7 --user=admin
 
# Translate menu with a specific provider for each language
wp gatotranslate menu 5 --user=admin --language-providers='{"es":"chatgpt","fr":"deepl"}'
 
# Translate disabling specific languages
wp gatotranslate menu 5 --user=admin --language-providers='{"de":"none","zh":"none"}'

wp gatotranslate user

Dịch mô tả người dùng.

Cách dùng

wp gatotranslate user <ids> [options]

Tham số

Tham sốMô tả
<ids>Danh sách ID người dùng cần dịch, phân cách bằng dấu phẩy hoặc dấu cách

Tùy chọn

Tùy chọnMô tảGiá trị có thể
--default-provider=<provider>Nhà cung cấp dịch thuật mặc địnhchatgpt, claude, deepl, gemini, google_translate, deepseek, mistral, openrouter, self_hosted_llm
--language-providers=<providers>Chuỗi JSON ánh xạ nhà cung cấp theo ngôn ngữChuỗi JSON với mã ngôn ngữ là khóa, và giá trị là tên nhà cung cấp, hoặc "none" (để tắt ngôn ngữ đó), hoặc "default" (để dùng nhà cung cấp mặc định)
--porcelainChỉ xuất thông tin thiết yếu, phù hợp để phân tích bằng scriptKhông yêu cầu giá trị (flag)
--fail-if-log-notificationsThất bại nếu có thông báo nhật ký được thêm trong quá trình thực thiKhông yêu cầu giá trị (flag)

Ví dụ

# Translate user with ID 1
wp gatotranslate user 1 --user=admin
 
# Translate users with IDs 1, 2, and 3
wp gatotranslate user 1,2,3 --user=admin
 
# Translate users with IDs 1 and 2
wp gatotranslate user "1 2" --user=admin
 
# Translate user using ChatGPT as default provider
wp gatotranslate user 1 --user=admin --default-provider=chatgpt
 
# Translate user with a specific provider for each language
wp gatotranslate user 1 --user=admin --language-providers='{"es":"chatgpt","fr":"deepl"}'
 
# Translate user disabling a specific language
wp gatotranslate user 1 --user=admin --language-providers='{"de":"none"}'