示例#1
0
文件: iso.php 项目: msooon/hubzilla
<?php

/**
 * Demonstrates how to use ISO language codes.
 *
 * The "name mode" changes the way languages are accepted and returned.
 */
require_once 'Text/LanguageDetect.php';
$l = new Text_LanguageDetect();
//will output the ISO 639-1 two-letter language code
// "de"
$l->setNameMode(2);
echo $l->detectSimple('Das ist ein kleiner Text') . "\n";
//will output the ISO 639-2 three-letter language code
// "deu"
$l->setNameMode(3);
echo $l->detectSimple('Das ist ein kleiner Text') . "\n";
 function test_omit_error()
 {
     $str = 'On January 29, 1737, Thomas Paine was born in Thetford, England. His father, a corseter, had grand visions for his son, but by the age of 12, Thomas had failed out of school. The young Paine began apprenticing for his father, but again, he failed.';
     $myobj = new Text_LanguageDetect();
     $result = $myobj->detectSimple($str);
     $this->assertEquals('english', $result);
     // omit all languages and you should get an error
     $myobj->omitLanguages($myobj->getLanguages());
     $result = $myobj->detectSimple($str);
     $this->assertNull($result, gettype($result));
 }
                        // Load noise dictionary, for tag generation
                        $noise = split_lines(file_get_contents_cached("english.dic")->data);
                        $noise = arraytolower($noise);
                        foreach (explode(" ", $raw_suggestion) as $tag) {
                            $tag = trim(clean_tag($tag));
                            if (strlen(trim($tag)) > 1 && in_array(strtolower(trim($tag)), $noise) === false) {
                                $tag_list[] = strtolower($tag);
                            }
                        }
                        $tag_list = array_unique($tag_list);
                        $tags_suggestion = utf8_entities_if_needed(implode(", ", $tag_list));
                    }
                    if ($detect_language) {
                        require_once "Text/LanguageDetect.php";
                        $detector = new Text_LanguageDetect();
                        $detected_language = $detector->detectSimple(strip_tags($request->result));
                    } else {
                        $detected_language = "English";
                    }
                    ?>
					<h2>Submit a related site</h2>
					
					<form method="POST" action="/related-sites/add/submit/" class="submission">
						
						<input type="hidden" name="url" value="<?php 
                    echo utf8entities($_POST['url']);
                    ?>
">
						
						<h4>Website Title</h4>
						<div class="form-notice">
示例#4
0
function langfilter_prepare_body(&$a, &$b)
{
    if (get_pconfig(local_user(), 'langfilter', 'disable')) {
        return;
    }
    if (local_user()) {
        $langs = get_pconfig(local_user(), 'langfilter', 'languages');
    }
    if ($langs) {
        $arr = explode(',', $langs);
    } else {
        return;
    }
    $found = false;
    $l = new Text_LanguageDetect();
    $l->_name_mode = 2;
    // two letter codes
    $l->_threshold = 600;
    // make it a bit harder to be confident with a lng
    // IOW make it more possible that lng is correct
    $lng = $l->detectSimple($b['html']);
    if ($lng == null) {
        return;
    }
    if (!in_array($lng, $arr)) {
        $found = true;
    }
    if ($lng == null) {
        $found = false;
    }
    if ($found) {
        $rnd = random_string(8);
        $b['html'] = '<div id="langfilter-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'langfilter-' . $rnd . '\'); >' . sprintf(t('unspoken language %s - Click to open/close'), $lng) . '</div><div id="langfilter-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';
    }
}