From 9059b7ad79b24c3bba88768a655f9c4872189a3d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 3 Sep 2016 22:22:36 +0930 Subject: [PATCH] Fix locale JS files not being added; add (temporary?) API to add locale CSS files fixes flarum/core#970 --- framework/core/src/Event/ConfigureLocales.php | 4 ++++ framework/core/src/Http/WebApp/WebAppView.php | 8 ++++++++ framework/core/src/Locale/LocaleManager.php | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/framework/core/src/Event/ConfigureLocales.php b/framework/core/src/Event/ConfigureLocales.php index b22fd6e6b..0d8c461ad 100644 --- a/framework/core/src/Event/ConfigureLocales.php +++ b/framework/core/src/Event/ConfigureLocales.php @@ -63,6 +63,10 @@ class ConfigureLocales $this->locales->addJsFile($locale, $file); } + if (file_exists($file = $localeDir.'/config.css')) { + $this->locales->addCssFile($locale, $file); + } + foreach (new DirectoryIterator($localeDir) as $file) { if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) { $this->locales->addTranslations($locale, $file->getPathname()); diff --git a/framework/core/src/Http/WebApp/WebAppView.php b/framework/core/src/Http/WebApp/WebAppView.php index 58457c46f..90f193367 100644 --- a/framework/core/src/Http/WebApp/WebAppView.php +++ b/framework/core/src/Http/WebApp/WebAppView.php @@ -159,6 +159,14 @@ class WebAppView $locale = $this->locales->getLocale(); $this->localeJs = $this->assets->getLocaleJs($locale); $this->localeCss = $this->assets->getLocaleCss($locale); + + foreach ($this->locales->getJsFiles($locale) as $file) { + $this->localeJs->addFile($file); + } + + foreach ($this->locales->getCssFiles($locale) as $file) { + $this->localeCss->addFile($file); + } } /** diff --git a/framework/core/src/Locale/LocaleManager.php b/framework/core/src/Locale/LocaleManager.php index 1d34cc3ed..89e0a8dc7 100644 --- a/framework/core/src/Locale/LocaleManager.php +++ b/framework/core/src/Locale/LocaleManager.php @@ -23,6 +23,8 @@ class LocaleManager protected $js = []; + protected $css = []; + /** * @param SymfonyTranslator $translator */ @@ -79,6 +81,24 @@ class LocaleManager return $files; } + public function addCssFile($locale, $css) + { + $this->css[$locale][] = $css; + } + + public function getCssFiles($locale) + { + $files = array_get($this->css, $locale, []); + + $parts = explode('-', $locale); + + if (count($parts) > 1) { + $files = array_merge(array_get($this->css, $parts[0], []), $files); + } + + return $files; + } + /** * @return SymfonyTranslator */