Skip to content

Commit

Permalink
Handle failure of braille translation of unknown words
Browse files Browse the repository at this point in the history
When the braille translation of an unknown word fails we have a
problem.

We simply do not add any braille to that particular word. The UI will
then disable all controlls on that word, i.e. you will not be able to
save it and.

To get rid of the word you will have to wrap it in a brl:select and
re-upload the xmlp
  • Loading branch information
egli committed Jan 28, 2025
1 parent 084e276 commit b531fac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
16 changes: 11 additions & 5 deletions src/clj/daisyproducer2/words.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@
untranslated (if (is-homograph? word)
(str/replace homograph-disambiguation "|" braille-dummy-text)
untranslated)]
(cond-> word
(and (contains? word :uncontracted) (nil? (:uncontracted word)))
(assoc :uncontracted (louis/translate untranslated (louis/translator (louis/get-tables 1 params))))
(and (contains? word :contracted) (nil? (:contracted word)))
(assoc :contracted (louis/translate untranslated (louis/translator (louis/get-tables 2 params)))))))
(try
(cond-> word
(and (contains? word :uncontracted) (nil? (:uncontracted word)))
(assoc :uncontracted (louis/translate untranslated (louis/translator (louis/get-tables 1 params))))
(and (contains? word :contracted) (nil? (:contracted word)))
(assoc :contracted (louis/translate untranslated (louis/translator (louis/get-tables 2 params)))))
;; if there was a problem with translating the word, simply return the
;; word without the braille added. That will serve as an indication that
;; the braille translation failed
(catch clojure.lang.ExceptionInfo e
word))))

(defn grades [grade]
(case (int grade) ; convert grade into a list of grades
Expand Down
4 changes: 4 additions & 0 deletions src/cljs/daisyproducer2/words/input_fields.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@
(defn disabled-field [value]
[:div.field
[:input.input {:type "text" :value value :disabled "disabled"}]])

(defn invalid-field []
[:div.field
[:input.input.is-danger {:type "text" :disabled "disabled"}]])
37 changes: 20 additions & 17 deletions src/cljs/daisyproducer2/words/unknown.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,26 @@
(let [grade @(rf/subscribe [::grade/grade])
{:keys [uuid untranslated uncontracted contracted type homograph-disambiguation
hyphenated invalid-hyphenated]} @(rf/subscribe [::word id])]
[:tr
[:td untranslated]
(when (#{0 1} grade)
(if uncontracted
[:td [fields/input-field :unknown uuid :uncontracted validation/braille-valid?]]
[:td]))
(when (#{0 2} grade)
(if contracted
[:td [fields/input-field :unknown uuid :contracted validation/braille-valid?]]
[:td]))
[:td (if hyphenated
[fields/input-field :unknown uuid :hyphenated #(validation/hyphenation-valid? % untranslated)]
[fields/disabled-field invalid-hyphenated])]
[:td {:width "8%"} (get words/type-mapping type (tr [:unknown]))]
[:td {:width "8%"} homograph-disambiguation]
[:td [fields/local-field :unknown uuid]]
[:td {:width "8%"} [buttons uuid]]]))
;; if we have neither the uncontracted nor the contracted field,
;; most likely the braille translation failed
(let [valid (or uncontracted contracted)]
[:tr
[:td untranslated]
(when (#{0 1} grade)
(if uncontracted
[:td [fields/input-field :unknown uuid :uncontracted validation/braille-valid?]]
[:td [fields/invalid-field]]))
(when (#{0 2} grade)
(if contracted
[:td [fields/input-field :unknown uuid :contracted validation/braille-valid?]]
[:td [fields/invalid-field]]))
[:td (if hyphenated
[fields/input-field :unknown uuid :hyphenated #(validation/hyphenation-valid? % untranslated)]
[fields/disabled-field invalid-hyphenated])]
[:td {:width "8%"} (get words/type-mapping type (tr [:unknown]))]
[:td {:width "8%"} homograph-disambiguation]
[:td (when valid [fields/local-field :unknown uuid])]
[:td {:width "8%"} (when valid [buttons uuid])]])))

(defn unknown-words []
(let [words @(rf/subscribe [::words-sorted])
Expand Down

0 comments on commit b531fac

Please sign in to comment.