Giter VIP home page Giter VIP logo

opencc-rust's Introduction

OpenCC Rust

CI

Open Chinese Convert(OpenCC, 開放中文轉換) binding for the Rust language for conversion between Traditional Chinese and Simplified Chinese.

Compilation

To compile this crate, you need to compile the OpenCC C++ library first. You can install OpenCC in your operating system, or in somewhere in your file system. As for the latter, you need to set the following environment variables to link the OpenCC library:

  • OPENCC_LIB_DIRS: The directories of library files, like -L. Use : to separate.
  • OPENCC_LIBS: The library names that you want to link, like -l. Use : to separate. Typically, it contains opencc:marisa.
  • OPENCC_INCLUDE_DIRS: The directories of header files, like -i. Use : to separate.
  • OPENCC_STATIC: Whether to use static or dylib.
  • OPENCC_DYLIB_STDCPP: If you use static linking, and your OpenCC library is compiled by the GNU C, this environment variable should be set.
  • OPENCC_STATIC_STDCPP: If you use static linking, and your OpenCC library is compiled by musl libc, this environment variable should be set.

Examples

use opencc_rust::*;

let opencc = OpenCC::new(DefaultConfig::TW2SP).unwrap();

let s = opencc.convert("涼風有訊");

assert_eq!("凉风有讯", &s);

let s = opencc.convert_to_buffer(",秋月無邊", s);

assert_eq!("凉风有讯,秋月无边", &s);
use opencc_rust::*;

let opencc = OpenCC::new(DefaultConfig::S2TWP).unwrap();

let s = opencc.convert("凉风有讯");

assert_eq!("涼風有訊", &s);

let s = opencc.convert_to_buffer(",秋月无边", s);

assert_eq!("涼風有訊,秋月無邊", &s);

Static Dictionaries

Usually, OpenCC needs to be executed on an environment where OpenCC is installed. If you want to make it portable, you can enable the static-dictionaries feature.

[dependencies.opencc-rust]
version = "*"
features = ["static-dictionaries"]

Then, the generate_static_dictionary and generate_static_dictionaries functions are available.

The default OpenCC dictionaries will be compiled into the binary file by lazy_static_include crate. And you can use the two functions to recover them on demand.

For example,

use opencc_rust::*;

let output_path = "/path/to/dictionaries-directory";

generate_static_dictionary(&output_path, DefaultConfig::TW2SP).unwrap();

let opencc = OpenCC::new(Path::join(&output_path, DefaultConfig::TW2SP)).unwrap();

assert_eq!("凉风有讯", &opencc.convert("涼風有訊"));

Supported Platforms

This crate currently supports Linux. Other platforms are not guaranteed.

Crates.io

https://crates.io/crates/opencc-rust

Documentation

https://docs.rs/opencc-rust

License

Apache-2.0

opencc-rust's People

Contributors

ckaznable avatar dependabot[bot] avatar magiclen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

isgasho

opencc-rust's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.