Skip to content

Commit

Permalink
Merge pull request #9 from ageekdev/feat/name-normalize
Browse files Browse the repository at this point in the history
Feat: add normalization for mm names
  • Loading branch information
thantthuhein-genie authored Sep 13, 2023
2 parents a8d699a + be17f3e commit 2ec61a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/MMName.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

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;
use EnglishSarHelpers, Macroable, MyanmarSarHelpers;

protected array $dataSource;

Expand All @@ -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] ?? '').' ';
Expand Down
22 changes: 22 additions & 0 deletions src/Utilities/Normalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace AgeekDev\MMName\Utilities;

/**
* Normalize the Myanmar Texts
*/
class Normalizer
{
private array $normalizations = [
'/\x{1037}\x{103A}/u' => '့်',
];

public function normalizeMmText(string $text): string
{
foreach ($this->normalizations as $pattern => $replace) {
$text = preg_replace($pattern, $replace, $text);
}

return $text;
}
}
9 changes: 6 additions & 3 deletions tests/NameConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');
});

0 comments on commit 2ec61a4

Please sign in to comment.