diff --git a/README.md b/README.md index 98bfaa3..6a7c4b3 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ A metabox labeled **Yard DeepL** is displayed on the edit screen of supported po ### Admin: Translation Cache Column -A **Translation cache** column is added to the post list screen of all supported post types. Its purpose is to notify editors which posts should be cached as soon as possible to avoid unnecessary DeepL API costs. +A **Cache** column can be added to the post list screen of all supported post types. It is off by default; enable it under **Settings > Yard DeepL > Translation cache column**. Its purpose is to notify editors which posts should be cached as soon as possible to avoid unnecessary DeepL API costs. - **Green badge per language** (e.g. `NL`, `EN-US`): a valid, up-to-date cached translation exists for that language. Visitor requests are served from cache at no cost. - **Yellow badge with a count per language** (e.g. `EN-US 3`): a cached translation exists, but that many visitor requests received only part of their texts because the rest is missing from the cache. Hovering the badge shows the full count as a tooltip. An editor visiting the page translates the missing texts, stores them and resets the count. diff --git a/assets/css/admin-columns.css b/assets/css/admin-columns.css index 37bec44..4c89aba 100644 --- a/assets/css/admin-columns.css +++ b/assets/css/admin-columns.css @@ -1,16 +1,20 @@ +.fixed .column-ydpl_translation_cache { + width: 6%; +} + .ydpl-cache-badges { display: flex; flex-wrap: wrap; - gap: 3px; + gap: 2px; } .ydpl-cache-badge { display: inline-flex; align-items: center; - gap: 4px; - font-size: 10px; + gap: 3px; + font-size: 9px; line-height: 1; - padding: 3px 6px; + padding: 2px 4px; border-radius: 3px; font-weight: 600; letter-spacing: 0.03em; diff --git a/dist/admin-columns.asset.php b/dist/admin-columns.asset.php index bb0a903..340bc6a 100644 --- a/dist/admin-columns.asset.php +++ b/dist/admin-columns.asset.php @@ -1 +1 @@ - array(), 'version' => '0921bcaa4b4ca4ac535b'); + array(), 'version' => '48a94204d54696f323e5'); diff --git a/dist/admin-columns.css b/dist/admin-columns.css index 8d7fb5d..bb96c92 100644 --- a/dist/admin-columns.css +++ b/dist/admin-columns.css @@ -1 +1 @@ -.ydpl-cache-badges{display:flex;flex-wrap:wrap;gap:3px}.ydpl-cache-badge{align-items:center;border-radius:3px;display:inline-flex;font-size:10px;font-weight:600;gap:4px;letter-spacing:.03em;line-height:1;padding:3px 6px}.ydpl-cache-badge--cached{background:#00a32a;color:#fff}.ydpl-cache-badge--incomplete{background:#dba617;color:#1d2327}.ydpl-cache-badge--uncached{background:#f0f0f1;color:#3c434a}.ydpl-badge-count{font-size:9px;font-weight:400;opacity:.7}.ydpl-cache-status--none{color:#8c8f94} +.fixed .column-ydpl_translation_cache{width:6%}.ydpl-cache-badges{display:flex;flex-wrap:wrap;gap:2px}.ydpl-cache-badge{align-items:center;border-radius:3px;display:inline-flex;font-size:9px;font-weight:600;gap:3px;letter-spacing:.03em;line-height:1;padding:2px 4px}.ydpl-cache-badge--cached{background:#00a32a;color:#fff}.ydpl-cache-badge--incomplete{background:#dba617;color:#1d2327}.ydpl-cache-badge--uncached{background:#f0f0f1;color:#3c434a}.ydpl-badge-count{font-size:9px;font-weight:400;opacity:.7}.ydpl-cache-status--none{color:#8c8f94} diff --git a/languages/yard-deepl-nl_NL.mo b/languages/yard-deepl-nl_NL.mo index 26d7fae..e9f79a2 100644 Binary files a/languages/yard-deepl-nl_NL.mo and b/languages/yard-deepl-nl_NL.mo differ diff --git a/languages/yard-deepl-nl_NL.po b/languages/yard-deepl-nl_NL.po index 7e191a2..c23e462 100644 --- a/languages/yard-deepl-nl_NL.po +++ b/languages/yard-deepl-nl_NL.po @@ -8,12 +8,12 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "POT-Creation-Date: 2026-07-31T00:00:00+00:00\n" -"PO-Revision-Date: 2026-07-31T00:00:00+00:00\n" +"PO-Revision-Date: 2026-11-10T15:32:27+00:00\n" "Language: \n" #. Plugin Name of the plugin #: yard-deepl.php:8 -#: src/Providers/MetaBoxServiceProvider.php:35 +#: src/Providers/MetaBoxServiceProvider.php:38 #: src/Providers/SettingsServiceProvider.php:44 #: src/Providers/SettingsServiceProvider.php:45 msgid "Yard DeepL" @@ -166,19 +166,51 @@ msgstr "Chinees (vereenvoudigd)" msgid "Chinese (Traditional)" msgstr "Chinees (traditioneel)" -#: src/Providers/MetaBoxServiceProvider.php:72 +#: src/Controllers/SettingsController.php:116 +msgid "The DeepL API base URL must be a valid https://*.deepl.com/v2/translate URL. The previous value has been kept." +msgstr "De DeepL API basis-URL moet een geldige https://*.deepl.com/v2/translate-URL zijn. De vorige waarde is behouden." + +#: src/Providers/AdminColumnsServiceProvider.php:68 +msgid "Cache" +msgstr "Cache" + +#: src/Providers/AdminColumnsServiceProvider.php:85 +msgid "No languages configured" +msgstr "Geen talen geconfigureerd" + +#. translators: %d: number of visitor requests that received only part of their texts from the cache +#: src/Providers/AdminColumnsServiceProvider.php:105 +#, php-format +msgid "%d incomplete response" +msgid_plural "%d incomplete responses" +msgstr[0] "%d onvolledig antwoord" +msgstr[1] "%d onvolledige antwoorden" + +#. translators: %d: number of uncached DeepL API calls made for this post and language +#: src/Providers/AdminColumnsServiceProvider.php:124 +#, php-format +msgid "%d uncached call" +msgid_plural "%d uncached calls" +msgstr[0] "%d aanroep zonder cache" +msgstr[1] "%d aanroepen zonder cache" + +#: src/Providers/AdminColumnsServiceProvider.php:135 +msgid "No cached translations" +msgstr "Geen gecachede vertalingen" + +#: src/Providers/MetaBoxServiceProvider.php:75 msgid "Disable translation cache when this object contains dynamic content." msgstr "Schakel de vertalingscache uit wanneer dit object dynamische inhoud bevat." -#: src/Providers/MetaBoxServiceProvider.php:75 +#: src/Providers/MetaBoxServiceProvider.php:78 msgid "Disable translation cache?" msgstr "Vertalingscache uitschakelen?" -#: src/Providers/MetaBoxServiceProvider.php:78 +#: src/Providers/MetaBoxServiceProvider.php:81 msgid "Clear cached translations on save." msgstr "Verwijder vertaalcache bij opslaan." -#: src/Providers/MetaBoxServiceProvider.php:81 +#: src/Providers/MetaBoxServiceProvider.php:84 msgid "Clear translation cache?" msgstr "Vertaalcache wissen?" @@ -198,14 +230,14 @@ msgstr "DeepL API-sleutel" msgid "DeepL supported languages" msgstr "DeepL ondersteunde talen" -#: src/Providers/SettingsServiceProvider.php:110 +#: src/Providers/SettingsServiceProvider.php:103 +msgid "Translation cache column" +msgstr "Vertaalcache-kolom" + +#: src/Providers/SettingsServiceProvider.php:119 msgid "Parameter object_id mandatory" msgstr "Parameter object_id verplicht" -#: src/Controllers/SettingsController.php:112 -msgid "The DeepL API base URL must be a valid https://*.deepl.com/v2/translate URL. The previous value has been kept." -msgstr "De DeepL API basis-URL moet een geldige https://*.deepl.com/v2/translate-URL zijn. De vorige waarde is behouden." - #. Translators: %s is the URL to the DeepL API documentation page. #: src/Views/admin/partials/settings/settings-description-general.php:10 msgid "website" @@ -217,31 +249,9 @@ msgstr "website" msgid "To query the DeepL API, an API key is required. You can find more information on their %s." msgstr "Om de DeepL API te bevragen, is een API-sleutel vereist. Meer informatie vind je op hun %s." -#: src/Providers/AdminColumnsServiceProvider.php:53 -msgid "Translation cache" -msgstr "Vertaalcache" - -#: src/Providers/AdminColumnsServiceProvider.php:70 -msgid "No languages configured" -msgstr "Geen talen geconfigureerd" - -#: src/Providers/AdminColumnsServiceProvider.php:105 -msgid "No cached translations" -msgstr "Geen gecachede vertalingen" - -#. Translators: %d is the number of visitor requests that received only part of their texts from the cache. -#: src/Providers/AdminColumnsServiceProvider.php:90 -msgid "%d incomplete response" -msgid_plural "%d incomplete responses" -msgstr[0] "%d onvolledig antwoord" -msgstr[1] "%d onvolledige antwoorden" - -#. Translators: %d is the number of uncached DeepL API calls made for this post and language. -#: src/Providers/AdminColumnsServiceProvider.php:109 -msgid "%d uncached call" -msgid_plural "%d uncached calls" -msgstr[0] "%d aanroep zonder cache" -msgstr[1] "%d aanroepen zonder cache" +#: src/Views/admin/partials/settings/settings-fields.php:44 +msgid "Show which languages are cached on post list screens" +msgstr "Toon in overzichten welke talen in de cache staan" #: src/Views/admin/settings-page.php:15 msgid "Save" diff --git a/languages/yard-deepl.pot b/languages/yard-deepl.pot index 28fe3db..b7cc57c 100644 --- a/languages/yard-deepl.pot +++ b/languages/yard-deepl.pot @@ -2,21 +2,21 @@ # This file is distributed under the GPLv2 or later. msgid "" msgstr "" -"Project-Id-Version: Yard DeepL 1.1.0\n" +"Project-Id-Version: Yard DeepL 2.2.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/yard-deepl\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2026-07-31T00:00:00+00:00\n" +"POT-Creation-Date: 2026-11-10T15:32:27+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.12.0\n" "X-Domain: yard-deepl\n" #. Plugin Name of the plugin #: yard-deepl.php:8 -#: src/Providers/MetaBoxServiceProvider.php:35 +#: src/Providers/MetaBoxServiceProvider.php:38 #: src/Providers/SettingsServiceProvider.php:44 #: src/Providers/SettingsServiceProvider.php:45 msgid "Yard DeepL" @@ -169,19 +169,51 @@ msgstr "" msgid "Chinese (Traditional)" msgstr "" -#: src/Providers/MetaBoxServiceProvider.php:72 -msgid "Disable translation cache when this object contains dynamic content." +#: src/Controllers/SettingsController.php:116 +msgid "The DeepL API base URL must be a valid https://*.deepl.com/v2/translate URL. The previous value has been kept." +msgstr "" + +#: src/Providers/AdminColumnsServiceProvider.php:68 +msgid "Cache" +msgstr "" + +#: src/Providers/AdminColumnsServiceProvider.php:85 +msgid "No languages configured" +msgstr "" + +#. translators: %d: number of visitor requests that received only part of their texts from the cache +#: src/Providers/AdminColumnsServiceProvider.php:105 +#, php-format +msgid "%d incomplete response" +msgid_plural "%d incomplete responses" +msgstr[0] "" +msgstr[1] "" + +#. translators: %d: number of uncached DeepL API calls made for this post and language +#: src/Providers/AdminColumnsServiceProvider.php:124 +#, php-format +msgid "%d uncached call" +msgid_plural "%d uncached calls" +msgstr[0] "" +msgstr[1] "" + +#: src/Providers/AdminColumnsServiceProvider.php:135 +msgid "No cached translations" msgstr "" #: src/Providers/MetaBoxServiceProvider.php:75 -msgid "Disable translation cache?" +msgid "Disable translation cache when this object contains dynamic content." msgstr "" #: src/Providers/MetaBoxServiceProvider.php:78 -msgid "Clear cached translations on save." +msgid "Disable translation cache?" msgstr "" #: src/Providers/MetaBoxServiceProvider.php:81 +msgid "Clear cached translations on save." +msgstr "" + +#: src/Providers/MetaBoxServiceProvider.php:84 msgid "Clear translation cache?" msgstr "" @@ -201,12 +233,12 @@ msgstr "" msgid "DeepL supported languages" msgstr "" -#: src/Providers/SettingsServiceProvider.php:110 -msgid "Parameter object_id mandatory" +#: src/Providers/SettingsServiceProvider.php:103 +msgid "Translation cache column" msgstr "" -#: src/Controllers/SettingsController.php:112 -msgid "The DeepL API base URL must be a valid https://*.deepl.com/v2/translate URL. The previous value has been kept." +#: src/Providers/SettingsServiceProvider.php:119 +msgid "Parameter object_id mandatory" msgstr "" #. Translators: %s is the URL to the DeepL API documentation page. @@ -220,32 +252,10 @@ msgstr "" msgid "To query the DeepL API, an API key is required. You can find more information on their %s." msgstr "" -#: src/Providers/AdminColumnsServiceProvider.php:53 -msgid "Translation cache" -msgstr "" - -#: src/Providers/AdminColumnsServiceProvider.php:70 -msgid "No languages configured" +#: src/Views/admin/partials/settings/settings-fields.php:44 +msgid "Show which languages are cached on post list screens" msgstr "" -#: src/Providers/AdminColumnsServiceProvider.php:105 -msgid "No cached translations" -msgstr "" - -#. Translators: %d is the number of visitor requests that received only part of their texts from the cache. -#: src/Providers/AdminColumnsServiceProvider.php:90 -msgid "%d incomplete response" -msgid_plural "%d incomplete responses" -msgstr[0] "" -msgstr[1] "" - -#. Translators: %d is the number of uncached DeepL API calls made for this post and language. -#: src/Providers/AdminColumnsServiceProvider.php:109 -msgid "%d uncached call" -msgid_plural "%d uncached calls" -msgstr[0] "" -msgstr[1] "" - #: src/Views/admin/settings-page.php:15 msgid "Save" msgstr "" diff --git a/readme.txt b/readme.txt index 709b60b..9190170 100644 --- a/readme.txt +++ b/readme.txt @@ -35,7 +35,7 @@ A metabox labeled Yard DeepL is displayed on the edit screen of supported post t = Admin: Translation Cache Column = -A Translation cache column is added to the post list screen of all supported post types. Its purpose is to notify editors which posts should be cached as soon as possible to avoid unnecessary DeepL API costs. +A Cache column can be added to the post list screen of all supported post types. It is off by default; enable it under Settings > Yard DeepL > Translation cache column. Its purpose is to notify editors which posts should be cached as soon as possible to avoid unnecessary DeepL API costs. * Green badge per language (e.g. NL, EN-US): a valid, up-to-date cached translation exists for that language. Visitor requests are served from cache at no cost. * Yellow badge with a count per language (e.g. EN-US 3): a cached translation exists, but that many visitor requests received only part of their texts because the rest is missing from the cache. Hovering the badge shows the full count as a tooltip. An editor visiting the page translates the missing texts, stores them and resets the count. diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php index db65207..0e22afd 100644 --- a/src/Controllers/SettingsController.php +++ b/src/Controllers/SettingsController.php @@ -55,6 +55,7 @@ public function section_fields_render( array $args ): void 'supported_languages' => ydpl_resolve_from_container( 'ydpl.supported_target.languages' ), 'configured_supported_languages' => ydpl_resolve_from_container( 'ydpl.site_options' )->configured_supported_languages(), 'rest_api_param_object_id_is_mandatory' => ydpl_resolve_from_container( 'ydpl.site_options' )->rest_api_param_object_id_is_mandatory(), + 'admin_column_enabled' => ydpl_resolve_from_container( 'ydpl.site_options' )->admin_column_enabled(), ) ); } diff --git a/src/Providers/AdminColumnsServiceProvider.php b/src/Providers/AdminColumnsServiceProvider.php index d720f68..f3d0375 100644 --- a/src/Providers/AdminColumnsServiceProvider.php +++ b/src/Providers/AdminColumnsServiceProvider.php @@ -19,6 +19,8 @@ * target languages already have a valid, non-stale cached translation so editors * can spot at a glance which posts will trigger a live DeepL API call. * + * Off by default: list screens get crowded, so sites opt in on the settings page. + * * @since 2.0.0 */ class AdminColumnsServiceProvider implements ServiceProviderInterface @@ -37,6 +39,10 @@ public function __construct() */ public function register(): void { + if ( ! ydpl_resolve_from_container( 'ydpl.site_options' )->admin_column_enabled() ) { + return; + } + add_action( 'admin_init', array( $this, 'register_columns' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); } @@ -59,7 +65,7 @@ public function register_columns(): void */ public function add_column( array $columns ): array { - $columns['ydpl_translation_cache'] = __( 'Translation cache', 'yard-deepl' ); + $columns['ydpl_translation_cache'] = __( 'Cache', 'yard-deepl' ); return $columns; } diff --git a/src/Providers/SettingsServiceProvider.php b/src/Providers/SettingsServiceProvider.php index 2c989d6..ac14d34 100644 --- a/src/Providers/SettingsServiceProvider.php +++ b/src/Providers/SettingsServiceProvider.php @@ -98,6 +98,15 @@ public function register_settings_options(): void array( 'settings_field_id' => 'ydpl_supported_target_languages' ) ); + add_settings_field( + 'ydpl_admin_column_enabled', + __( 'Translation cache column', 'yard-deepl' ), + array( $this->controller, 'section_fields_render' ), + 'yard-deepl', + 'ydpl_section_general', + array( 'settings_field_id' => 'ydpl_admin_column_enabled' ) + ); + add_settings_section( 'ydpl_section_rest_api', 'REST API', diff --git a/src/Singletons/SiteOptionsSingleton.php b/src/Singletons/SiteOptionsSingleton.php index e994e6a..ed99bea 100644 --- a/src/Singletons/SiteOptionsSingleton.php +++ b/src/Singletons/SiteOptionsSingleton.php @@ -87,4 +87,12 @@ public function rest_api_param_object_id_is_mandatory(): bool return 'on' === $value; } + + /** + * @since NEXT + */ + public function admin_column_enabled(): bool + { + return 'on' === ( $this->options['ydpl_admin_column_enabled'] ?? '' ); + } } diff --git a/src/Views/admin/partials/settings/settings-fields.php b/src/Views/admin/partials/settings/settings-fields.php index 4cff557..18ed3d7 100644 --- a/src/Views/admin/partials/settings/settings-fields.php +++ b/src/Views/admin/partials/settings/settings-fields.php @@ -13,6 +13,7 @@ $supported_languages = is_array( $supported_languages ?? null ) ? $supported_languages : array(); $configured_supported_languages = is_array( $configured_supported_languages ?? null ) ? $configured_supported_languages : array(); $rest_api_param_object_id_is_mandatory = $rest_api_param_object_id_is_mandatory ?? true; +$admin_column_enabled = $admin_column_enabled ?? false; ?> @@ -36,3 +37,10 @@ > + + + +