Browse Source

Fix Korean double family name bug. (#80)

* Fix foreign name check; add foreign name option.

* Add default value and correct type to foreign_name option.

* Add UI checkbox.
Stefano Cossu 5 months ago
parent
commit
47ac5b56b4

+ 11 - 5
scriptshifter/hooks/korean/romanizer.py

@@ -167,7 +167,9 @@ def _romanize_name(src, options):
 
     # `parsed` can either be a modified Korean string with markers, or in case
     # of a foreign name, the final romanized name.
-    parsed, _warnings = _parse_kor_name(re.sub(r"\s{2,}", " ", src.strip()))
+    parsed, _warnings = _parse_kor_name(
+            re.sub(r"\s{2,}", " ", src.strip()),
+            options)
 
     if len(_warnings):
         warnings += _warnings
@@ -211,7 +213,7 @@ def _romanize_name(src, options):
     return "", warnings
 
 
-def _parse_kor_name(src):
+def _parse_kor_name(src, options):
     parsed = None
     warnings = []
 
@@ -225,14 +227,18 @@ def _parse_kor_name(src):
     src_len = len(src)
 
     # FKR005: Error if more than 7 syllables
-    if src_len > 7 or src_len < 2 or " " in src[3:]:
-        return _kor_corp_name_rom(src), warnings
+    if src_len > 7 or src_len < 2 or src.find(" ") > 2:
+        if options.get("foreign_name"):
+            return _kor_corp_name_rom(src), warnings
+        else:
+            warnings.append("ERROR: not a Korean name.")
+            return None, warnings
 
     ct_spaces = src.count(" ")
     # FKR0006: Error if more than 2 spaces
     if ct_spaces > 2:
         warnings.append("ERROR: not a name (too many spaces)")
-        return parsed, warnings
+        return None, warnings
 
     # FKR007: 2 spaces (two family names)
     if ct_spaces == 2:

+ 8 - 0
scriptshifter/tables/data/korean_names.yml

@@ -8,6 +8,14 @@ options:
     description: Romanize according to a specific MARC field format. Leave blank if not applicable.
     type: string
     default:
+  - id: foreign_name
+    label: Foreign name
+    description: >
+      The provided string shall be romanized as a foreign name.
+      If this option is deactivated, names not falling within the Korean name
+      schema will not be transliterated and a warning will be issued.
+    type: boolean
+    default: false
 
 script_to_roman:
   hooks:

+ 10 - 1
scriptshifter/templates/index.html

@@ -108,10 +108,19 @@
                         label.append(opt.label);
 
                         let input = document.createElement("input");
+                        if (opt.type == "boolean") {
+                            // Use checkbox for boolean type.
+                            input.setAttribute("type", "checkbox");
+                            if (opt.default) {
+                                input.setAttribute("checked", 1);
+                            }
+                        } else {
+                            // Use text for all other types.
+                            input.value = opt.default;
+                        }
                         input.setAttribute("id", opt.id);
                         input.setAttribute("name", opt.id);
                         input.classList.add("option_i");
-                        input.value = opt.default;
 
                         let descr = document.createElement("p");
                         descr.setAttribute("class", "input_descr");