Skip to content

Commit

Permalink
better fix for reading multiline po-files
Browse files Browse the repository at this point in the history
  • Loading branch information
piranha committed Jun 27, 2019
1 parent 6862310 commit 694f991
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject ua.kasta/i18n "1.0.5"
(defproject ua.kasta/i18n "1.0.6"
:description "Internationalization lib"
:url "https://github.com/kasta-ua/i18n"
:license {:name "EPL-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/kasta/i18n.clj
Expand Up @@ -37,7 +37,7 @@


(defn get-trans [lang input]
(or (get (read-translations lang) input)
(or (not-empty (get (read-translations lang) input))
input))


Expand Down
13 changes: 6 additions & 7 deletions src/kasta/i18n/po.clj
Expand Up @@ -8,15 +8,14 @@
;;; Utils

(defn fmt-escaped [value]
(if (string? value)
value
(str "~" (pr-str value))))
(cond
(nil? value) value
(string? value) value
:else (str "~" (pr-str value))))


(defn read-escaped [value]
;; this looks like double-encoding since it is: first we generate string by
;; `fmt-escaped`, and then it's put in double-quotes in `gen-po`
(let [value (edn/read-string value)]
(not-empty
(if (= \~ (first value))
(edn/read-string (subs value 1))
value)))
Expand Down Expand Up @@ -75,7 +74,7 @@ msgstr \"\"
(fn [[line & rest]]
(let [[multiline-values rest] (split-with quoted-string? rest)
values (->> (concat [line] multiline-values)
(remove empty-str?))]
(map edn/read-string))]
[key (read-escaped (str/join values)) rest])))


Expand Down
4 changes: 4 additions & 0 deletions test/kasta/i18n/po_test.clj
Expand Up @@ -14,5 +14,9 @@
(let [single (test-data "single.po")]
(t/is (= {::po/msgid '(utils/plural warehouses " отделение" " отделения" " отделений")
::po/msgstr '(utils/plural warehouses " відділення" " відділення" " відділень")}
(po/parse-block single))))

(let [single (test-data "single2.po")]
(t/is (= {::po/msgid '(fmt (str "Заказ откорректирован на %s " "из-за нехватки доступных товаров") (utils/plural+ (- quantity new-quantity) "единицу" "единицы" "единиц"))}
(po/parse-block single))))))

0 comments on commit 694f991

Please sign in to comment.