kuroshiro.js 是一个用于处理日文文字转换的 JavaScript 库。
它提供了一些功能,比如将日文文字转换为假名(平假名和片假名)、将假名转换为罗马字母等。这个库可以帮助开发者在处理日文文字时实现简单的转换和处理操作。
项目原始地址:https://github.com/hexenq/kuroshiro
直接可用的 release 文件:https://github.com/cencuansen/kuroshiro
使用示例:furigana 模式(注音假名、振假名)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>日文假名标注工具</title>
<script src="kuroshiro.js"></script>
<script src="kuroshiro-analyzer-kuromoji.js"></script>
</head>
<body>
<div id="res"></div>
<script>
const res = document.getElementById('res');
const kuroshiro = new Kuroshiro();
kuroshiro.init(new KuromojiAnalyzer()).then((result) => {
kuroshiro.convert("教室に学生がいる", {
mode: 'furigana',
to: "hiragana"
}).then((result) => {
res.innerHTML = result;
})
})
</script>
</body>
</html>

注音假名生成结果有问题,解决:https://github.com/hexenq/kuroshiro/commit/aaa61f9da8e1cf25b4ee658fcc72b05e7765d3a5