translateR
というパッケージからMicrosoft翻訳を使って、Rでテキストを翻訳する。対応言語はこのサイトを参照。
library(translateR)
txt <- c("Hello", "How are you?", "What's your name?")
translate(content.vec = txt,
microsoft.client.id = "<Client ID>",
microsoft.client.secret = "<Client Secret>",
source.lang = "en", target.lang = "ja")
[1] "こんにちは" "お元気ですか。" "あなたの名前は何ですか。"
Microsoft Translatorにサインアップ(参考)
- このページから。
開発者ページへ行き、アプリケーションを登録
- クライアントID は既存のものとかぶらないものを、リダイレクトURIは無効なURLを指定する(例:https://localhost/)
- クライアントIDと顧客の秘密はあとで使うのでメモしておく。
Rから利用する。
translateR
はインストールしておく(install.packages("translateR")
)。
library(translateR)
txt <- c("Hello", "How are you?", "What's your name?")
translate(
content.vec = txt,
microsoft.client.id = "<クライアントID>",
microsoft.client.secret = "<顧客の秘密>",
source.lang = "en", target.lang = "ja")
#[1] "こんにちは" "お元気ですか。"
#[3] "あなたの名前は何ですか。"
#Warning message:
#The content appears to be in BRETON. However, the
#language code you provided suggests that the text is in
#ENGLISH. If you entered the wrong language code, stop
#the process. Otherwise, translateR will treat the text
#as ENGLISH.
警告メッセージは不思議だが(どうしてブルトン語に見えるのか)、きちんと翻訳できている。
対応言語も豊富(一覧)なので、使い道は多そう。