* Code Conversion * * This example shows how to translate a specific code between different code standards, but applies * to all supported coding methods. All paths are relative to the project directory. */ require 'vendor/autoload.php'; //Setup Lingua $setup = Lingua\Setup::prelude(); $setup->acceptAndDownload(); /* Language Codes */ //Translate an ISO 639-1 code to an ISO 639-2B code: $iso639Part1 = new Lingua\Code\Language\ISO639Part1(); $iso639Part2B = new Lingua\Code\Language\ISO639Part2B(); echo $iso639Part2B->translate($iso639Part1->unify('de')); /* Region Codes */ //Translate a ISO 3166-2 region code into the intermediate (ISO 3166-1 Alpha-3) code: $iso3166Part1Alpha2 = new Lingua\Code\Region\ISO3166Part1Alpha2(); echo $iso3166Part1Alpha2->unify('US'); //To support changes in the future, a better way is: $iso3166Part1Alpha2 = new Lingua\Code\Region\ISO3166Part1Alpha2(); $iso3166Part1Alpha3 = new Lingua\Code\Region\ISO3166Part1Alpha3(); echo $iso3166Part1Alpha3->translate($iso3166Part1Alpha2->unify('US')); /* Script Codes */ //This might be unnecessary, but simplifies future changes of the intermediate codings: $iso15924 = new Lingua\Code\Script\ISO15924(); $code = $iso15924->unify('Latn'); if (is_null($code)) { echo $code . ' is invalid.'; } else { echo $code . ' is valid.'; }