Homepage
Main navigation
Main content
Additional information
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Winter CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
This trick is a handy way of distributing Winter.Translate-ready translations with your plugin so that they can be used and overridden by themes. ```php <?php namespace Acme\Demo; use Lang; use Event; use System\Classes\PluginBase; class Demo extends PluginBase { public function boot() { Event::listen('cms.theme.extendConfig', function ($dirName, &$config) { $locales = []; $results = []; $prefix = 'frontend'; $loader = Lang::getLoader(); // Get the namespace of the current plugin $namespace = str_replace('\\', '.', strtolower(__NAMESPACE__)); // Scan for available languages under this plugin $localeDirectories = glob(plugins_path(str_replace('.', '/', $namespace) . '/lang/*', GLOB_ONLYDIR)); if (empty($localeDirectories)) { return; } foreach ($localeDirectories as $dir) { $locales[] = pathinfo($dir, PATHINFO_BASENAME); } // Load the messages under the given prefix and prepare them for use // as frontend messages foreach ($locales as $locale) { $translations = $loader->load($locale, 'lang', $namespace); if (!empty($translations[$prefix])) { $results[$locale] = array_dot($translations[$prefix]); } } if (empty($results)) { return; } // Load the plugin's messages into the theme's config, deferring to theme defined messages if present foreach ($results as $locale => $messages) { $config['translate'][$locale] = array_merge($messages, @$config['translate'][$locale] ?: []); } }); } } ```
References
Add additional online resources to your trick
×
Name
URL
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline