Skip to content

Commit 258057a

Browse files
committed
Add I18n\TextDirection enum
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
1 parent c2b1e31 commit 258057a

10 files changed

Lines changed: 24 additions & 13 deletions

src/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function getJsParams(): array
115115
'table' => Current::$table,
116116
'db' => Current::$database,
117117
'token' => $_SESSION[' PMA_token '],
118-
'text_dir' => LanguageManager::$textDir,
118+
'text_dir' => LanguageManager::$textDirection->value,
119119
'LimitChars' => $this->config->settings['LimitChars'],
120120
'pftext' => $pftext,
121121
'confirm' => $this->config->settings['Confirm'],

src/I18n/Language.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ public function activate(): void
163163
setlocale(0, $this->code);
164164
}
165165

166-
/* Text direction for language */
167-
LanguageManager::$textDir = $this->isRTL() ? 'rtl' : 'ltr';
166+
LanguageManager::$textDirection = $this->isRTL() ? TextDirection::RightToLeft : TextDirection::LeftToRight;
168167

169168
/* TCPDF */
170169
$GLOBALS['l'] = [];
171170

172171
/* TCPDF settings */
173172
$GLOBALS['l']['a_meta_charset'] = 'UTF-8';
174-
$GLOBALS['l']['a_meta_dir'] = LanguageManager::$textDir;
173+
$GLOBALS['l']['a_meta_dir'] = LanguageManager::$textDirection->value;
175174
$GLOBALS['l']['a_meta_language'] = $this->code;
176175

177176
/* TCPDF translations */

src/I18n/LanguageManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ class LanguageManager
723723

724724
private static LanguageManager|null $instance = null;
725725

726-
/** @psalm-var 'ltr'|'rtl' */
727-
public static string $textDir = 'ltr';
726+
public static TextDirection $textDirection = TextDirection::LeftToRight;
727+
728728
private readonly Config $config;
729729

730730
public function __construct()

src/I18n/TextDirection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\I18n;
6+
7+
enum TextDirection: string
8+
{
9+
case LeftToRight = 'ltr';
10+
case RightToLeft = 'rtl';
11+
}

src/InsertEdit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private function getTextarea(
404404
. (isset($maxlength) ? ' data-maxlength="' . $maxlength . '"' : '')
405405
. ' rows="' . $textAreaRows . '"'
406406
. ' cols="' . $textareaCols . '"'
407-
. ' dir="' . LanguageManager::$textDir . '"'
407+
. ' dir="' . LanguageManager::$textDirection->value . '"'
408408
. ' id="field_' . $this->fieldIndex . '_3"'
409409
. ($onChangeClause !== '' ? ' onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' : '')
410410
. ' tabindex="' . $this->fieldIndex . '"'

src/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getInputHtml(
5757
$class = 'transform_' . strtolower(static::getName()) . '_editor';
5858

5959
return $html . '<textarea name="fields' . $columnNameAppendix . '"'
60-
. ' dir="' . LanguageManager::$textDir . '" class="' . $class . '">'
60+
. ' dir="' . LanguageManager::$textDirection->value . '" class="' . $class . '">'
6161
. htmlspecialchars($value) . '</textarea>';
6262
}
6363
}

src/Plugins/Transformations/Input/Text_Plain_Iptobinary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getInputHtml(
8484
return $html . '<input type="text" name="fields' . $columnNameAppendix . '"'
8585
. ' value="' . htmlspecialchars($val) . '"'
8686
. ' size="40"'
87-
. ' dir="' . LanguageManager::$textDir . '"'
87+
. ' dir="' . LanguageManager::$textDirection->value . '"'
8888
. ' class="' . $class . '"'
8989
. ' id="field_' . $fieldIndex . '_3"'
9090
. ' tabindex="' . $fieldIndex . '">';

src/Plugins/Transformations/Input/Text_Plain_Iptolong.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getInputHtml(
7676
return $html . '<input type="text" name="fields' . $columnNameAppendix . '"'
7777
. ' value="' . htmlspecialchars($val) . '"'
7878
. ' size="40"'
79-
. ' dir="' . LanguageManager::$textDir . '"'
79+
. ' dir="' . LanguageManager::$textDirection->value . '"'
8080
. ' class="transform_IPToLong"'
8181
. ' id="field_' . $fieldIndex . '_3"'
8282
. ' tabindex="' . $fieldIndex . '" />';

src/Twig/PmaGlobalVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __call(string $name, array $arguments): string
2121
{
2222
return match ($name) {
2323
'version' => Version::VERSION,
24-
'text_dir' => LanguageManager::$textDir,
24+
'text_dir' => LanguageManager::$textDirection->value,
2525
default => throw new RuntimeException(sprintf('The "pma.%s" variable is not available.', $name)),
2626
};
2727
}

tests/unit/Twig/PmaGlobalVariableTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\Config;
88
use PhpMyAdmin\I18n\LanguageManager;
9+
use PhpMyAdmin\I18n\TextDirection;
910
use PhpMyAdmin\Template;
1011
use PhpMyAdmin\Tests\AbstractTestCase;
1112
use PhpMyAdmin\Twig\PmaGlobalVariable;
@@ -53,7 +54,7 @@ public function testVersion(): void
5354

5455
public function testTextDir(): void
5556
{
56-
LanguageManager::$textDir = 'ltr';
57+
LanguageManager::$textDirection = TextDirection::LeftToRight;
5758
self::assertSame('ltr', (new PmaGlobalVariable())->text_dir());
5859
}
5960

@@ -72,7 +73,7 @@ public function testVersionFromTwig(): void
7273

7374
public function testTextDirFromTwig(): void
7475
{
75-
LanguageManager::$textDir = 'ltr';
76+
LanguageManager::$textDirection = TextDirection::LeftToRight;
7677
$expected = '<span>ltr</span>' . "\n";
7778
self::assertSame($expected, (new Template(new Config()))->render('pma_global_variable/text_dir', []));
7879
}

0 commit comments

Comments
 (0)