patrickschur/language-detection通过分析输入文字类型返回文字归属语言的概率,目前已支持106种不同国家的文字。最低要求PHP版本≥7,所以需要使用docker。
创建工作目录
1 |
mkdir /var/www/language-detection |
初始化container
1 |
docker run -d -t -i -v /var/www/language-detection/:/var/www/html -p 8080:80 --name language-detection php:7.0-apache /bin/bash |
连接container
1 |
docker attach language-detection |
安装依赖
1 2 |
apt-get update apt-get install git |
安装patrickschur/language-detection
1 2 |
curl -sS https://getcomposer.org/installer | php php composer.phar require patrickschur/language-detection |
配置反向代理
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<VirtualHost *:80> ServerName proxy.minirplus.com ServerSignature Off ProxyRequests Off ProxyMaxForwards 100 ProxyPreserveHost On ProxyPass / http://0.0.0.0:8080/ ProxyPassReverse / http://0.0.0.0:8080/ <Proxy *> Order Deny,Allow Allow from all </Proxy> </VirtualHost> |
创建index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php // include composer autoload require 'vendor/autoload.php'; use LanguageDetection\Language; $ld = new Language; $object = $ld->detect('Mag het een onsje meer zijn?')->close(); $result = json_encode($object, JSON_PRETTY_PRINT); echo $result; // var_dump($object) ; |
启用apache
1 |
service apache2 start |
访问
1 |
http://proxy.minirplus.com |
输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
{ nl: 0.66193548387097, af: 0.51338709677419, br: 0.49634408602151, nb: 0.48849462365591, nn: 0.48741935483871, fy: 0.47822580645161, dk: 0.47172043010753, sv: 0.46408602150538, bi: 0.46021505376344, de: 0.45903225806452, ug-Latn: 0.45591397849462, tr: 0.45064516129032, sq: 0.42865591397849, ku: 0.42715053763441, is: 0.42639784946237, mt: 0.4208064516129, hu: 0.41704301075269, ca: 0.40887096774194, en: 0.40860215053763, eu: 0.39779569892473, fi: 0.39741935483871, fo: 0.39489247311828, fr: 0.3939247311828, ig: 0.38994623655914, gn: 0.38838709677419, sl: 0.38790322580645, mh: 0.38790322580645, eo: 0.38784946236559, jv: 0.3839247311828, cy: 0.37537634408602, et: 0.37129032258065, id: 0.36822580645161, ch: 0.36801075268817, io: 0.36736559139785, ms-Latn: 0.36376344086022, bs-Latn: 0.36306451612903, la: 0.36155913978495, wa: 0.35951612903226, gl: 0.35451612903226, ia: 0.35370967741935, pt-BR: 0.34989247311828, es: 0.34774193548387, hr: 0.34569892473118, it: 0.34483870967742, lg: 0.34209677419355, ha: 0.33994623655914, pt-PT: 0.33559139784946, tl: 0.32709677419355, az-Latn: 0.32333333333333, wo: 0.32311827956989, xh: 0.32215053763441, pl: 0.31876344086022, cs: 0.31838709677419, co: 0.31779569892473, ro: 0.31204301075269, fj: 0.31139784946237, ga: 0.31091397849462, gd: 0.30827956989247, so: 0.30301075268817, sk: 0.30198924731183, ve: 0.29811827956989, kr: 0.29634408602151, lv: 0.2939247311828, ng: 0.28655913978495, ss: 0.2839247311828, ay: 0.26204301075269, lt: 0.2608064516129, ty: 0.24951612903226, yo: 0.2408064516129, vi: 0.23489247311828, nv: 0.23430107526882, tt: 0, zh-Hans: 0, ug-Arab: 0, th: 0, ru: 0, uk: 0, uz: 0, ta: 0, ab: 0, ms-Arab: 0, el-monoton: 0, am: 0, ar: 0, az-Cyrl: 0, be: 0, bg: 0, bn: 0, bo: 0, bs-Cyrl: 0, cr: 0, dz: 0, el-polyton: 0, mn-Cyrl: 0, fa: 0, gu: 0, he: 0, hi: 0, hy: 0, iu: 0, ja: 0, ka: 0, km: 0, ko: 0, lo: 0, zh-Hant: 0 } |
There are no comments yet