Browse Source

Add Arabic transliteration via 3d party.

scossu 1 year ago
parent
commit
dae54334a7

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "ext/arabic_transliterator"]
+	path = ext/arabic_transliterator
+	url = git@github.com:MTG/ArabicTransliterator.git

+ 4 - 1
Dockerfile

@@ -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} .
 

+ 2 - 2
TODO.md

@@ -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
@@ -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)

+ 1 - 1
doc/hooks.md

@@ -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

+ 0 - 0
ext/.keep


+ 1 - 0
ext/arabic_transliterator

@@ -0,0 +1 @@
+Subproject commit df0296c5688a7bf07113fbab0f3c68c07df75edd

+ 22 - 0
scriptshifter/hooks/arabic_ext.py

@@ -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

+ 1 - 1
scriptshifter/tables/__init__.py

@@ -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)

+ 12 - 0
scriptshifter/tables/data/arabic_ext.yml

@@ -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 - 0
scriptshifter/tables/data/index.yml

@@ -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: