汉字标注假名转换器

您所在的位置:网站首页 日语汉字假名注音软件 汉字标注假名转换器

汉字标注假名转换器

#汉字标注假名转换器 | 来源: 网络整理| 查看: 265

kuroshiro是一款十分方便使用的日文转换注音工具,主要针对日文文本,进行到平假名、片假名及罗马字的转换,并支持注音假名、送假名 (旁注音)等注音模式。

汉字标注假名转换器

使用到的项目为kuroshiro,kuromoji

一、演示

你可以在这里查看我的演示。

二、搭建

导入kuroshiro.min.js和kuroshiro-analyzer-kuromoji.min.js ,其中kuroshiro.min.js需要使用1.1.0版本。可以直接通过CDN引入:

12 HTML代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 汉字标注假名 在线汉字标注假名工具 输入日文 清空 转换 复制 Ruby 格式 HTML 显示 Copyright ;2021-;sunshj.top CSS样式123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196* { margin: 0; padding: 0;}html,body { height: 100%;}.container { display: flex; flex-direction: column; height: 100%;}header { flex: 0 0 auto;}marquee { display: block; background: linear-gradient(90deg, #53c9ffd5, #ff6dc0, #ffed4a, #53c9ffd5); position: relative; font-weight: bold; font-family: "Microsoft YaHei"; background-size: 400%; color: white; padding: 3px; animation: animate 15s linear infinite;}@keyframes animate { 0% { background-position: 0%; } 100% { background-position: 400%; }}.main { flex: 1 0 auto; width: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center;}textarea { max-width: 400px; max-height: 200px; font-size: 16px; resize: none; width: 100%; height: 100%; border: none; outline: none;}/* 滚动条美化 */textarea::-webkit-scrollbar { width: 6px; height: 6px;}textarea::-webkit-scrollbar-thumb { border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; background-color: #c3c3c3;}textarea::-webkit-scrollbar-track { background-color: transparent;}fieldset { padding: 5px; margin: 10px; border: 1px solid #cccccc; border-radius: 4px; max-width: 400px;}fieldset legend { display: block; height: 24px; line-height: 24px; padding: 0px 5px; font-weight: bold; border-radius: 4px; background: #f2f2f2; font-family: "Microsoft YaHei";}#input { max-height: 160px;}#convert { width: 80px; height: 30px; margin: 10px; border: none; cursor: pointer; font-size: 16px; font-weight: bold; background-color: #2ec033; color: white; border-radius: 5px;}#convert:active { background-color: #2ec033; box-shadow: 0 2px rgb(189, 189, 189); transform: translateY(4px);}#clear { width: 80px; height: 30px; margin: 10px; border: none; cursor: pointer; font-size: 16px; font-weight: bold; background-color: #ff0000; color: white; border-radius: 5px;}#clear:active { background-color: #ff0000; box-shadow: 0 2px rgb(189, 189, 189); transform: translateY(4px);}#copy { width: 80px; height: 30px; margin: 10px; border: none; cursor: pointer; font-size: 16px; font-weight: bold; background-color: #2e68c0; color: white; border-radius: 5px;}#copy:active { background-color: #2e68c0; box-shadow: 0 2px rgb(189, 189, 189); transform: translateY(4px);}footer { flex: 0 0 auto; width: 100%; height: 30px; background: #f5f5f5; text-align: center; line-height: 30px; font-size: 14px; color: #666;}footer a { text-decoration: none; color: coral; font-weight: bold;}#alertmess { position: fixed; top: 25%; max-width: 100px; border-radius: 8px; padding: 10px 10px; background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 16px; text-align: center; z-index: 999; display: none;} js代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758let input = document.getElementById('input');let RubyOut = document.getElementById('RubyOut');let HTMLOut = document.getElementById('HTMLOut');let convert = document.getElementById('convert');let year = document.getElementById("year");let copy = document.getElementById('copy');let clear = document.getElementById('clear');let textarea = document.querySelector(".Ruby textarea");year.innerHTML = new Date().getFullYear();// 初始化kuroshirolet kuroshiro = new Kuroshiro();// 初始化kuroshiro-analyzer-kuromojikuroshiro.init(new KuromojiAnalyzer({ dictPath: "static/dict/"}))input.onchange = function () { if (input.value.length > 0 && (input.value.trim() != "")) { convert.disabled = false; convert.onclick = function () { kuroshiro.convert(input.value, { mode: "furigana", to: "hiragana" }).then(function (converted) { RubyOut.value = converted.trim(); HTMLOut.innerHTML = converted; alertmess('转换成功'); }); } } else { convert.disabled = true; }}copy.onclick = function () { textarea.select(); if (document.execCommand("copy")) { alertmess('复制成功'); }}clear.onclick = function () { input.value = ''; RubyOut.value = ''; HTMLOut.innerHTML = ''; alertmess('已清空');}function alertmess(mess) { let alertmess = document.getElementById('alertmess'); alertmess.innerHTML = mess; alertmess.style.display = 'block'; setTimeout(() => { alertmess.innerHTML = ''; alertmess.style.display = 'none'; }, 2000);} 字典文件

下载kuromoji项目中dict下的gz文件(共12个)

image

三、API说明

此处援引kuroshiro官网API说明

convert(str, [options])

转换指定的字符串到指定的音节文字(可在选项中配置注音模式等设置)。

参数

str - 将被转换的字符串。 options - 可选 转换选项,见下表。 选项 类型 默认值 描述 to String ‘hiragana’ 目标音节文字 hiragana (平假名), katakana (片假名), romaji (罗马字) mode String ‘normal’ 转换模式 normal (标准模式), spaced (空格分组), okurigana (送假名), furigana (注音假名) romajiSystem* String “hepburn” 罗马字体系 nippon (日本式), passport (护照式), hepburn (平文式) delimiter_start String ’(‘ 分隔符 (起始) delimiter_end String ’)’ 分隔符 (结束)

**: romajiSystem参数仅当to参数设置为romaji时生效。有关这一参数的更多信息, 请见 罗马字体系*

示例

12// normal (标准模式)kuroshiro.convert("感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!", {mode:"okurigana", to:"hiragana"});

结果:かんじとれたらてをつなごう、かさなるのはじんせいのライン and レミリアさいこう!

12// spaced (空格分组)kuroshiro.convert("感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!", {mode:"okurigana", to:"hiragana"});

结果:かんじとれ たら て を つなご う 、 かさなる の は じんせい の ライン and レミ リア さいこう !

12// okurigana (送假名)kuroshiro.convert("感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!", {mode:"okurigana", to:"hiragana"});

结果:感(かん)じ取(と)れたら手(て)を繋(つな)ごう、重(かさ)なるのは人生(じんせい)のライン and レミリア最高(さいこう)!

12// furigana (注音假名)kuroshiro.convert("感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!", {mode:"furigana", to:"hiragana"});

结果:感(かん)じ取(と)れたら手(て)を繋(つな)ごう、重(かさ)なるのは人生(じんせい)のライン and レミリア最高(さいこう)!

实用工具

示例

1const result = Kuroshiro.Util.isHiragana("あ")); isHiragana(char)

判断输入字符是否是平假名。

isKatakana(char)

判断输入字符是否是片假名。

isKana(char)

判断输入字符是否是假名。

isKanji(char)

判断输入字符是否是日文汉字。

isJapanese(char)

判断输入字符是否是日文。

hasHiragana(str)

检查输入字符串中是否含有平假名。

hasKatakana(str)

检查输入字符串中是否含有片假名。

hasKana(str)

检查输入字符串中是否含有假名。

hasKanji(str)

检查输入字符串中是否含有日文汉字。

hasJapanese(str)

检查输入字符串中是否含有日文。

kanaToHiragna(str)

转换输入假名字符串至平假名。

kanaToKatakana(str)

转换输入假名字符串至片假名。

kanaToRomaji(str, system)

转换输入假名字符串至罗马字。参数system可选值为"nippon", "passport", "hepburn" (默认值: “hepburn”)。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3