Beispiel #1
0
export default ({ title, body, className }) => {
  const language = franc(`${title} ${striptags(remarkable.render(body))}`);
  const textLength = (`${title} ${striptags(remarkable.render(body))}`).length;
  if (!(language !== 'eng' && language !== 'sco' && textLength > 255)) {
    return null;
  }
  return (
    <span className={className}>
      <Link to={`/hot/${getCountryCode(language)}`}>
        <img className="Flag" alt={language} src={`/img/flag/${getCountryCode(language)}.svg`} />
      </Link>
    </span>
  );
};
Beispiel #2
0
	$("#default-search-btn").click(function() {
		var text = $("#default-search").val();
		var latinLang = $("#language-selector").html();
		var lang = franc(text, {'minLength': 1, 'whitelist': ['eng', 'cmn', 'und']});

		if(lang == 'cmn') {
			cedict.searchByChinese(text, function(results) {
				console.log(results);
				if(results.length < 1) {
					displayNone();
				}
				else {
					displayResults(results);
				}
			});
		}
		else if(lang == 'eng') {
			if(latinLang == "EN") {
				console.log("Search Language is English");
				cedict.searchByEnglish(text, function(results) {
					displayResults(results);
				});
			}
			else if(latinLang == "PY") {
				cedict.searchByPinyin(text, function(results) {
					console.log(results);
					if(results.length < 1) {
						displayNone();
					}
					else {
						displayResults(results);
					}
				});
			}
			else {
				console.log("Unable to detect the search language. Try again using more characters/words.");
			}
		}
		else {
			console.log("Unable to detect the search language. Try using more characters/words.");
		}
	});
Beispiel #3
0
var parseMeta = function(url, options, body, header) {
	header = header || {};
	var uri = URI.parse(url);
	var $;
	try {
		$ = cheerio.load(body);
	} catch (e) {
		return "Invalid HTML";
	}
	$('script').remove();
	$('style').remove();
	$('applet').remove();
	$('embed').remove();
	$('object').remove();
	$('noscript').remove();
	var response = {};
	var title;
	if (options.title) {
		title = $('title').text();
	}
	if (options.charset) {
		response.charset = $("meta[charset]").attr("charset");
	}

	if (options.images) {
		var imagehash = {};
		response.images = $('img').map(function() {
			var src = $(this).attr('src');
			if (src) {
				return URI.resolve(url, src);
			} else {
				return "";
			}
		}).filter(function(e, f) {
			return (f.match(/\.(jpeg|jpg|gif|png|JPEG|JPG|GIF|PNG)$/) !== null);
		}).filter(function(i, item) {
			return imagehash.hasOwnProperty(item) ? false : (imagehash[item] = true);
		}).get();
	}
	if (options.links) {
		var linkhash = {};
		response.links = $('a').map(function() {
			var href = $(this).attr('href');
			if (href && href.trim().length && href[0] !== "#") {
				return URI.resolve(url, href);
			} else {
				return 0;
			}
		}).filter(function(i, item) {
			if (item === 0) {
				return false;
			}
			return linkhash.hasOwnProperty(item) ? false : (linkhash[item] = true);
		}).get();
	}
	var meta = $('meta'),
		canonicalURL = $("link[rel=canonical]").attr('href'),
		ampURL = $("link[rel=amphtml]").attr('href'),
		metaData = {};
	if (ampURL) {
		ampURL = URI.resolve(url, ampURL);
	}
	Object.keys(meta).forEach(function(key) {
		var attribs = meta[key].attribs;
		if (attribs) {
			if (attribs.property) {
				metaData[attribs.property.toLowerCase()] = attribs.content;
			}
			if (attribs.name) {
				metaData[attribs.name.toLowerCase()] = attribs.content;
			}
			if (attribs['http-equiv']) {
				header[attribs['http-equiv']] = attribs.content;
			}
		}
	});

	if (options.language) {
		response.language = $("html").attr("lang") || $("html").attr("xml:lang") || header["Content-Language"] || header["content-language"];
		if (!!!response.language) {
			response.language = langs.where("2", franc($('body').text().replace(/\n\s*\n/g, '\n')))
			response.language = response.language && response.language[1];
		} else {
			response.language = response.language.split("-")[0];
		}
	}

	response.uri = uri;

	if (options.title) {
		response.title = metaData['og:title'] || title;
	}
	if (options.description) {
		response.description = metaData['og:description'] || metaData.description;
	}
	if (options.type) {
		response.type = metaData['og:type'];
	}
	if (options.url) {
		response.url = URI.resolve(url, canonicalURL || metaData['og:url'] || url);
		response.originalURL = url;
		response.ampURL = ampURL || null;
	}
	if (options.siteName) {
		response.siteName = metaData['og:site_name'];
	}
	if (options.image) {
		response.image = metaData['og:image'];
	}
	if (options.meta) {
		response.meta = metaData;
	}
	if (options.headers) {
		response.headers = header;
	}
	return response;
};
         guessLanguage.guessLanguage.detect(shortened, function(language) {
             //console.log(i + " " + language + " <= '" + shortened + "'");
             if (language !== expectedLang && minCorrectChars < shortened.length) {
                 minCorrectChars = prevCharLength;
                 console.log("Wrong: '" + shortened + "'");
             }
             if (language === expectedLang) {
                 everCorrect = true;
             }
         });
     } else if (mode === 'franc') {
         var language = franc(shortened, 
             {
                 // top 20:
                 //'whitelist': ['cmn', 'spa', 'eng', 'rus', 'arb', 'ben', 'hin', 'por', 'ind', 'jpn', 'fra', 'deu', 'jav', 'kor', 'tel', 'vie', 'mar', 'ita', 'tam', 'tur']
                 // 4 languages with variants:
                 'whitelist': ['spa', 'eng',  'por', 'deu']
                 // top 100:
                 //'whitelist': ['cmn', 'spa', 'eng', 'rus', 'arb', 'ben', 'hin', 'por', 'ind', 'jpn', 'fra', 'deu', 'jav', 'kor', 'tel', 'vie', 'mar', 'ita', 'tam', 'tur', 'urd', 'guj', 'pol', 'ukr', 'mai', 'mal', 'kan', 'mya', 'ori', 'gax', 'swh', 'sun', 'ron', 'pan', 'bho', 'amh', 'fuc', 'hau', 'bos', 'bos', 'hrv', 'nld', 'srp', 'srp', 'tha', 'ckb', 'yor', 'uzn', 'uzn', 'ibo', 'nep', 'ceb', 'skr', 'tgl', 'hun', 'azj', 'azj', 'sin', 'ell', 'ces', 'mag', 'bel', 'plt', 'mad', 'nya', 'qug', 'kin', 'zul', 'bul', 'swe', 'lin', 'som', 'hms', 'ilo', 'kaz', 'uig', 'uig', 'hat', 'khm', 'aka', 'aka', 'hil', 'pes', 'sna', 'tat', 'xho', 'hye', 'min', 'afr', 'lua', 'sat', 'bod', 'tir', 'fin', 'run', 'slk', 'tuk', 'tuk', 'dan', 'als']
             });
         if (language !== expectedLang && minCorrectChars < shortened.length) {
             minCorrectChars = prevCharLength;
             console.log("Wrong: '" + shortened + "'");
         }
         if (language === expectedLang) {
             everCorrect = true;
         }
     } else {
         throw "Unknown mode: " + mode;
     }
 }