1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 20:45:55 +00:00

move language detection to a plugin, remove config.php constant

This commit is contained in:
Andrew Dolgov
2015-06-19 10:12:47 +03:00
parent 724e08f1c0
commit 3318d32410
11 changed files with 53 additions and 34 deletions

View File

@@ -0,0 +1,46 @@
<?php
class Af_Lang_Detect extends Plugin {
private $host;
private $lang;
function about() {
return array(1.0,
"Detect article language",
"fox");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
require_once __DIR__ . "/languagedetect/LanguageDetect.php";
$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;
}
}
?>