2015-06-19 07:12:47 +00:00
|
|
|
<?php
|
|
|
|
class Af_Lang_Detect extends Plugin {
|
|
|
|
private $host;
|
|
|
|
private $lang;
|
|
|
|
|
|
|
|
function about() {
|
2018-08-02 15:23:14 +00:00
|
|
|
return array(1.1,
|
2015-06-19 07:12:47 +00:00
|
|
|
"Detect article language",
|
|
|
|
"fox");
|
|
|
|
}
|
|
|
|
|
|
|
|
function init($host) {
|
|
|
|
$this->host = $host;
|
|
|
|
|
|
|
|
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
|
|
|
|
|
2018-08-02 15:23:14 +00:00
|
|
|
require_once __DIR__ . "/languagedetect/Text/LanguageDetect.php";
|
2015-06-19 07:12:47 +00:00
|
|
|
|
|
|
|
$this->lang = new Text_LanguageDetect();
|
|
|
|
$this->lang->setNameMode(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hook_article_filter($article) {
|
|
|
|
|
|
|
|
if ($this->lang) {
|
|
|
|
$entry_language = $this->lang->detect($article['title'] . " " . $article['content'], 1);
|
|
|
|
|
|
|
|
if (count($entry_language) > 0) {
|
|
|
|
$possible = array_keys($entry_language);
|
|
|
|
$entry_language = $possible[0];
|
|
|
|
|
|
|
|
_debug("detected language: $entry_language");
|
|
|
|
|
|
|
|
$article["language"] = $entry_language;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $article;
|
|
|
|
}
|
|
|
|
|
|
|
|
function api_version() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|