fix(rtl): Make clear that the direction is based on language

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-09-18 11:13:30 +02:00
parent 242f89afb3
commit 82566c5479
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
4 changed files with 10 additions and 11 deletions

View file

@ -377,9 +377,8 @@ class Factory implements IFactory {
return in_array($lang, $languages);
}
public function getLanguageDirectionFromLocale(string $locale): string {
if (in_array($locale, self::RTL_LANGUAGES)) {
public function getLanguageDirection(string $language): string {
if (in_array($language, self::RTL_LANGUAGES, true)) {
return 'rtl';
}

View file

@ -196,7 +196,7 @@ class TemplateLayout extends \OC_Template {
// 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);
$direction = \OC::$server->getL10NFactory()->getLanguageDirection($lang);
$lang = str_replace('_', '-', $lang);
$this->assign('language', $lang);

View file

@ -104,13 +104,13 @@ interface IFactory {
public function localeExists($locale);
/**
* Return the current language direction from locale
* Return the language direction
*
* @param string $locale
* @param string $language
* @return 'ltr'|'rtl'
* @since 31.0.0
*/
public function getLanguageDirectionFromLocale(string $locale): string;
public function getLanguageDirection(string $language): string;
/**
* iterate through language settings (if provided) in this order:

View file

@ -776,7 +776,7 @@ class FactoryTest extends TestCase {
self::assertInstanceOf(ILanguageIterator::class, $iterator);
}
public static function languagesWithRespectedDirection():array {
public static function dataGetLanguageDirection(): array {
return [
['en', 'ltr'],
['de', 'ltr'],
@ -786,11 +786,11 @@ class FactoryTest extends TestCase {
}
/**
* @dataProvider languagesWithRespectedDirection
* @dataProvider dataGetLanguageDirection
*/
public function testDirectionOfLocales(string $locale, string $expectedDirection) {
public function testGetLanguageDirection(string $language, string $expectedDirection) {
$factory = $this->getFactory();
self::assertEquals($expectedDirection, $factory->getLanguageDirectionFromLocale($locale));
self::assertEquals($expectedDirection, $factory->getLanguageDirection($language));
}
}