From e21d16069bef59567b4a630028e4746581c2bf2c Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:54:29 -0500 Subject: [PATCH] Translations of menu-items ^_^ --- dialogue.lisp | 4 ++-- flora-search-aurora.lisp | 17 +++++++++-------- ui.lisp | 5 +++-- util.lisp | 9 ++++++++- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/dialogue.lisp b/dialogue.lisp index fbe4bdf..66e8de2 100644 --- a/dialogue.lisp +++ b/dialogue.lisp @@ -60,14 +60,14 @@ If not, have some tea on me: I’m paying. =w=" (defun say (speaker &rest text) (list (list :speaker speaker :face 'talking-face :progress 0 - :text (or (getf text (…:system-language)) (getf text :en))) + :text (…:getf-lang text)) (car (face speaker 'normal-face)))) (defun mumble (speaker &rest text) (list (list :speaker speaker :progress 0 - :text (or (getf text (…:system-language)) (getf text :en))))) + :text (…:getf-lang text)))) (defun move (speaker world-coords &key (delay .05)) diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index 1abfdd1..8dff0d3 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -17,7 +17,7 @@ ;;;; A simple TUI-game made for the text-flavoured LibreJam of 2023-06! ;;;; See: https://jamgaroo.xyz/jams/2 -(ql:quickload '(alexandria assoc-utils cl-charms cl-tiled str)) +(ql:quickload '(alexandria anaphora assoc-utils cl-charms cl-tiled str)) (load "util.lisp") (load "input.lisp") @@ -107,16 +107,17 @@ with STATE-LOOP." args)))) -(defparameter *submenu* `(((label . "IDK") (selection . 100) (selected t)) - ((label . "GO BACK") (return . nil)))) +(defparameter *submenu* `(((LABEL :en "IDK") (selection . 100) (selected t)) + ((LABEL :en "GO BACK") (return . nil)))) -(defparameter *main-menu* `(((label . "PLAY") (selection . 100) (selected . t) +(defparameter *main-menu* `(((LABEL :en "PLAY" :eo "EKLUDI") + (selection . 100) (selected . t) (return . ,(make-main-overworld-state))) - ((label . "SUBMENU") (return . ,(📋:make-menu-state *submenu*))) - ((label . "QUIT") (return . nil)))) - - + ((LABEL :en "SUBMENU" :eo "SUBMENUO") + (return . ,(📋:make-menu-state *submenu*))) + ((LABEL :en "QUIT" :eo "REZIGNI") + (return . nil)))) (defun main () diff --git a/ui.lisp b/ui.lisp index 208fc23..0ad2252 100644 --- a/ui.lisp +++ b/ui.lisp @@ -111,11 +111,12 @@ left-to-right, unless negative — in which case, right-to-left." "Render several menu items to the matrix, starting at the given x/y coordinates, maximum width for any given item, and the height of all items. The item list should be an alist of the following format: - (((LABEL . “FOO”)(SELECTED . T)(SELECTION . 100)) ((LABEL . “BAR”)(SELECTION . -20)) ⋯)" + (((LABEL :en “BIRD” :eo “BIRDO”)(SELECTED . T)(SELECTION . 100)) + ((LABEL :en “BAR” :eo “BARO”)(SELECTION . -20)) ⋯)" (let ((x x)) (mapcar (lambda (item) - (let* ((label (cdr (assoc 'label item))) + (let* ((label (…:getf-lang (cdr (assoc 'label item)))) (selection (or (cdr (assoc 'selection item)) 0)) (width (…:at-most max-item-width diff --git a/util.lisp b/util.lisp index fb8f88a..667e8be 100644 --- a/util.lisp +++ b/util.lisp @@ -23,7 +23,7 @@ (:export #:split-string-by-length #:plist= #:at-least #:at-most - #:system-language #:langcode->keysym)) + #:system-language #:langcode->keysym #:getf-lang)) (in-package :flora-search-aurora.util) @@ -88,3 +88,10 @@ if the language is among the supported. Otherwise, nil." "Return the system language, if among the supported; otherwise, EN-glish." (or (langcode->keysym (uiop:getenv "LANG")) :en)) + + +(defun getf-lang (plist &optional (language (system-language)) (fallback-lang :en)) + "With a plist containing keys of language-codes, return the property either fitting the +preferred LANGUAGE, or the backup FALLBACK-LANG (if LANGUAGE’s is NIL)." + (or (getf plist language) + (getf plist fallback-lang)))