From d249867f63376cccf288a5af583ba62683554df8 Mon Sep 17 00:00:00 2001 From: scossu Date: Wed, 11 Feb 2026 19:05:19 -0500 Subject: [PATCH 1/9] Add Japanese S2R via PyKakasi. --- requirements.txt | 1 + scriptshifter/tables/data/japanese_hiragana.yml | 15 ++++----------- scriptshifter/tables/data/japanese_katakana.yml | 15 ++++----------- scriptshifter/tables/index.yml | 3 +++ 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9a20050..31d0989 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ aksharamukha>=2.2,<3 esupar>=1.7.5 flask>=2.3,<3 flask-cors>=4.0,<5 +pykakasi>=2.3,<3 python-dotenv>=1.0,<2 pyyaml>=6.0,<7 regex>=2023.8.8 diff --git a/scriptshifter/tables/data/japanese_hiragana.yml b/scriptshifter/tables/data/japanese_hiragana.yml index e0e6dbf..83f0e99 100644 --- a/scriptshifter/tables/data/japanese_hiragana.yml +++ b/scriptshifter/tables/data/japanese_hiragana.yml @@ -3,19 +3,12 @@ general: name: Japanese (Hiragana) case_sensitive: false description: Japanese language mapping for Hiragana syllabary. - version: 1.0.0 - date: 2025-12-23 + version: 2.0.0 + date: 2026-02-11 script_to_roman: hooks: post_config: - - - aksharamukha.romanizer.s2r_post_config - - src_script: "Hiragana" - -roman_to_script: - hooks: - post_config: - - - - aksharamukha.romanizer.r2s_post_config - - dest_script: "Hiragana" + - japanese.s2r_post_config + - src_code: "H" diff --git a/scriptshifter/tables/data/japanese_katakana.yml b/scriptshifter/tables/data/japanese_katakana.yml index c56f0ec..b4d2061 100644 --- a/scriptshifter/tables/data/japanese_katakana.yml +++ b/scriptshifter/tables/data/japanese_katakana.yml @@ -3,19 +3,12 @@ general: name: Japanese (Katakana) case_sensitive: false description: Japanese language mapping for Katakana syllabary. - version: 1.0.0 - date: 2025-12-23 + version: 2.0.0 + date: 2026-02-11 script_to_roman: hooks: post_config: - - - aksharamukha.romanizer.s2r_post_config - - src_script: "Katakana" - -roman_to_script: - hooks: - post_config: - - - - aksharamukha.romanizer.r2s_post_config - - dest_script: "Katakana" + - japanese.s2r_post_config + - src_code: "K" diff --git a/scriptshifter/tables/index.yml b/scriptshifter/tables/index.yml index df29230..1093f58 100644 --- a/scriptshifter/tables/index.yml +++ b/scriptshifter/tables/index.yml @@ -193,6 +193,9 @@ inuktitut: japanese_hiragana: marc_code: jpn name: Japanese (Hiragana) +japanese_kanji: + marc_code: jpn + name: Japanese (Kanji) japanese_katakana: marc_code: jpn name: Japanese (Katakana) From 7213cda47f9c344f30bc143e4bece29b85f88dce Mon Sep 17 00:00:00 2001 From: scossu Date: Wed, 11 Feb 2026 19:09:16 -0500 Subject: [PATCH 2/9] Add hook and Kanji. --- scriptshifter/hooks/japanese/__init__.py | 28 ++++++++++++++++++++ scriptshifter/tables/data/japanese_kanji.yml | 14 ++++++++++ 2 files changed, 42 insertions(+) create mode 100644 scriptshifter/hooks/japanese/__init__.py create mode 100644 scriptshifter/tables/data/japanese_kanji.yml diff --git a/scriptshifter/hooks/japanese/__init__.py b/scriptshifter/hooks/japanese/__init__.py new file mode 100644 index 0000000..240eeab --- /dev/null +++ b/scriptshifter/hooks/japanese/__init__.py @@ -0,0 +1,28 @@ +# @package ext + +__doc__ = """ +Transliterate Kanji, Katakana, and Hiragana into Romaji. """ + + +from logging import getLogger + +from pykakasi import kakasi + +from scriptshifter.exceptions import BREAK + + +logger = getLogger(__name__) +trans = kakasi() + + +def s2r_post_config(ctx, src_code): + if src_code not in "HKJ": + raise ValueError(f"Source script code {src_code} not supported.") + trans.setMode(src_code, "a") + # TODO Use option switch: “Hepburn” , “Kunrei” or “Passport” + trans.setMode("r", "Hepburn") + trans.setMode("C", ctx.options["capitalize"] is not False) + + ctx.dest = trans.getConverter().do(ctx.src) + + return BREAK diff --git a/scriptshifter/tables/data/japanese_kanji.yml b/scriptshifter/tables/data/japanese_kanji.yml new file mode 100644 index 0000000..adbae2d --- /dev/null +++ b/scriptshifter/tables/data/japanese_kanji.yml @@ -0,0 +1,14 @@ +--- +general: + name: Japanese (Kanji) + case_sensitive: false + description: Japanese language mapping for Kanji syllabary. + version: 1.0.0 + date: 2026-02-11 + +script_to_roman: + hooks: + post_config: + - + - japanese.s2r_post_config + - src_code: "J" From b5a35106f5daab4f1c91f6886e70d3d8f73628e3 Mon Sep 17 00:00:00 2001 From: scossu Date: Wed, 11 Feb 2026 19:38:22 -0500 Subject: [PATCH 3/9] Add options and capitalization for Japanese. --- scriptshifter/hooks/japanese/__init__.py | 7 ++++--- scriptshifter/tables/data/japanese_hiragana.yml | 14 ++++++++++++++ scriptshifter/tables/data/japanese_kanji.yml | 14 ++++++++++++++ scriptshifter/tables/data/japanese_katakana.yml | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/scriptshifter/hooks/japanese/__init__.py b/scriptshifter/hooks/japanese/__init__.py index 240eeab..2a283a2 100644 --- a/scriptshifter/hooks/japanese/__init__.py +++ b/scriptshifter/hooks/japanese/__init__.py @@ -19,9 +19,10 @@ def s2r_post_config(ctx, src_code): if src_code not in "HKJ": raise ValueError(f"Source script code {src_code} not supported.") trans.setMode(src_code, "a") - # TODO Use option switch: “Hepburn” , “Kunrei” or “Passport” - trans.setMode("r", "Hepburn") - trans.setMode("C", ctx.options["capitalize"] is not False) + trans.setMode("r", ctx.options.get("table", "Hepburn")) + trans.setMode("s", True) + # Both "first" and "all" behave as "all". + trans.setMode("C", not not ctx.options.get("capitalize", False)) ctx.dest = trans.getConverter().do(ctx.src) diff --git a/scriptshifter/tables/data/japanese_hiragana.yml b/scriptshifter/tables/data/japanese_hiragana.yml index 83f0e99..fec0e5a 100644 --- a/scriptshifter/tables/data/japanese_hiragana.yml +++ b/scriptshifter/tables/data/japanese_hiragana.yml @@ -6,6 +6,20 @@ general: version: 2.0.0 date: 2026-02-11 +options: + - id: table + label: Romanization table + description: Romanization table used for transliteration. + type: list + options: + - id: Hepburn + label: Hepburn + - id: Kunrei + label: Kunrei + - id: Passport + label: Passport + default: Hepburn + script_to_roman: hooks: post_config: diff --git a/scriptshifter/tables/data/japanese_kanji.yml b/scriptshifter/tables/data/japanese_kanji.yml index adbae2d..e290ae3 100644 --- a/scriptshifter/tables/data/japanese_kanji.yml +++ b/scriptshifter/tables/data/japanese_kanji.yml @@ -6,6 +6,20 @@ general: version: 1.0.0 date: 2026-02-11 +options: + - id: table + label: Romanization table + description: Romanization table used for transliteration. + type: list + options: + - id: Hepburn + label: Hepburn + - id: Kunrei + label: Kunrei + - id: Passport + label: Passport + default: Hepburn + script_to_roman: hooks: post_config: diff --git a/scriptshifter/tables/data/japanese_katakana.yml b/scriptshifter/tables/data/japanese_katakana.yml index b4d2061..a133802 100644 --- a/scriptshifter/tables/data/japanese_katakana.yml +++ b/scriptshifter/tables/data/japanese_katakana.yml @@ -6,6 +6,20 @@ general: version: 2.0.0 date: 2026-02-11 +options: + - id: table + label: Romanization table + description: Romanization table used for transliteration. + type: list + options: + - id: Hepburn + label: Hepburn + - id: Kunrei + label: Kunrei + - id: Passport + label: Passport + default: Hepburn + script_to_roman: hooks: post_config: From 4447f13ae05b84d8d7c96c06f2744efb1572302f Mon Sep 17 00:00:00 2001 From: scossu Date: Sat, 28 Feb 2026 18:35:53 -0500 Subject: [PATCH 4/9] UI adjustments. --- scriptshifter/static/ss.js | 1 + scriptshifter/templates/index.html | 38 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/scriptshifter/static/ss.js b/scriptshifter/static/ss.js index 49ff146..641449f 100644 --- a/scriptshifter/static/ss.js +++ b/scriptshifter/static/ss.js @@ -26,6 +26,7 @@ document.getElementById('lang').addEventListener('change',(event)=>{ data.forEach((opt)=>{ let fset = document.createElement("fieldset"); fset.setAttribute("class", "float-left"); + fset.setAttribute("class", "option"); let label = document.createElement("label"); label.setAttribute("for", opt.id); label.append(opt.label); diff --git a/scriptshifter/templates/index.html b/scriptshifter/templates/index.html index 4469d42..f4990b1 100644 --- a/scriptshifter/templates/index.html +++ b/scriptshifter/templates/index.html @@ -21,8 +21,8 @@ #results{ font-size: 1.25em; background-color: whitesmoke; - margin-top: 1em; padding: 1em; + margin-bottom: 1em; } #feedback_cont { @@ -50,13 +50,13 @@ margin: 20px auto; } + .option { display: inline-block; } +
- -
+

General Options

Direction -
+
-
+
@@ -82,17 +83,17 @@

General Options

Capitalize -
+
-
+
-
+
@@ -100,6 +101,18 @@

General Options

+ + + + + +
+ +
Results will appear here.
+
+
@@ -113,15 +126,6 @@

General Options

{% endif %} - - -
- -
Results will appear here.
-
- {% if feedback_form %}