If I try to parse the string "pt-BR", I get an error saying that the language code may be misspelled, invalid, ...
I've tried with pt_BR, en-US, en_US, etc. without success.
<?php
require "./vendor/autoload.php";
use Rinvex\Language\LanguageLoader;
$language = language('en');
echo "OK for en" . PHP_EOL;
$language = language('en-US'); //Not accepted by the constructor, it generates an exception.
<?php
require "./vendor/autoload.php";
use Rinvex\Language\LanguageLoader;
$languageCode = 'pt-BR';
$nativeName = '';
$pieces = explode("-", $languageCode);
$language = language($pieces[0]);
if (count($pieces) == 1) {
$nativeName = $language->getNativeName();
} else {
$cultureInfo = $language->getCulture($languageCode);
$nativeName = $cultureInfo['native'];
}
echo "Language is $nativeName" . PHP_EOL;
It looks weird to me. You should accept the culture in the constructor and then populate the culture info, if any.