Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fired events in the theme scanner. #576

Merged
merged 6 commits into from May 5, 2020
Merged

Conversation

bereznev
Copy link
Contributor

Fired events in ThemeScanner.php class for ability to extend scan method.

@LukeTowers
Copy link
Contributor

@bereznev please provide a real world use case for both proposed events. Additionally, please add inline event documentation (example here: https://github.com/octobercms/october/blob/develop/modules/backend/classes/Controller.php#L245-L263)

@bereznev
Copy link
Contributor Author

I added an extra scan for the php classes. Using it allows you to add words list using constants (properties) to prevent duplication of these lists. And I need to automatically generate translation files after scanning.

@LukeTowers
Copy link
Contributor

Please provide the code you use to listen to the event so I can better understand the purpose.

@bereznev
Copy link
Contributor Author

bereznev commented Apr 21, 2020

  Event::listen('translate.themeScanner.afterScan', function (ThemeScanner $scanner) {
            $dir = themes_path('my-theme/assets/lang');
            if (!is_dir($dir)) {
                File::makeDirectory($dir);
            }
            $exportMode = new MessageExport();
            $result = $exportMode->exportData(['code', 'sk', 'en', 'x',]);

            foreach (['sk', 'en'] as $lang) {
                $content = collect($result)->keyBy('x')->map(function (array $item) use ($lang) {
                    return $item[$lang];
                })->toArray();
                File::put("{$dir}/{$lang}.json", json_encode($content));
            }
        });

@LukeTowers
Copy link
Contributor

Change the event names in all the places it's referenced please.

@mjauvin mjauvin added this to the 1.7.2 milestone Apr 23, 2020
@mjauvin
Copy link
Contributor

mjauvin commented Apr 23, 2020

LGTM!

README.md Outdated Show resolved Hide resolved
@LukeTowers
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants