mirror of
https://github.com/nextcloud/server.git
synced 2026-04-05 00:56:16 -04:00
feat(rtl): Set layout direction based on language
Signed-off-by: ali ghorbani <ghorbani.ali.developer@gmail.com>
This commit is contained in:
parent
a8ee7424ad
commit
2b7efd66b6
4 changed files with 29 additions and 2 deletions
|
|
@ -51,7 +51,7 @@ p($theme->getTitle());
|
|||
<?php emit_script_loading_tags($_); ?>
|
||||
<?php print_unescaped($_['headers']); ?>
|
||||
</head>
|
||||
<body id="<?php p($_['bodyid']);?>" <?php foreach ($_['enabledThemes'] as $themeId) {
|
||||
<body dir="<?php p($_['direction']); ?>" id="<?php p($_['bodyid']);?>" <?php foreach ($_['enabledThemes'] as $themeId) {
|
||||
p("data-theme-$themeId ");
|
||||
}?> data-themes=<?php p(join(',', $_['enabledThemes'])) ?>>
|
||||
<?php include 'layout.noscript.warning.php'; ?>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,12 @@ class Factory implements IFactory {
|
|||
'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
|
||||
];
|
||||
|
||||
public const RTL_LANGUAGES = [
|
||||
'ae', 'ar', 'arc', 'arz', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk',
|
||||
'ha', 'he', 'khw', 'ks', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug',
|
||||
'ur', 'uzs', 'yi',
|
||||
];
|
||||
|
||||
private ICache $cache;
|
||||
|
||||
public function __construct(
|
||||
|
|
@ -364,6 +370,16 @@ class Factory implements IFactory {
|
|||
return in_array($lang, $languages);
|
||||
}
|
||||
|
||||
|
||||
public function getLanguageDirectionFromLocale(string $locale): string
|
||||
{
|
||||
if (in_array($locale, self::RTL_LANGUAGES)) {
|
||||
return 'rtl';
|
||||
}
|
||||
|
||||
return 'ltr';
|
||||
}
|
||||
|
||||
public function getLanguageIterator(?IUser $user = null): ILanguageIterator {
|
||||
$user = $user ?? $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
|
|
|
|||
|
|
@ -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()->getLanguageDirectionFromLocale($locale);
|
||||
|
||||
$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)) {
|
||||
|
|
|
|||
|
|
@ -103,6 +103,15 @@ interface IFactory {
|
|||
*/
|
||||
public function localeExists($locale);
|
||||
|
||||
/**
|
||||
* Return the current language direction from locale
|
||||
*
|
||||
* @param string $locale
|
||||
* @return 'ltr'|'rtl'
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function getLanguageDirectionFromLocale(string $locale): string;
|
||||
|
||||
/**
|
||||
* iterate through language settings (if provided) in this order:
|
||||
* 1. returns the forced language or:
|
||||
|
|
|
|||
Loading…
Reference in a new issue