* 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.'; }
<?php /** * Code Validation * * This example shows how to validate a specific code against the database. All paths are relative * to the project root directory. */ require 'vendor/autoload.php'; //Setup Lingua $setup = Lingua\Setup::prelude(); $setup->acceptAndDownload(); //Validate Language Codes $iso639Part1 = new Lingua\Code\Language\ISO639Part1(); if ($iso639Part1->validate('de')) { echo '`de` is a valid ISO 639-1 code.'; } else { echo '`de` is no valid ISO 639-1 code.'; } $iso639Part3 = new Lingua\Code\Language\ISO639Part3(); echo '`eng` is ' . ($iso639Part3->validate('eng') ? 'a' : 'no') . ' valid ISO 639-3 code.'; //Validate Region Codes $iso3166Part1Alpha2 = new Lingua\Code\Region\ISO3166Part1Alpha2(); echo '`US` is ' . ($iso3166Part1Alpha2->validate('US') ? 'a' : 'no') . ' valid ISO 3166-1 Alpha-2 code.'; //Validate script codes $iso15924 = new Lingua\Code\Script\ISO15924(); echo '`Latn` is ' . ($iso15924->validate('Latn') ? 'a' : 'no') . ' valid ISO 15924 code.';