mirror of
https://github.com/flarum/core.git
synced 2025-07-23 09:41:26 +02:00
Lay the groundwork for translation & refactor asset compilation
Ditched the idea of having language packs as extensions. Reasoning: 1. Because we use machine keys for translations (rather than English keys), extensions need to be able to define default translations. If English translations are to be included in extensions and not in a language pack extension, then it doesn’t make sense to have other languages as language pack extensions. Inconsistency → complexity. 2. Translations should maintain version parity with their respective extensions. There’s no way to do this if extension translations are external to the extension. Instead, localisation will be a core effort, as well as a per-extension effort. Translators will be encouraged to send PRs to core + extensions. In core, each locale has a directory containing three files: - translations.yml - config.js: contains pluralisation logic for the JS app, as well as moment.js localisation if necessary - config.php: contains pluralisation logic for the PHP app Extensions can use the Flarum\Extend\Locale extender to add/override translations/config to a locale. Asset compilation has been completely refactored with a better architecture. Translations + config.js are compiled and cached for the currently active locale.
This commit is contained in:
18
framework/core/src/Extend/AdminTranslations.php
Normal file
18
framework/core/src/Extend/AdminTranslations.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php namespace Flarum\Extend;
|
||||
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class AdminTranslations implements ExtenderInterface
|
||||
{
|
||||
protected $keys;
|
||||
|
||||
public function __construct($keys)
|
||||
{
|
||||
$this->keys = $keys;
|
||||
}
|
||||
|
||||
public function extend(Container $container)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@ class ForumAssets implements ExtenderInterface
|
||||
public function extend(Application $app)
|
||||
{
|
||||
$app['events']->listen('Flarum\Forum\Events\RenderView', function ($event) {
|
||||
$event->assets->addFile($this->files);
|
||||
$event->assets->addFiles($this->files);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
19
framework/core/src/Extend/ForumTranslations.php
Normal file
19
framework/core/src/Extend/ForumTranslations.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php namespace Flarum\Extend;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Flarum\Forum\Actions\IndexAction;
|
||||
|
||||
class ForumTranslations implements ExtenderInterface
|
||||
{
|
||||
protected $keys;
|
||||
|
||||
public function __construct($keys)
|
||||
{
|
||||
$this->keys = $keys;
|
||||
}
|
||||
|
||||
public function extend(Application $container)
|
||||
{
|
||||
IndexAction::$translations = array_merge(IndexAction::$translations, $this->keys);
|
||||
}
|
||||
}
|
57
framework/core/src/Extend/Locale.php
Normal file
57
framework/core/src/Extend/Locale.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php namespace Flarum\Extend;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
class Locale implements ExtenderInterface
|
||||
{
|
||||
protected $locale;
|
||||
|
||||
protected $translations;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected $js;
|
||||
|
||||
public function __construct($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function translations($translations)
|
||||
{
|
||||
$this->translations = $translations;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function config($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function js($js)
|
||||
{
|
||||
$this->js = $js;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extend(Application $container)
|
||||
{
|
||||
$manager = $container->make('flarum.localeManager');
|
||||
|
||||
if ($this->translations) {
|
||||
$manager->addTranslations($this->locale, $this->translations);
|
||||
}
|
||||
|
||||
if ($this->config) {
|
||||
$manager->addConfig($this->locale, $this->config);
|
||||
}
|
||||
|
||||
if ($this->js) {
|
||||
$manager->addJsFile($this->locale, $this->js);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user