OpenCC 0.1.0

dotnet add package OpenCC --version 0.1.0
                    
NuGet\Install-Package OpenCC -Version 0.1.0
                    
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="OpenCC" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenCC" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="OpenCC" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenCC --version 0.1.0
                    
#r "nuget: OpenCC, 0.1.0"
                    
#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.
#:package OpenCC@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenCC&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=OpenCC&version=0.1.0
                    
Install as a Cake Tool

OpenCC

純 C# 版本的 OpenCC 函式庫,無任何 NuGet 套件依賴。

安裝

dotnet add package OpenCC

專案結構

  • src/OpenCC/:函式庫原始碼
  • tests/OpenCC.Tests/:xUnit 單元測試
  • OpenCC.sln:解決方案檔,便於一鍵建置與測試

基本用法

using OpenCC;

var converter = OpenCC.Converter("cn", "tw2");
Console.WriteLine(converter("汉语")); // 漢語

自訂轉換器

使用陣列定義

using OpenCC;

var converter = OpenCC.CustomConverter(new[]
{
    new DictEntry("香蕉", "banana"),
    new DictEntry("蘋果", "apple"),
});

Console.WriteLine(converter("我喜歡吃香蕉和蘋果"));

使用字串定義

using OpenCC;

var converter = OpenCC.CustomConverter("香蕉 banana|蘋果 apple|梨 pear");
Console.WriteLine(converter("香蕉 蘋果 梨"));

進階組合

using OpenCC;

var customDict = new[]
{
    new DictEntry("“", "「"),
    new DictEntry("”", "」"),
};

var converter = OpenCC.ConverterFactory(
    OpenCC.Locale.From.Cn,
    OpenCC.Locale.To.Tw.Concat(new[] { Dict.FromEntries(customDict) })
);

Console.WriteLine(converter("悟空道:“师父又来了。”"));

HTML / XML 轉換 (XDocument)

HtmlConverterSystem.Xml.Linq 為基礎,適用於 XML 或可解析為 XML 的 HTML 片段。

using System.Xml.Linq;
using OpenCC;

var converter = OpenCC.Converter("hk", "cn");
var doc = XDocument.Parse("<html lang='zh-HK'><body><p lang='zh-HK'>漢語</p></body></html>");

var htmlConverter = OpenCC.HtmlConverter(converter, doc, "zh-HK", "zh-CN");
htmlConverter.Convert();

Console.WriteLine(doc.ToString());

htmlConverter.Restore();

NuGet 封裝

dotnet pack src/OpenCC/OpenCC.csproj -c Release

產出的 .nupkg 會在 src/OpenCC/bin/Release/

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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
0.1.0 117 1/23/2026

Initial release