Skip to content
Snippets Groups Projects
Unverified Commit 94df06bd authored by adam-james's avatar adam-james Committed by GitHub
Browse files

Fix unescaped apostrophes in translated strings during .edn creation (#22357)

This fixes many minor translation errors where apostrohpes are missing in the rendered message. This is extremely
common in French translations. In some cases it even causes {0} params to be missed since they accidentally end up
inside an improperly escaped string.
parent b14c3958
No related branches found
No related tags found
No related merge requests found
......@@ -5,17 +5,16 @@
[i18n.create-artifacts.frontend :as frontend]
[metabuild-common.core :as u]))
;; TODO -- shouldn't this be `locales.edn`?
(defn- locales-dot-clj []
(defn- locales-dot-edn []
{:locales (conj (i18n/locales) "en")
:packages ["metabase"]
:bundle "metabase.Messages"})
(defn- generate-locales-dot-clj! []
(defn- generate-locales-dot-edn! []
(u/step "Create resources/locales.clj"
(let [file (u/filename u/project-root-directory "resources" "locales.clj")]
(u/delete-file-if-exists! file)
(spit file (with-out-str (pprint/pprint (locales-dot-clj))))
(spit file (with-out-str (pprint/pprint (locales-dot-edn))))
(u/assert-file-exists file))))
(defn- create-artifacts-for-locale! [locale]
......@@ -33,7 +32,7 @@
(defn create-all-artifacts! []
(u/step "Create i18n artifacts"
(generate-locales-dot-clj!)
(generate-locales-dot-edn!)
(create-artifacts-for-all-locales!)
(u/announce "Translation resources built successfully.")))
......
......@@ -23,10 +23,19 @@
:str-plural nil
:plural? false})))
(def ^:private apostrophe-regex
"Regex that matches incorrectly escaped apostrophe characters.
Matches on a single apostrophe surrounded by any letter, number, space, or diacritical character (chars with accents like é) and is case-insensitive"
#"(?<![^a-zA-Z0-9\s\u00C0-\u017F])'(?![^a-zA-Z0-9\s\u00C0-\u017F])")
(defn- fix-unescaped-apostrophes [message]
(update message :str str/replace apostrophe-regex "''"))
(defn- ->edn [{:keys [messages]}]
(eduction
(filter backend-message?)
(map plural->singular)
(map fix-unescaped-apostrophes)
i18n/print-message-count-xform
messages))
......
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