
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
jtcg_locale_detector
Advanced tools
多語言地區檢測工具的Ruby綁定,特別針對中文繁簡體檢測進行優化。
將此行添加到應用程式的 Gemfile:
gem 'locale_detector'
然後執行:
$ bundle install
或者手動安裝:
$ gem install locale_detector
安裝 gem 後,需要安裝 Python 依賴:
$ rake install_python_deps
或手動安裝:
$ pip install -r python/requirements.txt
require 'locale_detector'
# 檢測單一文本
result = LocaleDetector.detect("Hello world")
puts result["locale"] # => "en-US"
# 檢測中文繁體
result = LocaleDetector.detect("繁體中文測試")
puts result["locale"] # => "zh-TW"
# 檢測中文簡體
result = LocaleDetector.detect("简体中文测试")
puts result["locale"] # => "zh-CN"
texts = ["Hello world", "繁體中文", "简体中文", "Bonjour le monde"]
results = LocaleDetector.detect_batch(texts)
results.each_with_index do |result, index|
puts "Text #{index + 1}: #{result['locale']}"
end
result = LocaleDetector.detect_file("path/to/text/file.txt")
puts result["locale"]
# 使用不同的檢測模式
client = LocaleDetector::Client.new(
mode: "ratio", # 'conversion', 'ratio', 'both'
low_memory: false, # 使用低記憶體模式
output_format: "json" # 'simple', 'json', 'detailed'
)
result = client.detect("測試文本")
# 獲取詳細檢測信息
detailed_result = client.detect_with_details("測試文本")
puts detailed_result.inspect
安裝 gem 後,您可以使用 locale-detector
命令:
# 檢測單一文本
$ locale-detector "Hello world"
en-US
# 從檔案檢測
$ locale-detector --file input.txt
# 批次處理
$ locale-detector --batch file1.txt file2.txt
# 使用不同模式
$ locale-detector "中文文本" --mode ratio --details
# JSON 輸出
$ locale-detector "測試" --output-format json
{
"locale": "zh-TW"
}
# 詳細信息
$ locale-detector "測試" --output-format detailed --details
conversion
: 快速模式,使用字符轉換比較ratio
: 準確模式,使用字符比例分析(預設)both
: 混合模式,結合兩種方法simple
: 簡單文本輸出(預設)json
: JSON 格式輸出detailed
: 詳細信息輸出本工具支援 176 種語言的檢測,包括但不限於:
zh-TW
(繁體), zh-CN
(簡體), zh-HK
, zh-MO
, zh-SG
en
, es
, fr
, de
, it
, pt
, ru
, nl
, sv
, no
, da
ja
, ko
, th
, vi
, hi
, ar
, he
, tr
LocaleDetector::Detector.supported_languages
LocaleDetector.detect(text, **options)
- 檢測單一文本LocaleDetector.detect_batch(texts, **options)
- 批次檢測LocaleDetector.detect_file(file_path, **options)
- 從檔案檢測#detect(text)
- 檢測單一文本#detect_batch(texts)
- 批次檢測#detect_file(file_path)
- 從檔案檢測#detect_with_details(text)
- 獲取詳細檢測信息mode
: 檢測模式('conversion', 'ratio', 'both')low_memory
: 使用低記憶體模式output_format
: 輸出格式('simple', 'json', 'detailed')encoding
: 檔案編碼(預設: 'utf-8')Detector.supported_languages
- 取得支援的語言列表Detector.chinese_variants
- 取得中文變體信息Detector.detection_modes
- 取得可用的檢測模式Detector.language_supported?(language_code)
- 檢查是否支援某語言Detector.chinese_variant?(locale)
- 檢查是否為中文變體獲取原始碼後,執行 bin/setup
安裝依賴。然後,執行 rake spec
來運行測試。您也可以執行 bin/console
來取得互動式提示符進行實驗。
要將此 gem 安裝到本地機器,執行 bundle exec rake install
。要發布新版本,更新 version.rb
中的版本號,然後執行 bundle exec rake release
,這將創建一個 git 標籤並推送 .gem
檔案到 rubygems.org。
Bug 報告和 pull request 歡迎在 GitHub 上提交:https://github.com/jtcg/locale-detector
此 gem 可在 MIT License 條款下使用。
本工具基於以下開源專案:
FAQs
Unknown package
We found that jtcg_locale_detector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.