├── .github └── workflows │ └── android.yml ├── .gitignore ├── .gitmodules ├── CHANGELOG.MD ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── zqc │ │ └── opencc │ │ └── android │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib-opencc-android ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zqc │ │ └── opencc │ │ └── andorid │ │ └── lib │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── openccdata │ │ ├── HKVariants.ocd2 │ │ ├── HKVariantsRev.ocd2 │ │ ├── HKVariantsRevPhrases.ocd2 │ │ ├── JPShinjitaiCharacters.ocd2 │ │ ├── JPShinjitaiPhrases.ocd2 │ │ ├── JPVariants.ocd2 │ │ ├── JPVariantsRev.ocd2 │ │ ├── STCharacters.ocd2 │ │ ├── STPhrases.ocd2 │ │ ├── TSCharacters.ocd2 │ │ ├── TSPhrases.ocd2 │ │ ├── TWPhrases.ocd2 │ │ ├── TWPhrasesRev.ocd2 │ │ ├── TWVariants.ocd2 │ │ ├── TWVariantsRev.ocd2 │ │ ├── TWVariantsRevPhrases.ocd2 │ │ ├── hk2s.json │ │ ├── hk2t.json │ │ ├── jp2t.json │ │ ├── s2hk.json │ │ ├── s2t.json │ │ ├── s2tw.json │ │ ├── s2twp.json │ │ ├── t2hk.json │ │ ├── t2jp.json │ │ ├── t2s.json │ │ ├── t2tw.json │ │ ├── tw2s.json │ │ ├── tw2sp.json │ │ ├── tw2t.json │ │ └── zFinished2 │ ├── java │ └── com │ │ └── zqc │ │ └── opencc │ │ └── android │ │ └── lib │ │ ├── ChineseConverter.java │ │ └── ConversionType.java │ └── jni │ ├── Android.mk │ ├── Application.mk │ └── chineseconverter.cpp ├── projectFilesBackup └── .idea │ └── workspace.xml └── settings.gradle /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: check out code recursively 12 | uses: actions/checkout@v1 13 | with: 14 | submodules: recursive 15 | - name: set up JDK 1.8 16 | uses: actions/setup-java@v1 17 | with: 18 | java-version: 1.8 19 | - name: Build with Gradle 20 | run: | 21 | touch local.properties 22 | ./gradlew build 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/* 5 | .DS_Store 6 | /build 7 | /captures 8 | /*/out 9 | **/build/* 10 | **/.externalNativeBuild 11 | **/.cxx 12 | .project 13 | .settings/* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib-opencc-android/src/main/jni/OpenCC"] 2 | path = lib-opencc-android/src/main/jni/OpenCC 3 | url = https://github.com/qichuan/OpenCC.git 4 | -------------------------------------------------------------------------------- /CHANGELOG.MD: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [1.2.0] - 2021-05-25 9 | 10 | ### Added 11 | - Update OpenCC dictionary data 12 | - Add hk2t support 13 | - Add jp2t support 14 | - Add t2jp support 15 | - Add tw2t support 16 | 17 | ### Changed 18 | - Replace ocd files with ocd2 files 19 | 20 | ## [1.1.0] - 2020-02-12 21 | 22 | ### Added 23 | 24 | - Update OpenCC data 25 | 26 | ## [1.0.0] - 2019-11-07 27 | 28 | ### Added 29 | 30 | - 1.0 release 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ZHANG Qichuan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | An Android port to [OPENCC](https://github.com/BYVoid/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. 4 | 5 | ## Note 6 | This project uses git submodules to download the source code from OpenCC, please use --recursive flag when cloning this project 7 | 8 | ``` 9 | git clone git@github.com:qichuan/android-opencc.git --recursive 10 | 11 | ``` 12 | 13 | ## Example 14 | ``` 15 | 滑鼠裡面的矽二極體壞了,導致游標解析度降低。 16 | ``` 17 | in Traditional Taiwan Chinese 18 | will be converted to 19 | ``` 20 | 鼠标里面的硅二极管坏了,导致光标分辨率降低。 21 | ``` 22 | in Simplified Chinese and using Mainland China terminology 23 | 24 | # Installation 25 | 26 | Add it in your root build.gradle at the end of repositories: 27 | ``` 28 | allprojects { 29 | repositories { 30 | ... 31 | maven { url 'https://jitpack.io' } 32 | } 33 | } 34 | ``` 35 | 36 | ``` 37 | // Add the dependency 38 | dependencies { 39 | ... 40 | implementation 'com.github.qichuan:android-opencc:1.2.0' 41 | } 42 | ``` 43 | 44 | # Usage 45 | To use Chinese converter is easy, just call `ChineseConverter.convert(originalText, conversionType, context));` 46 | 47 | ## Supported conversation types 48 | - HK2S, Traditional Chinese (Hong Kong Standard) to Simplified Chinese 香港繁體(香港小學學習字詞表標準)到簡體 49 | - HK2T, Traditional Chinese (Hong Kong variant) to Traditional Chinese 香港繁體(香港小學學習字詞表標準)到繁體 50 | - JP2T, New Japanese Kanji (Shinjitai) to Traditional Chinese Characters (Kyūjitai) 日本漢字到繁體 51 | - S2HK, Simplified Chinese to Traditional Chinese (Hong Kong Standard) 簡體到香港繁體(香港小學學習字詞表標準) 52 | - S2T, Simplified Chinese to Traditional Chinese 簡體到繁體 53 | - S2TW, Simplified Chinese to Traditional Chinese (Taiwan Standard) 簡體到臺灣正體 54 | - S2TWP, Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom 簡體到繁體(臺灣正體標準)並轉換爲臺灣常用詞彙 55 | - T2HK, Traditional Chinese to Traditional Chinese (Hong Kong Standard) 繁體到香港繁體(香港小學學習字詞表標準) 56 | - T2S, Traditional Chinese to Simplified Chinese 繁體到簡體 57 | - T2TW, Traditional Chinese to Traditional Chinese (Taiwan Standard) 繁體臺灣正體 58 | - TW2S, Traditional Chinese (Taiwan Standard) to Simplified Chinese 臺灣正體到簡體 59 | - T2JP, Traditional Chinese Characters (Kyūjitai) to New Japanese Kanji (Shinjitai) 繁體到日本漢字 60 | - TW2T, Traditional Chinese (Taiwan standard) to Traditional Chinese 臺灣正體到繁體 61 | - TW2SP, Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom 繁體(臺灣正體標準)到簡體並轉換爲中國大陸常用詞彙 62 | 63 | # Explanation 64 | 65 | 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()` 66 | 67 | 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. 68 | 69 | # Compilation 70 | 71 | You need the Android NDK for compilation, please download the [NDK](http://developer.android.com/ndk/downloads/index.html) and configure the path to NDK in `local.properties` file. 72 | 73 | # Example apk 74 | 75 | [Download here](https://www.dropbox.com/s/0qzcmchqf5hqyit/android-opencc-0.6.0.apk?dl=1) 76 | 77 | Feel free to feedback if there are any issues, and hope this library can be useful for you. 78 | 79 | # References 80 | - https://github.com/BYVoid/OpenCC 81 | - https://github.com/gelosie/OpenCC/tree/master/iOS 82 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion = 30 5 | buildToolsVersion = "30.0.3" 6 | ndkVersion "21.1.6352462" 7 | 8 | defaultConfig { 9 | applicationId "com.zqc.opencc.android" 10 | minSdkVersion 15 11 | targetSdkVersion 30 12 | } 13 | } 14 | 15 | android.buildTypes { 16 | release { 17 | minifyEnabled = false 18 | proguardFiles.add(file('proguard-rules.txt')) 19 | } 20 | } 21 | 22 | dependencies { 23 | //implementation project(':lib-opencc-android') 24 | implementation 'com.github.qichuan:android-opencc:1.2.0' 25 | implementation 'androidx.appcompat:appcompat:1.3.0' 26 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/zhangqichuan/dev/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/zqc/opencc/android/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zqc.opencc.android; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.AdapterView; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.EditText; 9 | import android.widget.Spinner; 10 | 11 | import com.zqc.opencc.android.lib.ChineseConverter; 12 | import com.zqc.opencc.android.lib.ConversionType; 13 | 14 | import java.util.concurrent.ExecutorService; 15 | import java.util.concurrent.Executors; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | 19 | private ConversionType currentConversionType = ConversionType.TW2SP; 20 | 21 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | 28 | Spinner spinner = findViewById(R.id.spinner); 29 | ArrayAdapter adapter = ArrayAdapter.createFromResource(this, 30 | R.array.conversion_type_array, android.R.layout.simple_spinner_item); 31 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 32 | spinner.setAdapter(adapter); 33 | 34 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 35 | @Override 36 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 37 | switch (position) { 38 | case 0: 39 | currentConversionType = ConversionType.TW2SP; 40 | break; 41 | case 1: 42 | currentConversionType = ConversionType.S2HK; 43 | break; 44 | case 2: 45 | currentConversionType = ConversionType.S2T; 46 | break; 47 | case 3: 48 | currentConversionType = ConversionType.S2TW; 49 | break; 50 | case 4: 51 | currentConversionType = ConversionType.S2TWP; 52 | break; 53 | case 5: 54 | currentConversionType = ConversionType.T2HK; 55 | break; 56 | case 6: 57 | currentConversionType = ConversionType.T2S; 58 | break; 59 | case 7: 60 | currentConversionType = ConversionType.T2TW; 61 | break; 62 | case 8: 63 | currentConversionType = ConversionType.TW2S; 64 | break; 65 | case 9: 66 | currentConversionType = ConversionType.HK2S; 67 | break; 68 | } 69 | } 70 | 71 | @Override 72 | public void onNothingSelected(AdapterView parent) { 73 | 74 | } 75 | }); 76 | 77 | final EditText textView = findViewById(R.id.text); 78 | 79 | findViewById(R.id.btn).setOnClickListener(v -> { 80 | String originalText = textView.getText().toString(); 81 | Runnable runnable = () -> { 82 | final String converted = ChineseConverter.convert(originalText, 83 | currentConversionType, getApplicationContext()); 84 | textView.post(() -> textView.setText(converted)); 85 | }; 86 | executorService.execute(runnable); 87 | }); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 24 | 25 |