Skip to content

Commit

Permalink
Add Arabic transliteration via 3d party.
Browse files Browse the repository at this point in the history
  • Loading branch information
scossu committed Dec 28, 2022
1 parent 9bc9ee8 commit dae5433
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ext/arabic_transliterator"]
path = ext/arabic_transliterator
url = [email protected]:MTG/ArabicTransliterator.git
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ WORKDIR ${_workroot}
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY entrypoint.sh uwsgi.ini wsgi.py ./

COPY ext ./ext/
RUN pip install ext/arabic_transliterator

COPY scriptshifter ./scriptshifter/
RUN chmod +x ./entrypoint.sh

RUN addgroup -S www && adduser -S www -G www
RUN chown -R www:www ${_workroot} .

Expand Down
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ discussion, etc.); *X* = not implementing.
- *D* Transliteration
- *D* REST API
- *W* Complete conversion of existing tables to YAML
- *P* Arabic
- *X* Arabic
- *P* Armenian
- *D* Asian Cyrillic
- *D* Azerbajani
Expand Down Expand Up @@ -65,6 +65,6 @@ discussion, etc.); *X* = not implementing.
- *P* Urdu
- *D* Uzbek
- *P* Additional languages not in legacy tables, but in other software
- *B* Arabic S2R (ArabicTransliterator)
- *D* Arabic S2R (ArabicTransliterator)
- *B* Japanese (?)
- *B* Korean (K-romanizer)
2 changes: 1 addition & 1 deletion doc/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ configuration file. See [`config.md`](./config.md) for details.

The function name takes the form of `<module name>.<function name>` and must
correspond to an existing module and function under the `scriptshifter.hooks`
package. Check the [`rot3.yml`](../scriptshifter/tables/data/rot3.yml) test
package. Check the [`rot3.yml`](../tests/data/rot3.yml) test
configuration and the referred functions for a working example.

Each hook requires some arguments to be defined in each function associated
Expand Down
Empty file added ext/.keep
Empty file.
1 change: 1 addition & 0 deletions ext/arabic_transliterator
Submodule arabic_transliterator added at df0296
22 changes: 22 additions & 0 deletions scriptshifter/hooks/arabic_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging

# This requires ArabicTransliterator to be installed as a package.
from arabic.ArabicTransliterator import ALA_LC_Transliterator as Trans
from mishkal.tashkeel.tashkeel import TashkeelClass

from scriptshifter.exceptions import BREAK


__doc__ = """ Integrate external ArabicTransliterator library. """


logger = logging.getLogger(__name__)


def s2r_post_config(ctx):
trans = Trans()
vocalizer = TashkeelClass()
voc = vocalizer.tashkeel(ctx.src)
ctx.dest = trans.do(voc.strip())

return BREAK
2 changes: 1 addition & 1 deletion scriptshifter/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def load_hook_fn(cname, sec):
for cfg_hook_fn in cfg_hook_fns:
modname, fnname = path.splitext(cfg_hook_fn[0])
fnname = fnname.lstrip(".")
fn_kwargs = cfg_hook_fn[1]
fn_kwargs = cfg_hook_fn[1] if len(cfg_hook_fn) > 1 else {}
try:
fn = getattr(import_module(
"." + modname, HOOK_PKG_PATH), fnname)
Expand Down
12 changes: 12 additions & 0 deletions scriptshifter/tables/data/arabic_ext.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Arabic S2R using the 3rd-party ArabicTransliterator library:
# https://github.com/MTG/ArabicTransliterator

general:
name: Arabic (ArabicTransliterator)
description: Arabic S2R using a 3rd party library.

script_to_roman:
hooks:
post_config:
-
- arabic_ext.s2r_post_config
3 changes: 3 additions & 0 deletions scriptshifter/tables/data/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# key within the entry is the human-readable label that can be used in a
# multiple-choice menu.

arabic_ext:
name: Arabic (S2R)
description: Arabic-to-Roman transliterator using the ArabicTransliterator external library.
armenian:
name: Armenian
azerbaijani:
Expand Down

0 comments on commit dae5433

Please sign in to comment.