Skip to content

Commit

Permalink
feat(worker): implement
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowee committed Nov 29, 2024
1 parent adfec05 commit e7b11c0
Show file tree
Hide file tree
Showing 9 changed files with 1,690 additions and 8 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Deploy Worker
on:
push:
pull_request:
repository_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
steps:
- uses: actions/checkout@v2
- name: Build & Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ once_cell = "1.20"
regex = "1.11"
ruzstd = { version = "0.7", optional = true }
strum = { version = "0.26", features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["serde_derive"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ It leverages the [Aho-Corasick](https://github.com/daac-tools/daachorse) algorit

🐍 **Python package w/ wheels via PyO3**: `pip install zhconv-rs` or `pip install zhconv-rs-opencc` (with rulesets from OpenCC)

🧩 **API demo**: https://zhconv.bamboo.workers.dev
<a href="https://deploy.workers.cloudflare.com/?url=https://github.com/gowee/zhconv-rs">
<img src="https://deploy.workers.cloudflare.com/button" height="20" alt="Deploy to Cloudflare Workers">
</a>

<details open>
<summary>Python snippet</summary>

Expand Down
27 changes: 25 additions & 2 deletions src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,52 @@ use crate::utils::get_with_fallback;

/// Chinese variants (a.k.a 中文變體), parsed from language tags, as listed in [Help:高级字词转换语法#组合转换标签](https://zh.wikipedia.org/wiki/Help:高级字词转换语法#组合转换标签).
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, Display, EnumString, VariantNames, IntoStaticStr,
Clone,
Copy,
Debug,
Default,
PartialEq,
Eq,
Hash,
Display,
EnumString,
VariantNames,
IntoStaticStr,
)]
#[strum(serialize_all = "kebab_case", ascii_case_insensitive)]
#[derive(Default)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "kebab-case")
)]
pub enum Variant {
#[default]
/// Chinese (dummy variant)
Zh,
/// Script: Traditional Chinese
#[cfg_attr(feature = "serde", serde(alias = "zh-Hant"))]
ZhHant,
/// Script: Simplified Chinese
#[cfg_attr(feature = "serde", serde(alias = "zh-Hans"))]
ZhHans,
/// Short for `zh-Hant-TW`, Script: Traditional Chinese, Region: Taiwan
#[cfg_attr(feature = "serde", serde(rename = "zh-tw", alias = "zh-TW"))]
// zh-t-w by serde by default
ZhTW,
/// Short for`zh-Hant-HK`, Script: Traditional Chinese, Region: Hong Kong
#[cfg_attr(feature = "serde", serde(rename = "zh-hk", alias = "zh-HK"))]
ZhHK,
/// Short for`zh-Hant-MO`, Script: Traditional Chinese, Region: Macau
#[cfg_attr(feature = "serde", serde(rename = "zh-mo", alias = "zh-MO"))]
ZhMO,
/// Short for`zh-Hans-MY`, Script: Simplified Chinese, Region: Malaysia
#[cfg_attr(feature = "serde", serde(rename = "zh-my", alias = "zh-MY"))]
ZhMY,
/// Short for`zh-Hans-SG`, Script: Simplified Chinese, Region: Singapore
#[cfg_attr(feature = "serde", serde(rename = "zh-sg", alias = "zh-SG"))]
ZhSG,
/// Short for`zh-Hans-CN`, Script: Simplified Chinese, Region: China (mainland)
#[cfg_attr(feature = "serde", serde(rename = "zh-cn", alias = "zh-CN"))]
ZhCN,
// Unknown(String)
}
Expand Down
1 change: 1 addition & 0 deletions worker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
node_modules
.wrangler
dist/
Loading

0 comments on commit e7b11c0

Please sign in to comment.