WanaKanaSwift is a port to Swift; I suppose technically it's more a wrapper than a port. I first wrote this code in 2019 for use in a couple of iOS apps. I decided to clean it up an make it available.
WanaKanaSwift is made available as a Swift package so there is no installation, per se needed. Rather you need to include the package as a dependency in your own Swift project. If you are using Xcode, then select the menu option
New > Swift Packages > Add Package Dependency.... If you are not using Xcode, you can specify the dependency in your
Package.swift with the following:
.package(url: "https://github.com/profburke/wanakanaswift", from: "1.0.0")
NOTE: The current version of WanaKanaSwift is 0.5.0. The project uses version numbers that follow the conventions outlined at semver.org. Check the tags in the Github repo to verify the current version and update the above dependency specifier as appropriate.
In addition to a library for use in your Swift project, this package also includes two, simple CLI utilities
The easiest way to build and install these two utilities is from the command line.
cd to the package's directory and run
The two executables will be in
.build/debug. Copy these into a directory on your
PATH, such as
/usr/local/bin and you're ready to roll.
After importing the package, you can use the functinality by calling the appropriate function. All functions are declared as static functions on
WanaKana struct (basically the struct
is just there for name-spacing). Examples follow:
import WanaKana print(WanaKana.isJapanese("泣き虫")) # prints true print(WanaKana.isHiragana("A")) # prints false let result = WanaKana.toHiragana("スーパー") # result = "すうぱあ" let result = WanaKana.stripOkurigana("お腹", leading: true), # result = "腹"
Both of these CLI tools support reciving input either through piping
echo "haiku toukyou oosaka" | tokana
or as command line arguments
toromaji とうきょう おおさか
How to Contribute
Thank you for taking the time to contribute!
There are many ways to contribute in addition to submitting code. Bug reports, feature suggestions, a logo for the project, and improvements to documentation are all appreciated.
When creating an issue, the more detail, the better. For bug reports in partciular, try to include at least the following information:
- The library version
- The operating system (macOS, Windows, etc) and version
- The expected behavior
- The observed behavior
- Step-by-step instructions for reproducing the bug
Ensure the PR description clearly describes the problem and solution. It should include the relevant issue number, if applicable.
Preferably, submit documentation changes by pull request. However, feel free to post your changes to an issue or send them to the project team.
- Documentation is sorely lacking...
- custom kana mapping
- custom romaji mapping
- The following need improved error handling:
- initing JSC
- evaluate script failure
- casting failure
- evaluate script failure
- casting, etc failure in loop
- Replace stringly-typing of allowed parameter in
isRomaji()with something type safe
testToKana(): Will convert punctuation but pass through spaces
testToKana(): splitIntoConvertedKana tests
testToRomaji(): Will convert punctuation and full-width spaces
- Research means for combining
For all error handling consider making use of the
tokenizeDetailed(): Perhaps create a type that behaves like an array of strings but can be queried for additional details.
All Swift code written by Matthew M. Burke and licensed according to the terms in the LICENSE file (also included in each Swift file).