bog / yandex-dictionary-api

1.0.2 2019-11-16 10:10 UTC

README

描述

API 包含两个方法:获取语言(getLangs)和查找。
使用它需要 API 密钥。您可以在以下位置获取
https://tech.yandex.ru/dictionary/

安装

composer require bog/yandex-dictionary-api

用法

使用 API 密钥作为参数创建对象。

$dictionary = new Dictionary('apiKey');

设置输出类型

您可以将响应获取为 JSON(默认)或 XML。
两种类型的输出示例
https://tech.yandex.ru/dictionary/doc/dg/reference/getLangs-docpage/
https://tech.yandex.ru/dictionary/doc/dg/reference/lookup-docpage/

// JSON output (default)
$dictionary->setType(Dictionary::TYPE_JSON);

// XML output
$dictionary->setType(Dictionary::TYPE_XML);

获取可用语言

$langs = $dictionary->getLangs();

查找(翻译)

设置语言('en-ru' 为默认值)

$dictionary->setTranslateFrom('en');
$dictionary->setTranslateTo('ru');

查找

$translation = $dictionary->lookup('hello');