コード例 #1
0
ファイル: code-validation.php プロジェクト: scento/lingua
<?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.';