Skip to content

shiningdracon/OpenCC-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCC-swift

OpenCC Swift wrapper

OS X Build Notes

This package requires the Home Brew build of OpenCC.

To install Home Brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Linux Build Notes

This package requires OpenCC installed.

git clone https://github.com/BYVoid/OpenCC.git
cd OpenCC
make
sudo make install

Building

Add this project as a dependency in your Package.swift file.

.Package(url:"https://github.com/shiningdracon/OpenCC-swift", majorVersion: 1)

Example

import OpenCC

let openccS2T = OpenCC(configFile: "s2t.json")
let openccT2S = OpenCC(configFile: "t2s.json")

func ChineseConvertSimplified2Traditional(_ s: String) -> String {
	if let t = openccS2T.convert(s) {
		return t
	} else {
		return ""
	}
}

func ChineseConvertTraditional2Simplified(_ t: String) -> String {
	if let s = openccT2S.convert(t) {
		return s
	} else {
		return ""
	}
}