]> git.wh0rd.org - tt-rss.git/blob - plugins/af_lang_detect/init.php
Merge branch 'pullreq-fix-undefined-index-warning' of tkappe/tt-rss into master
[tt-rss.git] / plugins / af_lang_detect / init.php
1 <?php
2 class Af_Lang_Detect extends Plugin {
3 private $host;
4 private $lang;
5
6 function about() {
7 return array(1.1,
8 "Detect article language",
9 "fox");
10 }
11
12 function init($host) {
13 $this->host = $host;
14
15 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
16
17 require_once __DIR__ . "/languagedetect/Text/LanguageDetect.php";
18
19 $this->lang = new Text_LanguageDetect();
20 $this->lang->setNameMode(2);
21 }
22
23 function hook_article_filter($article) {
24
25 if ($this->lang) {
26 $entry_language = $this->lang->detect($article['title'] . " " . $article['content'], 1);
27
28 if (count($entry_language) > 0) {
29 $possible = array_keys($entry_language);
30 $entry_language = $possible[0];
31
32 _debug("detected language: $entry_language");
33
34 $article["language"] = $entry_language;
35 }
36 }
37
38 return $article;
39 }
40
41 function api_version() {
42 return 2;
43 }
44
45 }