Skip to content

Commit

Permalink
fix(rtl): Make clear that the direction is based on language
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Sep 18, 2024
1 parent a22001a commit b020d9e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ public function languageExists($app, $lang) {
}


public function getLanguageDirectionFromLocale(string $locale): string
public function getLanguageDirection(string $language): string
{
if (in_array($locale, self::RTL_LANGUAGES)) {
if (in_array($language, self::RTL_LANGUAGES, true)) {
return 'rtl';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function __construct($renderAs, $appId = '') {
// 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);
Expand Down
6 changes: 3 additions & 3 deletions lib/public/L10N/IFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public function languageExists($app, $lang);
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:
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/L10N/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ public function testGetLanguageIterator(bool $hasSession, ?IUser $iUserMock = nu
self::assertInstanceOf(ILanguageIterator::class, $iterator);
}

public static function languagesWithRespectedDirection():array {
public static function dataGetLanguageDirection(): array {
return [
['en', 'ltr'],
['de', 'ltr'],
Expand All @@ -786,11 +786,11 @@ public static function languagesWithRespectedDirection():array {
}

/**
* @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));
}
}

0 comments on commit b020d9e

Please sign in to comment.