From 3318d324105ee222a54afc94076878c12b588c24 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Jun 2015 10:12:47 +0300 Subject: move language detection to a plugin, remove config.php constant --- plugins/af_lang_detect/init.php | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plugins/af_lang_detect/init.php (limited to 'plugins/af_lang_detect/init.php') diff --git a/plugins/af_lang_detect/init.php b/plugins/af_lang_detect/init.php new file mode 100644 index 000000000..3f2eb29f8 --- /dev/null +++ b/plugins/af_lang_detect/init.php @@ -0,0 +1,46 @@ +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; + } + +} +?> -- cgit v1.2.3-54-g00ecf