From 48095d63f0e6557c2f2cbf8bfef8a94a7329781f Mon Sep 17 00:00:00 2001 From: Thant Thu Hein <99555752+thantthuhein-genie@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:14:46 +0630 Subject: [PATCH 1/2] Feat: add normalization for mm names --- src/MMName.php | 7 ++++--- src/Utilities/Normalizer.php | 22 ++++++++++++++++++++++ tests/NameConverterTest.php | 9 ++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/Utilities/Normalizer.php diff --git a/src/MMName.php b/src/MMName.php index 0410d44..ab01ba1 100755 --- a/src/MMName.php +++ b/src/MMName.php @@ -4,10 +4,11 @@ use AgeekDev\MMName\Traits\EnglishSarHelpers; use AgeekDev\MMName\Traits\MyanmarSarHelpers; +use AgeekDev\MMName\Utilities\Normalizer; use Illuminate\Support\Facades\Config; use Illuminate\Support\Traits\Macroable; -class MMName +class MMName extends Normalizer { use MyanmarSarHelpers, EnglishSarHelpers, Macroable; @@ -24,11 +25,11 @@ public function __construct() public function convertToEn(string $nameString): string { if (! $this->isMmName($nameString)) { - return $nameString; + return $this->normalizeMmText($nameString); } $enName = ''; - $nameSegments = $this->myanmarSarSegment($nameString); + $nameSegments = $this->myanmarSarSegment($this->normalizeMmText($nameString)); foreach (explode(' ', $nameSegments) as $name) { $enName .= ($this->dataSource['mm'][$name] ?? '').' '; diff --git a/src/Utilities/Normalizer.php b/src/Utilities/Normalizer.php new file mode 100644 index 0000000..8333391 --- /dev/null +++ b/src/Utilities/Normalizer.php @@ -0,0 +1,22 @@ + '့်', + ]; + + public function normalizeMmText(string $text): string + { + foreach ($this->normalizations as $pattern => $replace) { + $text = preg_replace($pattern, $replace, $text); + } + + return $text; + } +} diff --git a/tests/NameConverterTest.php b/tests/NameConverterTest.php index 1801d90..249ffab 100644 --- a/tests/NameConverterTest.php +++ b/tests/NameConverterTest.php @@ -62,9 +62,6 @@ }); it('can convert myanmar name to myan-glish', function () { - $result = mm_name_to_en('မောင်မောင်'); - expect($result)->toEqual('mg mg'); - $result = MMName::convertToEn('မောင်မောင်'); expect($result)->toEqual('mg mg'); @@ -136,4 +133,10 @@ $result = MMName::convertToEn('စန္ဒာ'); expect($result)->toEqual('sandar'); + + $result = MMName::convertToEn('မောင်သန့်သူ'); + expect($result)->toEqual('mg thant thu'); + + $result = MMName::convertToEn('မောင်မောင်ကျော်'); + expect($result)->toEqual('mg mg kyaw'); }); From be17f3e1414026fc350168f347dbce123a8e3110 Mon Sep 17 00:00:00 2001 From: thantthuhein-genie Date: Wed, 13 Sep 2023 07:45:22 +0000 Subject: [PATCH 2/2] Fix styling --- src/MMName.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MMName.php b/src/MMName.php index ab01ba1..42c08db 100755 --- a/src/MMName.php +++ b/src/MMName.php @@ -10,7 +10,7 @@ class MMName extends Normalizer { - use MyanmarSarHelpers, EnglishSarHelpers, Macroable; + use EnglishSarHelpers, Macroable, MyanmarSarHelpers; protected array $dataSource;