aozen/language-detector
最新稳定版本:v1.0.0
Composer 安装命令:
composer require aozen/language-detector
包简介
This package provides a set of functions to detect and manipulate language-specific strings, including language detection, case conversion, and language-based filtering.
README 文档
README
Used to determine which language a given string belongs to.
Installation
You can install the package via composer:
composer require aozen/language-detector
Usage
The LanguageDetector class must be included by yourself.
use \Aozen\LanguageDetector\LanguageDetector;
Example:
class YourClass { public function yourFunction() { $language_detector = new LanguageDetector(); return $language_detector->detect("Güneş")->getLanguage(); // Result: "tr" } }
Other Usage Examples
-
By default, the code searches in all languages specified as
availablewithin the code. -
The
getClosestLanguagefunction works similarly togetLanguage, but it doesn't guarantee a 100% correct result. For instance, the exampleÄpfel straße délicieuxwould returninvalid_languagewithgetLanguage, whilegetClosestLanguagewould returnde, based on which language had the most character matches. For instance, the expressiondélicieux délicieux Äpfelwould have also returnedfr. -
To search only in the desired languages,
checkListis used.
$language_detector->detect("Äpfel")->checkList("tr", "de", "it")->getLanguage(); // de
- To prevent searching in unwanted languages,
blockListis used.
$language_detector->detect("Äpfel")->blockList("de")->getLanguage(); // invalid_language
- To retrieve the
lowercaseversion of the given string for each language,getLowerCaseis used. Separate definitions for each language are required.
$language_detector->detect("TÜRKÇE-BİR-YAZI")->getLowerCase(); // türkçe-bi̇r-yazı
Testing
vendor/bin/phpunit tests/Test.php
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-05