Skip to content
Snippets Groups Projects
Unverified Commit 3e234a40 authored by Noah Moss's avatar Noah Moss Committed by GitHub
Browse files

Fix detection of backend files when generating i18n EDN (#26022)


* fix detection of backend files when generation i18n edn

* appease whitespace linter

* tweak comment

* fix cypress test

* appease linter

* Use eduction instead of threading

* Update bin/i18n/test/i18n/create_artifacts/backend_test.clj

Co-authored-by: default avatarTim Macdonald <tim@metabase.com>

Co-authored-by: default avatarTim Macdonald <tim@metabase.com>
parent 79bd538d
No related branches found
No related tags found
No related merge requests found
......@@ -7,14 +7,20 @@
java.nio.charset.StandardCharsets))
(defn- backend-message? [{:keys [source-references]}]
(some (fn [path]
(some
(fn [dir]
(str/starts-with? path dir))
["src" "backend" "enterprise/backend" "shared"]))
;; sometimes 2 paths exist in a single string, space separated
;; if a backend path is second, it is missed if we don't str/split
(mapcat #(str/split % #" ") source-references)))
(boolean
(let [paths (eduction
;; Sometimes 2 paths exist in a single string, space separated
(mapcat #(str/split % #" "))
;; Strip off the line number at the end of some paths
(map #(str/split % #":"))
(map first)
source-references)]
(some (fn [path]
(some
(fn [suffix]
(str/ends-with? path suffix))
[".clj" ".cljc"]))
paths))))
(def ^:private apostrophe-regex
"Regex that matches incorrectly escaped apostrophe characters.
......
......@@ -28,3 +28,33 @@
"}"]
(some-> (slurp "/tmp/out.edn")
(str/split-lines)))))
(deftest backend-message?
(testing "messages present in any .clj and .cljc files are detected as backend messages"
(are [source-references expected] (= (@#'backend/backend-message? {:source-references source-references})
expected)
;; Simple .clj and .cljc files with and without line numbers
["test.clj"] true
["test.clj:123"] true
["test.cljc"] true
["test.cljc:123"] true
;; Assorted real backend paths from the .po file
["src/metabase/query_processor/streaming/xlsx.clj"] true
["metabase/mbql/normalize.cljc:839"] true
["metabase/driver/common.clj:223"] true
["backend/mbql/src/metabase/mbql/normalize.clj"] true
["metabase_enterprise/audit_app/interface.clj:25"] true
["enterprise/backend/test/metabase_enterprise/serialization/load_test.clj"] true
["target/classes/metabase/server/request/util.clj"] true
;; Both a FE and a BE path
["frontend/src/metabase/browse/components/TableBrowser/TableBrowser.jsx:145"
"metabase/api/database.clj:178"] true
;; FE-only paths
["frontend/src/metabase/components/ActionButton.jsx:31"] false
["frontend/src/metabase/entities/collections/forms.js:22"] false
["frontend/src/metabase/public/components/widgets/SharingPane.tsx:69"] false
["test.cljs"] false
["test.cljs:123"] false
;; Invalid or empty references
[] false
["foo"] false)))
......@@ -17,7 +17,7 @@
:str-plural nil
:fuzzy? false
:plural? false
:source-references ["src/metabase/models/table.clj"]
:source-references ["metabase/models/table.clj"]
:comment nil})
(def singular-template-message-frontend
......@@ -37,7 +37,7 @@
:str-plural nil
:fuzzy? false
:plural? false
:source-references ["src/metabase/models/table.clj"]
:source-references ["src/metabase/models/table.clj:80"]
:comment nil})
(def plural-message-frontend
......
......@@ -18,7 +18,7 @@
[metabase.sync.field-values :as sync.field-values]
[metabase.types :as types]
[metabase.util :as u]
[metabase.util.i18n :refer [deferred-tru trs tru]]
[metabase.util.i18n :refer [deferred-tru trs]]
[metabase.util.schema :as su]
[schema.core :as s]
[toucan.db :as db]
......@@ -305,8 +305,8 @@
include_hidden_fields (s/maybe su/BooleanString)
include_editable_data_model (s/maybe su/BooleanString)}
(fetch-query-metadata (db/select-one Table :id id) {:include-sensitive-fields? include_sensitive_fields
:include-hidden-fields? include_hidden_fields
:include-editable-data-model? include_editable_data_model}))
:include-hidden-fields? include_hidden_fields
:include-editable-data-model? include_editable_data_model}))
(defn- card-result-metadata->virtual-fields
"Return a sequence of 'virtual' fields metadata for the 'virtual' table for a Card in the Saved Questions 'virtual'
......@@ -338,7 +338,7 @@
"Schema name to use for the saved questions virtual database for Cards that are in the root collection (i.e., not in
any collection)."
[]
(tru "Everything else"))
"Everything else")
(defn card->virtual-table
"Return metadata for a 'virtual' table for a `card` in the Saved Questions 'virtual' database. Optionally include
......
......@@ -117,15 +117,15 @@
(fn [n] (str (i18n/deferred-trsn "{0} table" "{0} tables" n)))}]
(testing message
(testing "Should fall back to English if user locale & system locale are unset"
(mt/with-temporary-setting-values [site-locale nil])
(is (= "0 tables"
(f 0)))
(mt/with-temporary-setting-values [site-locale nil]
(is (= "0 tables"
(f 0)))
(is (= "1 table"
(f 1)))
(is (= "1 table"
(f 1)))
(is (= "2 tables"
(f 2))))
(is (= "2 tables"
(f 2)))))
(testing "Should use system locale if set"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment