Theme and plugin translation for Polylang (TTfP)

Opis

Jak działa „Theme and plugin translation for Polylang”?

Rozszerzenie dla wtyczki Polylang.
Ta wtyczka jest niezbędna jeśli chcesz tłumaczyć swoje motywy i wtyczki wykorzystując narzędzie Polylang.

Jak skonfigurować wtyczkę?

Wybierz skórki i wtyczki, w których mają być wyszukiwane teksty do tłumaczenia przez silnik Polylang.
W panelu administratora:

Languages -> TTfP Settings

Jak działa?

Wtyczka „Theme translation for Polylang” automatycznie przeszukuje wszystkie pliki wybranego motywu i wtyczki, które posiadają rozszerzenie:

  • php
  • inc
  • twig

Dodatkowo możliwa jest integracja z biblioteką Timber (czytaj więcej: http://timber.upstatement.com) – co pozwala w prosty sposób tłumaczyć twigowe templatki.

Wtyczka skanuje pliki skórek oraz pluginów w poszukiwaniu tekstów do tłumaczenia, które są renderowane przez funkcje Polylang takie jak:

  • _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’);

W pliku function.php, w skórce albo wtyczce:

Na przykład:

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

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

Dla kontekstu timbera w pliku functions.php musisz zadeklarować użycie powyższych funkcji:

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

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

Zobacz więcej w dokumentacji: https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
Funkcje te są zdefiniowane przez wtyczkę Polylang do wyświetlania tłumaczeń.
Dzięki wtyczce „Theme and plugin translation for Polylang” możesz w łatwy sposób odszukać teksty do tłumaczeń i dodać je do rejestru Polylang.
Tłumaczeń możesz dokonać bezpośrednio w panelu administratora.
Wynik skanowania można zobaczyć w zakładce z tłumaczeniami:

Settings -> Languages -> String translation

lub

Languages -> String translation

Nie potrzebujesz programu poedit – nie musisz ręcznie edytować plików z rozszerzeniem: .pot, .po, .mo.
„Theme and plugin translation for Polylang” plugin jest bardzo wydajny, ponieważ skaner działa tylko w panelu administracyjnym:

Settings -> Languages -> String translation

lub

Languages -> String translation

Eksport i import tekstów do tłumaczenia

W panelu:

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');
 }

Zrzuty ekranu

  • Zrzut pokazuje tabelę z frazami ze skórek gotowymi do tłumaczenia przez Polylang.
  • Eksport / import tłumaczeń jako plik CSV przez wtyczkę "Theme and plugin translation for Polylang"
  • Ustawienia - wybierz zakres: jakie wtyczki i moduły mają być uwzględnione

Instalacja

Ten plugin wymaga aktywnej wtyczki Polylang oraz wersji PHP min 5.0.

  1. Rozpakuj archiwum z wtyczką „Theme and plugin translation for Polylang” do katalogu `/wp-content/plugins/` na Twoim serwerze.
  2. Włącz wtyczkę z menu „Wtyczki” w WordPressie.
  3. Przejdź do Settings -> Languages -> String translation lub Languages -> String translation i odszukaj swój tekst do przetłumaczenia.

Użyj

<?php
 pll_e('My string'); // similar to _e();
 // or:
 $var = pll_('My string'); // similar to __();
 // or:
  _e('My string', 'my_theme');
 // or:
  $var = __('My string', 'my_theme');

Jak aktywować rozszerzenie Twig (wtyczka Timber) dla wtyczki „Theme and plugin translation for Polylang” ?

W pliku functions.php dodaj:

if (!class_exists('Timber')) {
    add_action('admin_notices', function () {
        echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
    });
    return;
}

function timber_context()
{
    $context = Timber::get_context();
    $post = Timber::query_post();
    $context['post'] = $post;
    $context['pll_e'] = TimberHelper::function_wrapper('pll_e');
    $context['pll__'] = TimberHelper::function_wrapper('pll__');
    return $context;
}

Timber::$dirname = array('templates', 'views'); // directory names with twig templates
timber_context();

Następnie, np. w pliku index.php dodaj:

<?php
 $context = timber_context();
 $templates = array('home.twig', 'index.twig'); // twig files for render
 Timber::render($templates, $context);

W zdefiniowanym wcześniej pliku twig (np. templates/home.twig) można skorzystać z funkcji polyalng:

{% extends "base.twig" %}
 {% block content %}
     <p>
         {{ pll_e("Test text on TWIG template 1.") }}
     </p>
     <p>
         {{ pll__("Test text on TWIG template 2.") }}
     </p>
 {% endblock %}

Recenzje

2023-04-30
Works very well, required plugin to work with polylang.
2022-12-12 3 odpowiedzi
The latest plugin update broke my online store and did not allow me to get into the admin panel. For a whole hour, while I was looking for the cause of the error, we could not process orders, although the speed of order processing is what sets our online store apart from the competition. It is very irresponsible to provide updates that break the site!
Przeczytaj 31 recenzji

Kontrybutorzy i deweloperzy

„Theme and plugin translation for Polylang (TTfP)” jest oprogramowaniem open source. Poniższe osoby miały wkład w rozwój wtyczki.

Zaangażowani

Rejestr zmian

3.4.2 – 2024/02/15

  • Fixed preg_match_all for pll_.
  • New option in settings: „Translate admin dashboard by user preferences (user profile settings)”.

3.4.1 – 2024/01/16

  • Fixed 'Call to undefined function get_plugins()’

3.4.0 – 2023/08/03

  • Added apply_filters: ttfp_translation_access.
  • Fixed force translating the administrator’s dashboard.
  • Switched to PHP 7.0.

3.3.5 – 2023/04/24

  • Fixed text domains of plugins on setting page.
  • Fixed pll_admin_current_language filter for translate or no translate admin dashboard.

3.3.4 – 2023/04/03

  • Check if function get_plugin_data exist before use.
  • Added pll_admin_current_language filter for translate or no translate admin dashboard.

3.3.3 – 2023/01/26

  • Include text domain of plugins and themes.

3.3.2 – 2022/12/27

  • Fixed notice in Polylang_Theme_Translation_Settings.

3.3.1 – 2022/12/15

  • Added apply_filters: ttfp_domains.

3.3.0 – 2022/12/15

  • Fixed performance in filters in admin.
  • Added temporary cache on polylang translations page (for 60s).
  • Added WordPress core and admin string scanner: default domain.
  • Loading translations on action: pll_language_defined

3.2.23 – 2022/12/12

  • Fixed performance in filters in admin.

3.2.22 – 2022/12/12

  • Fixed translators in filters.

3.2.21 – 2022/12/12

  • Removed esc_html filter.

3.2.20 – 2022/12/10

  • Fixed gettext filter for default domain.

3.2.19 – 2022/11/17

  • Security fix.

3.2.18 – 2022/11/17

  • Security fix.

3.2.17 – 2022/11/08

  • Security fix.

3.2.16 – 2022/11/04

  • Fixed gettext filter.

3.2.15 – 2022/11/04

  • Fixed gettext filter.

3.2.14 – 2022/11/03

  • Fixed gettext filter.

3.2.13 – 2022/05/26

  • Updated plugin description.
  • Test with Polylang version 3.2.3 and WordPress 6.0.

3.2.12 – 2021/06/15

  • Added esc_attr_e and esc_attr__ filter.

3.2.11 – 2021/05/17

  • Added esc_html filter.
  • Test with WordPress 5.7.2 version and Polylang version 3.0.4.
  • Updated version.

3.2.10 – 2021/05/10

  • Fixed gettext_with_context filter.

3.2.9 – 2021/05/04

  • Updated scanner regex.

3.2.8 – 2021/05/03

  • Updated scanner regex.
  • Updated readme.

3.2.7 – 2021/05/03

  • Updated scanner regex: added esc_html__.

3.2.6 – 2021/04/27

  • Updated scanner regex.
  • Test with Polylang version 3.0.4.
  • Updated version.

3.2.5 – 2021/02/20

  • UTF-8 header in csv exporter.
  • Test with Polylang version 2.9.2.
  • Updated version.

3.2.4 – 2020/09/13

  • Added ngettext polylang filter.
  • Added to file skaner function _n(): single + plural.
  • Test with Polylang version 2.8.2.
  • Updated version.

3.2.3 – 2020/03/26

  • Updated screens.
  • Refactoring.
  • Test with Polylang version 2.6.10.
  • Updated version.

3.2.2 – 2020/02/02

  • Fixed gettext filter.
  • Test with WordPress 5.3.2 version and Polylang version 2.6.9.
  • Updated version.

3.2.1 – 2019/12/07

  • Updated version.
  • Test with WordPress 5.3 version and Polylang version 2.6.7

3.2.0 – 2019/09/26

  • Added setting section in „TTfP Settings” tab.
  • Updated version.

3.1.1 – 2019/09/20

  • Fix file scanner.
  • Updated version.

3.1.0 – 2019/09/13

  • Translate strings from functions: _e( string $text, string $domain = 'default’ ) and __( string $text, string $domain = 'default’ ).
  • Updated plugin description.
  • Test with WordPress 5.2.3 version and Polylang version 2.6.x.
  • Updated version.

3.0.0 – 2019/05/12

  • Added import and export feature.
  • Updated plugin description.
  • Test with WordPress 5.2 version and Polylang version 2.5.x.
  • Updated version.

2.0.4 – 2018/12/10

  • Test with WordPress 5.0 version and Polylang version 2.5.
  • Updated version.

2.0.3 – 2018/07/04

  • Test with WordPress 4.9.5 version and Polylang version 2.3.4.
  • Updated version.

2.0.2 – 2018/01/02

  • Updated plugin description.
  • Test with WordPress 4.9 version and Polylang version 2.2.7.
  • Updated version.

2.0.1 – 2017/10/03

  • Wtyczka przetestowana na wersji WordPress 4.8 oraz wersji Polylang 2.2.3
  • Updated version.

2.0.0 – 2017/03/05

  • Added plugin scanner.
  • Updated version.

1.4.0 – 2017/01/29

  • Polylang version 2.1 – fixed: polylang changed default tab.
  • Updated version.

1.3.3 – 2017/01/09

  • Test with WordPress 4.7 version and Polylang version 2.0.12.
  • Updated version.

1.3.2 – 2016/09/07

  • Test with 4.6.1 WordPress version.
  • Updated version.

1.3.1 – 2016/06/07

  • Added plugin logo.

1.3 – 2016/05/15

  • Fixed warnings.
  • Test with 4.5 WordPress version.
  • Updated description.
  • Updated version.

1.2 – 2016/03/27

  • Updated description.

1.1 – 2016/02/03

  • Fixed readme.txt