From 2af28fef80917261ea620e4d78b5accae26c68b1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 20 Oct 2022 00:06:50 +0200 Subject: [PATCH] :bug: Fix autodetect language issues --- CHANGES.md | 2 ++ frontend/src/app/util/i18n.cljs | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 702ad177a..196fb3ecb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,8 @@ - Fix path nodes panel. "To curve" and "To corner" icons are active if node is already curved/cornered [Taiga #4371](https://tree.taiga.io/project/penpot/issue/4371) - Fix displaying comments settings are not applied via "Comments" menu drop-down on the top navbar on view mode [Taiga #4389](https://tree.taiga.io/project/penpot/issue/4389) - Fix bad behaviour on hovering and click nested artboards[Taiga #4018](https://tree.taiga.io/project/penpot/issue/4018) and [Taiga #4269](https://tree.taiga.io/project/penpot/us/4269) +- Fix lang autodetect issue [Taiga #4277](https://tree.taiga.io/project/penpot/issue/4277) + ## 1.16.0-beta diff --git a/frontend/src/app/util/i18n.cljs b/frontend/src/app/util/i18n.cljs index c031ee9ec..eaf898d1b 100644 --- a/frontend/src/app/util/i18n.cljs +++ b/frontend/src/app/util/i18n.cljs @@ -68,19 +68,22 @@ (defonce locale (l/atom (or (get @storage ::locale) (autodetect)))) -;; The translations `data` is a javascript object and should be treated -;; with `goog.object` namespace functions instead of a standart -;; clojure functions. This is for performance reasons because this -;; code is executed in the critical part (application bootstrap) and -;; used in many parts of the application. - (defn init! + "Initialize the i18n module with translations. + + The `data` is a javascript object for performance reasons. This code + is executed in the critical part (application bootstrap) and used in + many parts of the application." [data] (set! translations data)) (defn set-locale! [lname] - (if lname + (if (or (nil? lname) + (str/empty? lname)) + (let [lname (autodetect)] + (swap! storage dissoc ::locale) + (reset! locale lname)) (let [supported (into #{} (map :value supported-locales)) lname (loop [locales (seq (parse-locale lname))] (if-let [locale (first locales)] @@ -88,11 +91,7 @@ locale (recur (rest locales))) cfg/default-language))] - (swap! storage assoc ::locale lname) - (reset! locale lname)) - (let [lname (autodetect)] - (swap! storage dissoc ::locale) (reset! locale lname)))) (defn reset-locale