diff --git a/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php b/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php new file mode 100644 index 00000000..c319ef33 --- /dev/null +++ b/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php @@ -0,0 +1,43 @@ +shortcodes()->addHandler('tr', static function (ShortcodeInterface $s) { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.I18n.enabled')) { + return ''; + } + + $varsDelimeter = $s->getParameter('varsDelimeter') ?: '|'; + + if ($s->getParameter('find') != null) { + + // Get vars + foreach($s->getParameters() as $key => $value) { + $vars = $value !== null ? strings($value)->contains($varsDelimeter) ? explode($varsDelimeter, $value) : [$value] : []; + } + + return __($vars[0], collectionFromQueryString($vars[1] ?? '')->toArray(), $vars[2] ?? null); + } + + return ''; +}); diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index ab9079dd..09a55b29 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -558,6 +558,9 @@ parsers: registry: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php" + url: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php" strings: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php" @@ -566,6 +569,10 @@ parsers: path: "/src/flextype/core/Parsers/Shortcodes/FilesystemShortcode.php" get: enabled: true + i18n: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php" + # CORS # diff --git a/tests/fixtures/settings/settings.yaml b/tests/fixtures/settings/settings.yaml index 5e9d349d..a79bdaa2 100644 --- a/tests/fixtures/settings/settings.yaml +++ b/tests/fixtures/settings/settings.yaml @@ -533,21 +533,32 @@ parsers: path: "/src/flextype/core/Parsers/Shortcodes/EntriesShortcode.php" fetch: enabled: true + php: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php" raw: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/RawShortcode.php" + markdown: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php" registry: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php" - url: - enabled: true - path: "/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php" strings: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php" + url: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php" filesystem: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/FilesystemShortcode.php" + get: + enabled: true + i18n: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php" # CORS # # CORS (Cross-origin resource sharing) allows JavaScript web apps to make HTTP requests to other domains. diff --git a/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php new file mode 100644 index 00000000..3656ed1d --- /dev/null +++ b/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php @@ -0,0 +1,7 @@ +shortcodes()->parse('[tr find="site_title"]'))->toBe('Site'); +});