diff --git a/config/services.yaml b/config/services.yaml index 5580cfd3..6d5ee3bf 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -65,5 +65,6 @@ services: arguments: $base_currency: '%default_currency%' - # add more service definitions when explicit configuration is needed - # please note that last definitions always *replace* previous ones + App\Services\TranslationExtractor\PermissionExtractor: + tags: + - { name: 'translation.extractor', alias: 'permissionExtractor'} \ No newline at end of file diff --git a/src/Services/TranslationExtractor/PermissionExtractor.php b/src/Services/TranslationExtractor/PermissionExtractor.php new file mode 100644 index 00000000..56017af5 --- /dev/null +++ b/src/Services/TranslationExtractor/PermissionExtractor.php @@ -0,0 +1,104 @@ +permission_structure = $resolver->getPermissionStructure(); + } + + /** + * Extracts translation messages from files, a file or a directory to the catalogue. + * + * @param string|array $resource Files, a file or a directory + * @param MessageCatalogue $catalogue The catalogue + */ + public function extract($resource, MessageCatalogue $catalogue) + { + if (!$this->finished) { + //Extract for every group... + foreach ($this->permission_structure['groups'] as $group) { + if (isset($group['label'])) { + $catalogue->add([ + $group['label'] => '__' . $group['label'] + ]); + } + } + + //... every permission + foreach ($this->permission_structure['perms'] as $perm) { + if (isset($perm['label'])) { + $catalogue->add([ + $perm['label'] => '__' . $perm['label'] + ]); + } + + //... and all of their operations + foreach ($perm['operations'] as $op) { + if (isset($op['label'])) { + $catalogue->add([ + $op['label'] => '__' . $op['label'] + ]); + } + } + } + + + $this->finished = true; + } + } + + /** + * Sets the prefix that should be used for new found messages. + * + * @param string $prefix The prefix + */ + public function setPrefix($prefix) + { + return ''; + } +} \ No newline at end of file