prev ScrapboxAutoTrans開発日記2022-01-17
どう翻訳する?
結局、リンクがつながるためには最低限タイトルの翻訳が必要だし、検索のためには全部の翻訳が必要だし、全部翻訳すれば良いのでは?という感じ
こういう流れかな
一部翻訳する
split_sentences Optional Sets whether the translation engine should first split the input into sentences. This is enabled by default. Possible values are:
preserve_formatting Optional Sets whether the translation engine should respect the original formatting, even if it would usually correct some aspects. Possible values are: "0" (default) "1" The formatting aspects affected by this setting include: Punctuation at the beginning and end of the sentence Upper/lower case at the beginning of the sentence これがScrapboxの翻訳に影響するかどうかは要実験
glossary_id Optional Specify the glossary to use for the translation. Important: This requires the source_lang parameter to be set and the language pair of the glossary has to match the language pair of the request. あ、訳語の指定もできそうだ
XMLのハンドリングは公式にサポートされているので、構造を壊さずに翻訳したいなら手元でXMLに変換すると良い
できた
ts
const data = {
auth_key: secret,
text: text,
source_lang: 'JA',
target_lang: 'EN-US',
}
const trans = await fetch('https://api-free.deepl.com/v2/translate', {
method: 'POST',
headers: {
'Content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: new URLSearchParams(data),
})
const transJson = await trans.json()
API経由で翻訳するのができた
翻訳結果をどうキャッシュするのか考えているうちにこんがらがってきた…
キャッシュするベータベースの設計は、それがどう使われるのかによって決まる
あれ?機械翻訳の前に「Scrapboxにおいたコンテンツで書籍的ナビゲーション」をやるべきか??