Skip to content

Commit

Permalink
Add rudimentary translation support
Browse files Browse the repository at this point in the history
See #285.
  • Loading branch information
tarsius committed Apr 29, 2024
1 parent 2dd0102 commit 4744ec2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,8 @@ This is bound while the suffixes are drawn in the transient buffer.")
mwheel-scroll
scroll-bar-toolkit-scroll))

(defvar transient-translation-function nil)

;;; Identities

(defun transient-prefix-object ()
Expand Down Expand Up @@ -3706,8 +3708,9 @@ have a history of their own.")

(cl-defmethod transient--insert-group :around ((group transient-group))
"Insert GROUP's description, if any."
(when-let ((desc (transient-with-shadowed-buffer
(transient-format-description group))))
(when-let* ((desc (transient-with-shadowed-buffer
(transient-format-description group)))
(desc (transient--maybe-translate obj desc)))
(insert desc ?\n))
(let ((transient--max-group-level
(max (oref group level) transient--max-group-level))
Expand Down Expand Up @@ -3921,6 +3924,11 @@ as a button."
(transient--add-face key 'transient-mismatched-key))
(key))))

(defun transient--maybe-translate (obj string)
(or (and transient-translation-function
(funcall transient-translation-function obj desc))
string))

(cl-defgeneric transient-format-description (obj)
"Format OBJ's `description' for display and return the result.")

Expand All @@ -3933,7 +3941,8 @@ and its value is returned to the caller."
(if (= (car (transient--func-arity desc)) 1)
(funcall desc obj)
(funcall desc))
desc)))
desc))
(desc (transient--maybe-translate obj desc)))
(if-let* ((face (transient--get-face obj 'face)))
(transient--add-face desc face t)
desc)))
Expand All @@ -3942,7 +3951,7 @@ and its value is returned to the caller."
"Format the description by calling the next method. If the result
doesn't use the `face' property at all, then apply the face
`transient-heading' to the complete string."
(and-let* ((desc (cl-call-next-method obj)))
(and-let* ((desc (transient--maybe-translate obj (cl-call-next-method obj))))
(if (text-property-not-all 0 (length desc) 'face nil desc)
desc
(propertize desc 'face 'transient-heading))))
Expand Down

0 comments on commit 4744ec2

Please sign in to comment.