diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-09-24 11:27:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 11:27:42 +0200 |
commit | 12ed773b58f023a642a4f03acfa8a5f9c3d58ce5 (patch) | |
tree | 76113c3366a9dabb7f5ac9c852c216738647efc4 /lib | |
parent | 129f6b2e5c4d7532593edfdffdfe3c3d1e776546 (diff) | |
parent | 82566c5479b7cf3374501a1e6b113680ae75afee (diff) | |
download | nextcloud-server-12ed773b58f023a642a4f03acfa8a5f9c3d58ce5.tar.gz nextcloud-server-12ed773b58f023a642a4f03acfa8a5f9c3d58ce5.zip |
Merge pull request #47349 from nextcloud/feat/31420/bidi-backend-support
Add bidirectional text support - Backend
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/L10N/Factory.php | 21 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 4 | ||||
-rw-r--r-- | lib/public/L10N/IFactory.php | 9 |
3 files changed, 33 insertions, 1 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 7dd0704682d..a519ae7e761 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -58,6 +58,19 @@ class Factory implements IFactory { 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' ]; + /** + * Keep in sync with `build/translation-checker.php` + */ + public const RTL_LANGUAGES = [ + 'ar', // Arabic + 'fa', // Persian + 'he', // Hebrew + 'ps', // Pashto, + 'ug', // 'Uyghurche / Uyghur + 'ur_PK', // Urdu + 'uz', // Uzbek Afghan + ]; + private ICache $cache; public function __construct( @@ -364,6 +377,14 @@ class Factory implements IFactory { return in_array($lang, $languages); } + public function getLanguageDirection(string $language): string { + if (in_array($language, self::RTL_LANGUAGES, true)) { + return 'rtl'; + } + + return 'ltr'; + } + public function getLanguageIterator(?IUser $user = null): ILanguageIterator { $user = $user ?? $this->userSession->getUser(); if ($user === null) { diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index c21df495b5b..60c7526435e 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -193,13 +193,15 @@ class TemplateLayout extends \OC_Template { } else { parent::__construct('core', 'layout.base'); } - // Send the language and the locale to our layouts + // Send the language, locale, and direction to our layouts $lang = \OC::$server->get(IFactory::class)->findLanguage(); $locale = \OC::$server->get(IFactory::class)->findLocale($lang); + $direction = \OC::$server->getL10NFactory()->getLanguageDirection($lang); $lang = str_replace('_', '-', $lang); $this->assign('language', $lang); $this->assign('locale', $locale); + $this->assign('direction', $direction); if (\OC::$server->getSystemConfig()->getValue('installed', false)) { if (empty(self::$versionHash)) { diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 5c2f4dcbfa4..aebd318dfad 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -104,6 +104,15 @@ interface IFactory { public function localeExists($locale); /** + * Return the language direction + * + * @param string $language + * @return 'ltr'|'rtl' + * @since 31.0.0 + */ + public function getLanguageDirection(string $language): string; + + /** * iterate through language settings (if provided) in this order: * 1. returns the forced language or: * 2. if applicable, the trunk of 1 (e.g. "fu" instead of "fu_BAR" |