Thanks to visit codestin.com
Credit goes to github.com

Skip to content
 
 

Latest commit

 

History

71 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compact Language Detector 2 PHP Extension

This extension wraps CLD2 (Compact Language Detector 2) that detects over 80 languages in Unicode UTF-8 text.

Usage

Detector

$cld2 = new \CLD2Detector();

$cld2->setTldHint('it'); // optional, hints about the Top level domain (it: italian, fr: french, de: german etc..)
$cld2->setLanguageHint(CLD2Language::GERMAN); // optional, hints about the language.
$cld2->setEncodingHint(CLD2Encoding::UTF8); // optional, hints about text encoding
 
var_dump($cld2->detect('My name is Melissa'));

// Output
array(5) {
  'language_id' =>
  int(0)
  'language_code' =>
  string(2) "en"
  'language_name' =>
  string(7) "ENGLISH"
  'language_probability' =>
  int(95)
  'is_reliable' =>
  bool(true)
}

Language

Get language name from Language id

$lang = CLD2Language::PAMPANGA;
echo CLD2Language::languageName($lang);

// Output
string(8) "PAMPANGA"

Get language code from Language id

echo CLD2Language::languageCode(CLD2Language::PAMPANGA);

// Output
string(3) "pam"

Get language id from name where Name can be either full name or ISO code, or can be ISO code embedded in a language-script combination such as "en-Latn-GB"

echo CLD2Language::getLanguageFromName('PAMPANGA');
// or
echo CLD2Language::getLanguageFromName('pam');

// Output
int(176)

Encoding

Get encoding name from id

$enc = CLD2Encoding::UTF8;
echo CLD2Encoding::encodingName($enc);

// Output
string(4) "UTF8"

Installation

From PECL

Not submitted yet.

Build from source

First of all clone current repository and enter into its directory.

git clone [email protected]:fntlnz/cld2-php-ext.git
cd cld2-php-ext

Compile CLD2 library

git svn clone http://cld2.googlecode.com/svn/trunk/ libcld2
cd libcld2/internal
./compile_libs.sh
sudo cp libcld2.so /usr/local/lib 

Compile CLD2 PHP extension

Come back to the cld2-php-ext directory and execute:

phpize
./configure --with-cld2=libcld2
make -j
sudo make install

Do not forget to add extension=cld2.so to your PHP ini.

Contributing

See CONTRIBUTING.md

NOTES

Analytics

About

🇬🇧 🇮🇹 🇩🇪 This extension wraps CLD2 (Compact Language Detector 2) that detects over 80 languages in Unicode UTF-8 text.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages