Home

Awesome

Introduction

An Android port to OPENCC, a library to convert Simplified Chinese to Traditional Chinese and vice versa. In additional, it also adopts the regional vocabulary and terminology interchangeably during conversion among Mainland China Simplified Chinese, Taiwan Traditional Chinese and Hong Kong Traditional Chinese.

Note

This project uses git submodules to download the source code from OpenCC, please use --recursive flag when cloning this project

 git clone git@github.com:qichuan/android-opencc.git --recursive

Example

滑鼠裡面的矽二極體壞了,導致游標解析度降低。

in Traditional Taiwan Chinese will be converted to

鼠标里面的硅二极管坏了,导致光标分辨率降低。

in Simplified Chinese and using Mainland China terminology

Installation

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
	...
	    maven { url 'https://jitpack.io' }
	}
}
// Add the dependency
dependencies {
    ...
	implementation 'com.github.qichuan:android-opencc:1.2.0'
}

Usage

To use Chinese converter is easy, just call ChineseConverter.convert(originalText, conversionType, context));

Supported conversation types

Explanation

android-opencc leverages on the original OpenCC project and invoke the native code via JNI, the text phrase dictionary files are shipped in the assets folder. Android NDK does not provide means to create and read file streams from directly from assets folder, therefore the dictionary files are then copied to the application data folder in the first call of ChineseConverter.convert()

If you need to update the dictionary files in the assets folder, please remember to call ChineseConverter.clearDictDataFolder() once to clear the old dictionary files, so the new dictionary files will be effective in the next ChineseConverter.convert() call.

Compilation

You need the Android NDK for compilation, please download the NDK and configure the path to NDK in local.properties file.

Example apk

Download here

Feel free to feedback if there are any issues, and hope this library can be useful for you.

References