rauwebieten / craft-translations-extractor
Craft CMS Translations Extractor
Installs: 58
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Type:craft-plugin
Requires
- php: ^7.2.5|^8.0
- craftcms/cms: ^4.0.0
- lucleroy/php-regex: ^0.5.0
Requires (Dev)
- php: ^7.2.5|^8.0
- craftcms/cms: ^4.0.0
- vlucas/phpdotenv: ^3.0
README
WORK IN PROGRESS, USE AT OWN RISK
Requirements
This plugin requires Craft CMS 3.5 later.
Installation
composer require rauwebieten/craft-translations-extractor
Usage
php craft translations-extractor/index
This command will search for translations strings in your templates folder. This command uses a regular expression to find all translation strings, it will find following translation strings:
<p> {# translation with t filter #} {{ "Hello world"|t }} {# translation with translate filter #} {{ "Hello craft"|translate }} {# translation with single quotes #} {{ 'Hello template'|t }} {# translation with single/double quotes #} {{ 'This is a "quoted string"'|t }} {{ "This is another \"quoted string\""|t }} {{ 'This too is a \'quoted string\''|t|raw }} </p>
Foreach defined language in your project it will create a translation file.
- Translation string that are not in use anymore, are removed from the translation file
- Existing translations strings are merge with the newly found translations strings
translations/en/site-extracted.php
Do whatever you like with this file. For example, include it in the main translation file. This way you can still use a site.php file with your custom translation strings.
// translations/en/site.php <?php return array_merge(include __DIR__ .'site-extracted.php',[ 'other-translation-strings' => 'blah blah' ]);
Not supported.
This plugin is a work in progress. Use at own risk.
This plugin cannot:
- detect translation strings with parameters, like
"{num} pages"(params={num:3})
- detect translation strings with other namespaces, like
"hello"|t('plugin-handle')
Roadmap
- resolve issues as mentioned above
- use a translation API
- Craft 4 support