Fix locale JS files not being added; add (temporary?) API to add locale CSS files

fixes flarum/core#970
This commit is contained in:
Toby Zerner 2016-09-03 22:22:36 +09:30
parent 7a7649ec7f
commit 9059b7ad79
3 changed files with 32 additions and 0 deletions

View File

@ -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());

View File

@ -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);
}
}
/**

View File

@ -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
*/