Skip to content

Commit

Permalink
add ISO639::code2tByCode1 method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas NAUDIN committed Feb 14, 2024
1 parent 647ef1c commit 13940cb
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 13940cb

Please sign in to comment.