"langfilter" uses the new "language" field as well

This commit is contained in:
Michael 2018-06-30 05:20:17 +00:00
parent 25e4decd78
commit aae9da33dc

View file

@ -153,6 +153,18 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
$read_languages_array = explode(',', $read_languages_string); $read_languages_array = explode(',', $read_languages_string);
// Extract the language of the post // Extract the language of the post
if (!empty($hook_data['item']['language'])) {
$languages = json_decode($hook_data['item']['language'], true);
if (!is_array($languages)) {
return;
}
foreach ($languages as $iso2 => $confidence) {
break;
}
$lang = Text_LanguageDetect_ISO639::code2ToName($iso2);
} else {
$opts = $hook_data['item']['postopts']; $opts = $hook_data['item']['postopts'];
if (!$opts) { if (!$opts) {
// no options associated to post // no options associated to post
@ -167,13 +179,14 @@ function langfilter_prepare_body_content_filter(App $a, &$hook_data)
$lang = $matches[1]; $lang = $matches[1];
$confidence = $matches[2]; $confidence = $matches[2];
$iso2 = Text_LanguageDetect_ISO639::nameToCode2($lang);
}
// Do not filter if language detection confidence is too low // Do not filter if language detection confidence is too low
if ($minconfidence && $confidence < $minconfidence) { if ($minconfidence && $confidence < $minconfidence) {
return; return;
} }
$iso2 = Text_LanguageDetect_ISO639::nameToCode2($lang);
if (!$iso2) { if (!$iso2) {
return; return;
} }