Upgrade to 3.2.0
This commit is contained in:
@@ -2,8 +2,20 @@
|
||||
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Data\Data;
|
||||
use Kirby\Toolkit\F;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* AppTranslations
|
||||
*
|
||||
* @package Kirby Cms
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://getkirby.com/license
|
||||
*/
|
||||
trait AppTranslations
|
||||
{
|
||||
protected $translations;
|
||||
@@ -13,9 +25,9 @@ trait AppTranslations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function i18n()
|
||||
protected function i18n(): void
|
||||
{
|
||||
I18n::$load = function ($locale) {
|
||||
I18n::$load = function ($locale): array {
|
||||
$data = [];
|
||||
|
||||
if ($translation = $this->translation($locale)) {
|
||||
@@ -25,12 +37,16 @@ trait AppTranslations
|
||||
// inject translations from the current language
|
||||
if ($this->multilang() === true && $language = $this->languages()->find($locale)) {
|
||||
$data = array_merge($data, $language->translations());
|
||||
|
||||
// Add language slug rules to Str class
|
||||
Str::$language = $language->rules();
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
};
|
||||
|
||||
I18n::$locale = function () {
|
||||
I18n::$locale = function (): string {
|
||||
if ($this->multilang() === true) {
|
||||
return $this->defaultLanguage()->code();
|
||||
} else {
|
||||
@@ -38,7 +54,7 @@ trait AppTranslations
|
||||
}
|
||||
};
|
||||
|
||||
I18n::$fallback = function () {
|
||||
I18n::$fallback = function (): string {
|
||||
if ($this->multilang() === true) {
|
||||
return $this->defaultLanguage()->code();
|
||||
} else {
|
||||
@@ -47,6 +63,20 @@ trait AppTranslations
|
||||
};
|
||||
|
||||
I18n::$translations = [];
|
||||
|
||||
if (isset($this->options['slugs']) === true) {
|
||||
$file = $this->root('i18n:rules') . '/' . $this->options['slugs'] . '.json';
|
||||
|
||||
if (F::exists($file) === true) {
|
||||
try {
|
||||
$data = Data::read($file);
|
||||
} catch (\Exception $e) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
Str::$language = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +85,7 @@ trait AppTranslations
|
||||
*
|
||||
* @internal
|
||||
* @param string $languageCode
|
||||
* @return Language|null
|
||||
* @return Kirby\Cms\Language|null
|
||||
*/
|
||||
public function setCurrentLanguage(string $languageCode = null)
|
||||
{
|
||||
@@ -84,7 +114,7 @@ trait AppTranslations
|
||||
* @param string $translationCode
|
||||
* @return void
|
||||
*/
|
||||
public function setCurrentTranslation(string $translationCode = null)
|
||||
public function setCurrentTranslation(string $translationCode = null): void
|
||||
{
|
||||
I18n::$locale = $translationCode ?? 'en';
|
||||
}
|
||||
@@ -95,7 +125,7 @@ trait AppTranslations
|
||||
* @internal
|
||||
* @param string|array $locale
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
public function setLocale($locale): void
|
||||
{
|
||||
if (is_array($locale) === true) {
|
||||
foreach ($locale as $key => $value) {
|
||||
@@ -110,7 +140,7 @@ trait AppTranslations
|
||||
* Load a specific translation by locale
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return Translation|null
|
||||
* @return Kirby\Cms\Translation|null
|
||||
*/
|
||||
public function translation(string $locale = null)
|
||||
{
|
||||
@@ -134,7 +164,7 @@ trait AppTranslations
|
||||
/**
|
||||
* Returns all available translations
|
||||
*
|
||||
* @return Translations
|
||||
* @return Kirby\Cms\Translations
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
|
Reference in New Issue
Block a user