From 7ddd045ff337b100b30bc27db38b490877c3e1ea Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Thu, 30 Jun 2022 17:01:07 +0530 Subject: [PATCH 2/2] Add new customizable phonetic Tamil input method * lisp/leim/quail/indian.el (quail-tamil-itrans-compute-syllable-table): New function extracted from.. (quail-tamil-itrans-syllable-table): ... here. Use above function. (quail-tamil-itrans-compute-signs-table): Add new argument VARIOUS. (quail-tamil-itrans-various-signs-and-digits-table) (quail-tamil-itrans-various-signs-table): Adjust function call, and add TAMIL OM sign translation. (tamil): New phonetic Tamil input method. (tamil-vowel-translation, tamil-consonant-translation) (tamil-misc-translation, tamil-native-digits): New defcustoms to change the translation rules of the input method. (tamil-uyir-translation, tamil-mei-translation): Aliases to new defcustom for better discoverability. (tamil--syllable-table, tamil--signs-table, tamil--hashtables) (tamil--vowel-signs): Internal variables used by the Tamil input method. (tamil--make-trans-table): Function to produce an itrans compatible translation table. (tamil--update-quail-rules): Function to update the translation rules for the Tamil input method. * lisp/language/indian.el ("Tamil"): Change the default input method of the Tamil language environment to the phonetic input method. --- lisp/language/indian.el | 2 +- lisp/leim/quail/indian.el | 276 +++++++++++++++++++++++++++++--------- 2 files changed, 211 insertions(+), 67 deletions(-) diff --git a/lisp/language/indian.el b/lisp/language/indian.el index 2887d410ad..91ad818533 100644 --- a/lisp/language/indian.el +++ b/lisp/language/indian.el @@ -109,7 +109,7 @@ 'devanagari "Tamil" '((charset unicode) (coding-system utf-8) (coding-priority utf-8) - (input-method . "tamil-itrans") + (input-method . "tamil") (sample-text . "Tamil (தமிழ்) வணக்கம்") (documentation . "\ South Indian Language Tamil is supported in this language environment.")) diff --git a/lisp/leim/quail/indian.el b/lisp/leim/quail/indian.el index 8fffcc3511..120a446b44 100644 --- a/lisp/leim/quail/indian.el +++ b/lisp/leim/quail/indian.el @@ -127,47 +127,18 @@ "\\''" indian-mlm-itrans-v5-hash "malayalam-itrans" "Malayalam" "MlmIT" "Malayalam transliteration by ITRANS method.") -(defvar quail-tamil-itrans-syllable-table - (let ((vowels - '(("அ" nil "a") - ("ஆ" "ா" "A") - ("இ" "ி" "i") - ("ஈ" "ீ" "I") - ("உ" "ு" "u") - ("ஊ" "ூ" "U") - ("எ" "ெ" "e") - ("ஏ" "ே" "E") - ("ஐ" "ை" "ai") - ("ஒ" "ொ" "o") - ("ஓ" "ோ" "O") - ("ஔ" "ௌ" "au"))) - (consonants - '(("க" "k") ; U+0B95 - ("ங" "N^") ; U+0B99 - ("ச" "ch") ; U+0B9A - ("ஞ" "JN") ; U+0B9E - ("ட" "T") ; U+0B9F - ("ண" "N") ; U+0BA3 - ("த" "t") ; U+0BA4 - ("ந" "n") ; U+0BA8 - ("ப" "p") ; U+0BAA - ("ம" "m") ; U+0BAE - ("ய" "y") ; U+0BAF - ("ர" "r") ; U+0BB0 - ("ல" "l") ; U+0BB2 - ("வ" "v") ; U+0BB5 - ("ழ" "z") ; U+0BB4 - ("ள" "L") ; U+0BB3 - ("ற" "rh") ; U+0BB1 - ("ன" "nh") ; U+0BA9 - ("ஜ" "j") ; U+0B9C - ("ஶ" nil) ; U+0BB6 - ("ஷ" "Sh") ; U+0BB7 - ("ஸ" "s") ; U+0BB8 - ("ஹ" "h") ; U+0BB9 - ("க்ஷ" "x" ) ; U+0B95 - )) - (virama #x0BCD) +;; FIXME: This only accepts a single translation for vowels. Ideally, +;; we want it to support mutliple translation just like consonants. +(defun quail-tamil-itrans-compute-syllable-table (vowels consonants) + "Return the syllable table for the input method as a string. +VOWELS is a list of (VOWEL SIGN TRANS) where VOWEL is a string or +character representing the Tamil vowel character, SIGN is the +vowel sign corresponding to VOWEL or nil for none, and TRANS is +the input sequence to insert VOWEL. +CONSONANTS is a list of (CONSONANT TRANS...) where CONSONANT is +the Tamil consonant character, and TRANS is one or more strings +that describe how to insert CONSONANT." + (let ((virama #x0BCD) clm) (with-temp-buffer (insert "\n") @@ -197,21 +168,42 @@ quail-tamil-itrans-syllable-table (insert (propertize "\t" 'display (list 'space :align-to clm)) (car c) (or (nth 1 v) "")) (setq clm (+ clm 6))) - (insert "\n" (or (nth 1 c) "") - (propertize "\t" 'display '(space :align-to 4)) - "|") - (setq clm 6) - - (dolist (v vowels) - (apply #'insert (propertize "\t" 'display (list 'space :align-to clm)) - (if (nth 1 c) (list (nth 1 c) (nth 2 v)) (list ""))) - (setq clm (+ clm 6)))) + (dolist (ct (cdr c)) + (insert "\n" (or ct "") + (propertize "\t" 'display '(space :align-to 4)) + "|") + (setq clm 6) + (dolist (v vowels) + (apply #'insert (propertize "\t" 'display (list 'space :align-to clm)) + (if ct (list ct (nth 2 v)) (list ""))) + (setq clm (+ clm 6))))) (insert "\n") (insert "----+") (insert-char ?- 74) (insert "\n") (buffer-string)))) +(defvar quail-tamil-itrans-syllable-table + (quail-tamil-itrans-compute-syllable-table + (let ((vowels (car indian-tml-base-table)) + trans v ret) + (dotimes (i (length vowels)) + (when (setq v (nth i vowels)) + (setq trans (nth i (car indian-itrans-v5-table-for-tamil))) + (push (append v (list (if (listp trans) (car trans) trans))) + ret))) + (setq ret (nreverse ret)) + ret) + (let ((consonants (cadr indian-tml-base-table)) + trans c ret) + (dotimes (i (length consonants)) + (when (setq c (nth i consonants)) + (setq trans (nth i (cadr indian-itrans-v5-table-for-tamil))) + (push (cons c (if (listp trans) trans (list trans))) + ret))) + (setq ret (nreverse ret)) + ret))) + (defvar quail-tamil-itrans-numerics-and-symbols-table (let ((numerics '((?௰ "பத்து") (?௱ "நூறு") (?௲ "ஆயிரம்"))) (symbols '((?௳ "நாள்") (?௴ "மாதம்") (?௵ "வருடம்") @@ -244,25 +236,28 @@ quail-tamil-itrans-numerics-and-symbols-table (insert "\n") (buffer-string)))) -(defun quail-tamil-itrans-compute-signs-table (digitp) +(defun quail-tamil-itrans-compute-signs-table (digitp various) "Compute the signs table for the tamil-itrans input method. -If DIGITP is non-nil, include the digits translation as well." - (let ((various '((?ஃ . "H") ("ஸ்ரீ" . "srii") (?ௐ))) - (digits "௦௧௨௩௪௫௬௭௮௯") +If DIGITP is non-nil, include the digits translation as well. +If VARIOUS is non-nil, then it should a list of (CHAR . TRANS) +where CHAR is the character/string to translate and TRANS is +CHAR's translation." + (let ((digits "௦௧௨௩௪௫௬௭௮௯") (width 6) clm) (with-temp-buffer - (insert "\n" (make-string 18 ?-) "+") - (when digitp (insert (make-string 60 ?-))) + (insert "\n" (make-string 18 ?-)) + (when digitp + (insert "+" (make-string 60 ?-))) (insert "\n") (insert (propertize "\t" 'display '(space :align-to 5)) "various" - (propertize "\t" 'display '(space :align-to 18)) "|") + (propertize "\t" 'display '(space :align-to 18))) (when digitp (insert - (propertize "\t" 'display '(space :align-to 45)) "digits")) - (insert "\n" (make-string 18 ?-) "+") + "|" (propertize "\t" 'display '(space :align-to 45)) "digits")) + (insert "\n" (make-string 18 ?-)) (when digitp - (insert (make-string 60 ?-))) + (insert "+" (make-string 60 ?-))) (insert "\n") (setq clm 0) @@ -270,7 +265,8 @@ quail-tamil-itrans-compute-signs-table (insert (propertize "\t" 'display (list 'space :align-to clm)) (car (nth i various))) (setq clm (+ clm width))) - (insert (propertize "\t" 'display '(space :align-to 18)) "|") + (when digitp + (insert (propertize "\t" 'display '(space :align-to 18)) "|")) (setq clm 20) (when digitp (dotimes (i 10) @@ -283,23 +279,26 @@ quail-tamil-itrans-compute-signs-table (insert (propertize "\t" 'display (list 'space :align-to clm)) (or (cdr (nth i various)) "")) (setq clm (+ clm width))) - (insert (propertize "\t" 'display '(space :align-to 18)) "|") + (when digitp + (insert (propertize "\t" 'display '(space :align-to 18)) "|")) (setq clm 20) (when digitp (dotimes (i 10) (insert (propertize "\t" 'display (list 'space :align-to clm)) (format "%d" i)) (setq clm (+ clm width)))) - (insert "\n" (make-string 18 ?-) "+") + (insert "\n" (make-string 18 ?-)) (when digitp - (insert (make-string 60 ?-) "\n")) + (insert "+" (make-string 60 ?-) "\n")) (buffer-string)))) (defvar quail-tamil-itrans-various-signs-and-digits-table - (quail-tamil-itrans-compute-signs-table t)) + (quail-tamil-itrans-compute-signs-table + t '((?ஃ . "H") ("ஸ்ரீ" . "srii") (?ௐ . "OM")))) (defvar quail-tamil-itrans-various-signs-table - (quail-tamil-itrans-compute-signs-table nil)) + (quail-tamil-itrans-compute-signs-table + nil '((?ஃ . "H") ("ஸ்ரீ" . "srii") (?ௐ . "OM")))) (if nil (quail-define-package "tamil-itrans" "Tamil" "TmlIT" t "Tamil ITRANS")) @@ -347,6 +346,151 @@ quail-tamil-itrans-various-signs-table Full key sequences are listed below:") +;;; +;;; Tamil phonetic input method +;;; + +(defvaralias 'tamil-uyir-translation 'tamil-vowel-translation) +(defcustom tamil-vowel-translation + '(("அ" "a") ("ஆ" "aa") ("இ" "i") ("ஈ" "ii") + ("உ" "u") ("ஊ" "uu") ("எ" "e") ("ஏ" "ee") + ("ஐ" "ai") ("ஒ" "o") ("ஓ" "oo") ("ஔ" "au" "ow")) + "List of input sequences to translate to Tamil vowels. +Each element should be (VOWEL . TRANSLATIONS) where VOWEL is the +Tamil vowel character (உயிரெழுத்து) and TRANSLATIONS is the +list of input sequences to translate to that vowel." + :group 'leim + :type '(alist :key string :value-type (repeat string)) + :options (delq nil + (mapcar (lambda (x) (and (consp x) (string (car x)))) + (car indian-tml-base-table)))) + +(defvaralias 'tamil-mei-translation 'tamil-consonant-translation) +(defcustom tamil-consonant-translation + '(("க்" "k" "g") ("ங்" "ng") ("ச்" "ch" "s") ("ஞ்" "nj") ("ட்" "t" "d") + ("ண்" "N") ("த்" "th" "dh") ("ந்" "nh") ("ப்" "p" "b") ("ம்" "m") + ("ய்" "y") ("ர்" "r") ("ல்" "l") ("வ்" "v") ("ழ்" "z" "zh") + ("ள்" "L") ("ற்" "rh") ("ன்" "n") + ;; Sanskrit. + ("ஜ்" "j") ("ஸ்" "S") ("க்ஷ்" "ksH") ("ஷ்" "sh") ("ஹ்" "h") + ("க்‌ஷ்" "ksh") ("ஶ்" "Z")) + "List of input sequences to translate to Tamil consonants. +Each element should be (VOWEL . TRANSLATIONS) where VOWEL is the +Tamil consonant character (மெய் எழுத்து) and TRANSLATIONS is a list +of input sequences to translate to that consonant." + :group 'leim + :type '(alist :key string :value-type (repeat string)) + :options (delq nil + (mapcar (lambda (x) (if (stringp x) + (concat x "்") + ;; #x0BCD = pulli/virama. + (and x (string x #x0BCD)))) + (cadr indian-tml-base-table)))) + +(defcustom tamil-misc-translation + ;; ஃ is not a vowel or a consonant. + '(("ஃ" "F" "q") + ("ௐ" "OM")) + "List of input sequences to translate to various Tamil characters. +Each should element should be (CHARACTER . TRANSLATIONS) where +CHARACTER may be any string and TRANSLATIONS is a list of input +sequences to translate to that CHARACTER." + :group 'leim + :type '(alist :key string :value-type (repeat string))) + +(defcustom tamil-native-digits nil + "When non-nil, use Tamil native digits instead of Arabic ones." + :group 'leim + :type 'boolean) + +(defvar tamil--syllable-table nil) +(defvar tamil--signs-table nil) +(defvar tamil--hashtables nil) +(defvar tamil--vowel-signs + '(("அ" . nil) ("ஆ" . ?ா) ("இ" . ?ி) ("ஈ" . ?ீ) + ("உ" . ?ு) ("ஊ" . ?ூ) ("எ" . ?ெ) ("ஏ" . ?ே) + ("ஐ" . ?ை) ("ஓ" . ?ோ) ("ஒ" . ?ொ) ("ஔ" . ?ௌ))) + +(defun tamil--make-trans-table () + `((;; Vowels. + ,@(mapcar + (lambda (v) (assoc-default (and v (string (car v))) tamil-vowel-translation)) + (car indian-tml-base-table))) + (;; Consonants. + ,@(mapcar + (lambda (c) + (when c + (assoc-default (if (stringp c) + (concat c "்") + ;; #x0BCD = pulli/virama. + (string c #x0BCD)) + tamil-consonant-translation))) + (nth 1 indian-tml-base-table))) + ;; Misc symbols. We will ignore the base table here. + ())) + +(defun tamil--update-quail-rules () + (let ((quail-current-package (assoc "tamil" quail-package-alist)) + (hts (indian-make-hash (if tamil-native-digits + indian-tml-base-digits-table + indian-tml-base-table) + (tamil--make-trans-table)))) + ;; Do the misc characters here. + (indian--puthash-m (mapcar #'car tamil-misc-translation) + (mapcar #'cdr tamil-misc-translation) + hts) + (setq tamil--hashtables hts + tamil--syllable-table + (quail-tamil-itrans-compute-syllable-table + (mapcar (lambda (v) (list (car v) (assoc-default (car v) tamil--vowel-signs) + (cadr v))) + tamil-vowel-translation) + (mapcar (lambda (c) (cons (substring (car c) 0 -1) (cdr c))) + tamil-consonant-translation)) + tamil--signs-table + ;; FIXME: This should also show how to input ஸ்ரீ (default: Srii). + (quail-tamil-itrans-compute-signs-table + tamil-native-digits + (mapcar (lambda (m) (cons (car m) (cadr m))) tamil-misc-translation))) + ;; (nth 2 ...) = quail-map. + (setf (nth 2 quail-current-package) '(nil)) + (maphash (lambda (k v) + (quail-defrule k (if (length= v 1) + (string-to-char v) + (vector v)))) + (cdr hts)))) + +(quail-define-package + "tamil" "Tamil" "ழ" t + "Customisable Tamil phonetic input method. +To change the translation of vowels (உயிரெத்துக்கள்), customize `tamil-vowel-translation'. +To change the translation of consonants (மெய் எழுத்துக்கள்), customize + `tamil-consonant-translation'. +To input miscellaneous characters (including ஃ), customize + `tamil-misc-translation'. +To use native Tamil digits, customize `tamil-native-digits'. + +To end the current translation process, say \\\\[quail-select-current] (defined in +`quail-translation-keymap'). This is useful when there's a + conflict between two possible translation. + +The current input scheme is: + +### Basic syllables (உயிர்மெய் எழுத்துக்கள்) ### +\\=\\ + +### Miscellaneous #### +\\=\\ + +The following characters have NO input sequence associated with +them by default. Their descriptions are included for easy +reference. +\\=\\ + +Full key sequences are listed below:" + nil nil nil nil nil nil t) +(tamil--update-quail-rules) + ;;; ;;; Input by Inscript ;;; -- 2.35.1