Skip to content

Commit

Permalink
Merge pull request #9 from cHoXu/feature/PHPISO-639
Browse files Browse the repository at this point in the history
add ISO639::code2tByCode1 method
  • Loading branch information
matriphe committed Mar 17, 2024
2 parents 8040544 + 13940cb commit a5fb655
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ISO639.php
Expand Up @@ -450,4 +450,26 @@ public function getLanguageByIsoCode2b($code)
return null;
}

/**
* Get ISO-639-2t code from ISO-639-1 code
*
* @param string $code
* @return string
*/
public function code2tByCode1($code)
{
$code = strtolower($code);

$result = '';

foreach ($this->languages as $lang) {
if($lang[0] === $code) {
$result = $lang[1];
break;
}
}

return $result;
}

}
8 changes: 8 additions & 0 deletions tests/ISO639Test.php
Expand Up @@ -249,4 +249,12 @@ public function testGetLanguageByIsoCode2B()
$this->assertNull($this->iso->getLanguageByIsoCode2b('null'));
}

public function testCode2tByCode1()
{
$this->assertSame('fra', $this->iso->code2tByCode1('fr'));
$this->assertSame('eng', $this->iso->code2tByCode1('en'));
$this->assertSame('spa', $this->iso->code2tByCode1('es'));
$this->assertSame('ind', $this->iso->code2tByCode1('id'));
}

}

0 comments on commit a5fb655

Please sign in to comment.