diff --git a/src/ISO639.php b/src/ISO639.php index 3ed8486..433f734 100644 --- a/src/ISO639.php +++ b/src/ISO639.php @@ -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; + } + } diff --git a/tests/ISO639Test.php b/tests/ISO639Test.php index 5a5b4bc..0e13813 100644 --- a/tests/ISO639Test.php +++ b/tests/ISO639Test.php @@ -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')); + } + }