[WordPress] 外掛分享: Theme and plugin translation for Polylang (TTfP)

首頁外掛目錄 › Theme and plugin translation for Polylang (TTfP)
10,000+
安裝啟用
★★★★
4.7/5 分(35 則評價)
366 天前
最後更新
問題解決
WordPress 5.7+ PHP 7.0+ v3.4.9 上架:2016-02-02

內容簡介

「Polylang 的主題和外掛程式翻譯」是什麼?

這是 Polylang 外掛的擴充套件。Polylang 是一個可讓 WordPress 網站多語言化的擴充套件。
這個外掛可以讓 Polylang 翻譯 WordPress 主題和外掛程式。

如何設定?

選擇要針對 Polylang 翻譯文字的主題和外掛程式。
在管理儀錶板中:

Languages -> TTfP 設定

它是如何運作的?

「Polylang 的主題和外掛程式翻譯」會自動搜尋所有 WordPress 主題和外掛程式的檔案。它會從這些檔案中,選擇那些副檔名為:

php
inc
twig

此外,它還實現了與 Timber 庫 (更多資訊請參閱:http://timber.upstatement.com) 的整合,這使得翻譯 twig 的模板非常簡單。
在搜尋到模板或外掛程式的文字時,它會從 Polylang 函式中選擇文字,例如:

_e(string $text, string $domain = ‘default’);
__(string $text, string $domain = ‘default’);
_x(string $text, string $context, string $domain = ‘default’);
pll_e(string $text);
pll__(string $text);
esc_html(string $text);
esc_html_e(string $text, string $domain = ‘default’);
esc_html__(string $text, string $domain = ‘default’);
_n(string $single, string $plural, int $number, string $domain = ‘default’);
esc_attr_e(string $text, string $domain = ‘default’);
esc_attr__(string $text, string $domain = ‘default’);

在您的 function.php、主題模板或外掛程式中使用:

例如:

<p><?php pll_e('My text'); ?></p>

<p><?php _e('My another text', 'my_theme'); ?></p>

在 Timber 上下文中,聲明這些函式:

$context['pll_e'] = TimberHelper::function_wrapper('pll_e');

$context['pll_'] = TimberHelper::function_wrapper('pll_');

詳情請參閱:https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
這些函式是由 Polylang 外掛定義的,用於輸出翻譯。
有了「Polylang 的主題和外掛程式翻譯」,您可以非常簡單地找到這些需翻譯的字符串並添加到 Polylang 註冊中。
然後,您可以在管理儀錶板中翻譯這些文字。
掃描結果可在翻譯選項卡中查看:

設定 -> 語言 -> 字串翻譯

或者

語言 -> 字串翻譯

您不需要使用 poedit 等程式,也不會更改像 .pot、.po、.mo 這樣的擴展名文件。
「Polylang 的主題和外掛程式翻譯」非常高效,因為掃描器只在儀錶板的選項卡中運行:

設定 -> 語言 -> 字串翻譯

或者

語言 -> 字串翻譯

匯出和匯入字串翻譯

在儀錶板中:

語言 -> TTfP 設定

篩選器參考
ttfp_domains

允許外掛程式和主題(在 functions.php 中)修改文字域的列表(用於檢索翻譯字符串的唯一標識符)。
文字域列表顯示在:

外掛標籤

開發者團隊

⬇ 下載最新版 (v3.4.9) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Theme and plugin translation for Polylang (TTfP)」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

What is “Theme and plugin translation for Polylang”?
Extension for Polylang plugin (Polylang is an extension to make multilingual WordPress websites.).
Plugin is needed to translate the WordPress themes and plugins by Polylang.
How to configure it?
Select themes and plugins to find texts for translation by Polylang.
In admin dashboard:
Languages -> TTfP Settings

How it is work?
“Theme and plugin translation for Polylang” automatically searches all files of WordPress themes and plugins. It chooses from this file only those files with extensions:

php
inc
twig

In addition, is implemented the integration with Timber library (read more: http://timber.upstatement.com) – which allows to translate twig’s skins in simple way.
Plugin in searched skins or plugins chooses texts from Polylang functions, such as:

_e(string $text, string $domain = ‘default’);
__(string $text, string $domain = ‘default’);
_x(string $text, string $context, string $domain = ‘default’);
pll_e(string $text);
pll__(string $text);
esc_html(string $text);
esc_html_e(string $text, string $domain = ‘default’);
esc_html__(string $text, string $domain = ‘default’);
_n(string $single, string $plural, int $number, string $domain = ‘default’);
esc_attr_e(string $text, string $domain = ‘default’);
esc_attr__(string $text, string $domain = ‘default’);

In your function.php, themes or plugins.
For example:

On the timber context declare this functions like:
$context['pll_e'] = TimberHelper::function_wrapper('pll_e');

$context['pll_'] = TimberHelper::function_wrapper('pll_');

See more on: https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
These functions are defined by Polylang plugin for printing translations.
Thanks “Theme and plugin translation for Polylang” you can find these strings to translate and add to Polylang register on very simple way.
And then you can translate these texts from the admin dashboard.
The scan result can be seen on the tab with translations:
Settings -> Languages -> String translation

or
Languages -> String translation

You don’t need programs like poedit – you don’t change files with extensions like: .pot, .po, .mo.
“Theme and plugin translation for Polylang” is highly efficient because the scanner is worked only on admin dashboard in tab:
In dashboard:
Settings -> Languages -> String translation

or
Languages -> String translation

Export and import string translation
In dashboard:
Languages -> TTfP Settings

Filter reference
ttfp_domains

Allows plugins and themes (in functions.php) to modify list of text domains (unique identifier for retrieving translated strings).
List of text domains is displayed on “TTfP Settings” page to select them for translation by polylang engine.
Example:
add_filter('ttfp_domains', 'custom_ttfp_domains', 10, 1);
function custom_ttfp_domains(array $domains):array
{
$domains[] = "my-custom-domain";
return $domains;
}

Filter reference
ttfp_translation_access

Returns whether the user has capability to view and edit translations provided by TTfP.
Example:
add_filter('ttfp_translation_access', 'custom_ttfp_translation_access', 10, 1);
function custom_ttfp_translation_access(bool $hasAccess):bool
{
return current_user_can('edit_posts');
}

延伸相關外掛

文章
Filter
Apply Filters
Mastodon