diff --git a/CHANGELOG.md b/CHANGELOG.md index 7956dc3b0..62bfeb483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.42 +## mm/dd/2023 + +1. [](#new) + * Added a new `system.languages.debug` option that adds a `` around strings translated with `|t`. This can be styled by the theme as needed. + # v1.7.41.2 ## 06/01/2023 diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 14fef03ce..182457cbb 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -448,6 +448,17 @@ form: validate: type: bool + languages.debug: + type: toggle + label: PLUGIN_ADMIN.LANGUAGE_DEBUG + help: PLUGIN_ADMIN.LANGUAGE_DEBUG_HELP + highlight: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + http_headers: type: tab title: PLUGIN_ADMIN.HTTP_HEADERS diff --git a/system/config/system.yaml b/system/config/system.yaml index 2ffd02a8c..8bcc28075 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -28,6 +28,7 @@ languages: override_locale: false # Override the default or system locale with language specific one content_fallback: {} # Custom language fallbacks. eg: {fr: ['fr', 'en']} pages_fallback_only: false # DEPRECATED: Use `content_fallback` instead + debug: false # Debug language detection home: alias: '/home' # Default path for home, ie / diff --git a/system/src/Grav/Common/Twig/Extension/GravExtension.php b/system/src/Grav/Common/Twig/Extension/GravExtension.php index 9f54a1733..cfadb0417 100644 --- a/system/src/Grav/Common/Twig/Extension/GravExtension.php +++ b/system/src/Grav/Common/Twig/Extension/GravExtension.php @@ -46,6 +46,7 @@ use Twig\Error\RuntimeError; use Twig\Extension\AbstractExtension; use Twig\Extension\GlobalsInterface; use Twig\Loader\FilesystemLoader; +use Twig\Markup; use Twig\TwigFilter; use Twig\TwigFunction; use function array_slice; @@ -905,8 +906,13 @@ class GravExtension extends AbstractExtension implements GlobalsInterface return $this->grav['admin']->translate($args, $lang); } - // else use the default grav translate functionality - return $this->grav['language']->translate($args); + $translation = $this->grav['language']->translate($args); + + if ($this->config->get('system.languages.debug', false)) { + return new Markup("$translation", 'UTF-8'); + } else { + return $translation; + } } /**