PHP code example of sylvaincombes / php-lcid

1. Go to this page and download the library: Download sylvaincombes/php-lcid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sylvaincombes / php-lcid example snippets




ylvainCombes\Lcid\Finder;

$finder = new Finder();

// NB : find methods returns null if not found


// 1. Finding a locale by lcid

// You should always use this method (use fallbacks if no 'perfect match' to try to answer something to your query instead of failing if no 'perfect match')
$locale = $finder->findByLcidWithFallback(8201);
// Should give you $locale == 'en'

// You can avoid searching in fallbacks if you really want to
$locale = $finder->findByLcid(1036);
// Should give you $locale == 'fr_FR'


// 2. Finding lcid(s) by locale
$localeLcid = $finder->findOneByLocale('fr');
// Should give you $localeLcid == 1036
// NB : this method is limited as it will return only 'perfect match'

$localeLcid = $finder->findByLocale('fr');
/**
 * Get an array or null in response (search everywhere)
 * First result in array should be the 'best' match
 * 
 * Return example :
 * array(8) {
 *     [0] => int(1036)
 *     [1] => int(11276)
 *     [2] => int(9228)
 *     [3] => int(12300)
 *     [4] => int(13324)
 *     [5] => int(14348)
 *     [6] => int(10252)
 *     [7] => int(7180)
 *   }
 * 
 */



ylvainCombes\Lcid\Finder;

// Pass your json file in constructor
// Your json must validate against the json schema, see src/SylvainCombes/Lcid/Resources/datas-schema.json
$finder = new Finder('src/Me/Resources/my-lcids.json');

// ...



composer 

php bin/console lcid:generate-datas -v