Kana.NET 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Kana.NET --version 1.0.2                
NuGet\Install-Package Kana.NET -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kana.NET" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kana.NET --version 1.0.2                
#r "nuget: Kana.NET, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kana.NET as a Cake Addin
#addin nuget:?package=Kana.NET&version=1.0.2

// Install Kana.NET as a Cake Tool
#tool nuget:?package=Kana.NET&version=1.0.2                

Kana.NET

Japanese Kana utility for .NET. Convert Hiragana and Katakana. Kana.NET depends on only .NET. Kana.NET doesn't invoke windows funtion. So it works on Linux too.

平仮名とカタカナを変換します。文字コードの計算処理だけで変換を実現しているためOSの機能に依存しません。 そのため、非日本語環境のWindowsやLinux上でも動作します。

You can get "どらえもん大好き" from this code.

string hiragana = Umayadia.Kana.KanaConverter.ToHiragana("ドラえもん大好き");

You can get "ドラエモン大好キ" from this code.

string katakana = Umayadia.Kana.KanaConverter.ToKatakana("ドラえもん大好き");

Custom mapper

MapToHiraganaプロパティを使用すると、カスタムなひらがな変換を定義できます。 MapToKatakanaプロパティを使用すると同様にカスタムなカタカナ変換を定義できます。

これらは静的なプロパティなので1度定義すればその後のすべての変換に適用されます。 カスタムな変換を無効にするには null を設定します。

sample

//Define custom map to Hiragana
Umayadia.Kana.KanaConverter.MapToHiragana =
    (System.Text.StringBuilder builder, string letter, string suggestion, string source) =>
    {
        builder.Append(letter switch
        {
            "ド" => "★",
            "ラ" => "ららら~",
            _ => suggestion
        });
    };

string result1 = Umayadia.Kana.KanaConverter.ToHiragana("ドラえもん大好き");
Console.WriteLine(result1); //★ららら~えもん大好き

sample

//Define custom map to Hiragana
Umayadia.Kana.KanaConverter.MapToKatakana =
    (System.Text.StringBuilder builder, string letter, string suggestion, string source) =>
    {
        builder.Append(letter switch
        {
            "え" => "e",
            "も" => "MO",
            _ => suggestion
        });
    };

string result2 = Umayadia.Kana.KanaConverter.ToKatakana("ドラえもん大好き");
Console.WriteLine(result2); //ドラeMOン大好キ

カスタム変換用の関数は1文字ごとに呼ばれます。引数の意味は次の通りです。

builder

変換結果のバッファーです。ここに変換後の文字を追加してください。 ここに何も追加しないと、その文字は無視されます。

letter

この文字に対する変換を定義してください。言い換えるとこれは変換前の文字です。

suggestion

Kana.NET が提案する変換後の文字です。カスタムな変換が不要な場合、この文字をそのまま builder に追加してください。

source

変換を行おうとしている文字列全体です。

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 139,593 11/8/2021
1.0.5 385 11/6/2021
1.0.4 494 10/31/2021
1.0.3 373 10/30/2021
1.0.2 396 10/30/2021
1.0.1 381 10/26/2021
1.0.0 424 10/25/2021