[Git][clojure-team/puppetlabs-i18n-clojure][upstream] New upstream version 0.9.2

Jérôme Charaoui (@lavamind) gitlab at salsa.debian.org
Sun Jan 22 04:29:19 GMT 2023



Jérôme Charaoui pushed to branch upstream at Debian Clojure Maintainers / puppetlabs-i18n-clojure


Commits:
22bd84d9 by Jérôme Charaoui at 2023-01-21T22:35:17-05:00
New upstream version 0.9.2
- - - - -


12 changed files:

- .gitignore
- .travis.yml
- + CHANGELOG.md
- README.md
- test/locales.clj → dev-resources/locales.clj
- project.clj
- src/leiningen/i18n.clj
- src/leiningen/i18n/utils.clj
- src/puppetlabs/i18n/core.clj
- src/puppetlabs/i18n/main.clj
- test/puppetlabs/i18n/bin_test.clj
- test/puppetlabs/i18n/core_test.clj


Changes:

=====================================
.gitignore
=====================================
@@ -1,3 +1,4 @@
+/.eastwood
 /target
 /classes
 /checkouts


=====================================
.travis.yml
=====================================
@@ -8,7 +8,17 @@ jobs:
     - stage: jdk11
       dist: bionic
       jdk: openjdk11
+    - stage: lint jdk11
+      dist: bionic
+      jdk: openjdk11
+      script: |
+        set -e
+        ./dev-setup
+        set -x
+        lein eastwood
+        lein check
+        set +x
 script: "./ext/travisci/test.sh"
 branches:
   only:
-    - master
+    - main


=====================================
CHANGELOG.md
=====================================
@@ -0,0 +1,4 @@
+## [0.9.1]
+
+- remove AOT and main specification from jar to make artifact more portable.
+- remove main specification in project.clj and update README with new example.


=====================================
README.md
=====================================
@@ -10,8 +10,8 @@ which a huge amount of tooling exists.
 The `main.clj` and `example/program` in this repo contain some simple code
 that demonstrates how to use the translation functions. Before you can use
 it, you need to run `make` to generate the necessary
-`ResourceBundles`. After that, you can use `lein run` or `LANG=de_DE lein
-run` to look at English and German output.
+`ResourceBundles`. After that, you can use `lein run -m puppetlabs.i18n.main`
+or `LANG=de_DE lein run -m puppetlabs.i18n.main` to look at English and German output.
 
 ## Developer usage
 


=====================================
test/locales.clj → dev-resources/locales.clj
=====================================


=====================================
project.clj
=====================================
@@ -1,4 +1,4 @@
-(defproject puppetlabs/i18n "0.9.0"
+(defproject puppetlabs/i18n "0.9.2"
   :description "Clojure i18n library"
   :url "http://github.com/puppetlabs/clj-i18n"
   :license {:name "Apache License, Version 2.0"
@@ -9,13 +9,13 @@
                  [cpath-clj "0.1.2"]
                  [org.gnu.gettext/libintl "0.18.3"]]
 
-  :profiles {:dev {:dependencies [[puppetlabs/kitchensink "2.1.0"
-                                   :exclusions [org.clojure/clojure]]]}}
-
-  :main puppetlabs.i18n.main
-  :aot [puppetlabs.i18n.main]
+  :profiles {:dev {:dependencies [[puppetlabs/kitchensink "3.1.3"
+                                   :exclusions [org.clojure/clojure]]]
+                   :plugins [[jonase/eastwood "0.8.1"
+                              :exclusions [org.clojure/clojure]]]}}
 
   :deploy-repositories [["releases" {:url "https://clojars.org/repo"
                                      :username :env/clojars_jenkins_username
                                      :password :env/clojars_jenkins_password
-                                     :sign-releases false}]])
+                                     :sign-releases false}]]
+  :eval-in-leiningen true)


=====================================
src/leiningen/i18n.clj
=====================================
@@ -7,7 +7,9 @@
             [clojure.pprint :as pprint]
             [clojure.string :as cstr]
             [clojure.java.shell :as sh :refer [sh]]
-            [cpath-clj.core :as cp]))
+            [cpath-clj.core :as cp])
+  (:import
+   (java.io File)))
 
 (defn help
   []
@@ -97,7 +99,7 @@
 (defn ensure-contains-line
   "Make sure that file contains the given line, if not append it. If file
   does not exist yet, create it and put line into it"
-  [file line]
+  [^File file line]
   (if (.isFile file)
     (let [contents (slurp file)]
       (if-not (.contains contents line)
@@ -136,7 +138,12 @@
 (defn i18n-make
   [project]
   (l/info "Running 'make i18n'")
-  (sh "make" "i18n"))
+  (let [{:keys [exit out err]} (sh "make" "i18n")]
+    (print out)
+    (binding [*out* *err*]
+      (print err))
+    (when-not (zero? exit)
+      (l/abort))))
 
 (defn abort
   [& rest]


=====================================
src/leiningen/i18n/utils.clj
=====================================
@@ -7,5 +7,5 @@
    replacement. Uses RegExp's m flag (?m) so that ^/$ matches beginning of line."
   [s regex-match replacement]
   (cstr/replace-first s
-                      (re-pattern (str "(?m)^" (.toString regex-match) "$"))
+                      (re-pattern (str "(?m)^" (str regex-match) "$"))
                       replacement))


=====================================
src/puppetlabs/i18n/core.clj
=====================================
@@ -156,11 +156,12 @@
        (binding [*locale* locale#] ~@body)
        (throw (IllegalArgumentException.
                (str "Expected java.util.Locale but got "
-                    (.getName (.getClass locale#))))))))
+                    (.getName (class locale#))))))))
 
-(defn user-locale []
+(defn user-locale
   "Return the user's preferred locale. If none is set, return the system
-  locale"
+  locale."
+  []
   (or *locale* (system-locale)))
 
 ;; @todo lutter 2015-04-21: there are various formats of string locales
@@ -182,7 +183,7 @@
   "Find the name of the ResourceBundle for the given namespace name"
   ([namespace]
    (bundle-for-namespace @info-map namespace))
-  ([i18n-info-map namespace]
+  ([i18n-info-map ^String namespace]
    (:bundle
     (get i18n-info-map
          (first (filter #(.startsWith namespace %)
@@ -195,9 +196,9 @@
 
 (defn get-bundle
   "Get the java.util.ResourceBundle for the given locale (a string)"
-  [namespace loc]
+  [namespace ^java.util.Locale loc]
   (try
-    (let [base-name (bundle-for-namespace namespace)]
+    (let [^String base-name (bundle-for-namespace namespace)]
       (and base-name
            (gnu.gettext.GettextResource/getBundle base-name loc)))
     (catch java.lang.NullPointerException e
@@ -312,12 +313,13 @@
            (remove
             ;; q values can only have three decimal places; we need to
             ;; remove all q values that are 0
-            (fn [[lang q]] (< q 0.0001))
-            (for [choice (remove str/blank? (str/split (str header) #","))]
-              (let [[lang q] (str/split choice #";")]
-                [(str/trim lang)
-                 (or (when q (as-number (get (str/split q #"=") 1)))
-                     1)])))))
+            (fn [[lang q]] (or (not q) (< q 0.0001)))
+            (doall
+             (for [choice (remove str/blank? (str/split (str header) #","))]
+               (when-let [[lang q] (seq (str/split choice #";"))]
+                 [(str/trim lang)
+                  (or (when q (as-number (get (str/split q #"=") 1)))
+                      1)]))))))
 
 (defn negotiate-locale
   "Given a string sequence of wanted locale (sorted by preference) and a
@@ -335,9 +337,11 @@
   ;; For example, if we have locales #{"de" "es"} available, and the user
   ;; asks for ["de_AT" "fr"], we should probably return "de" rather than
   ;; falling back to the message locale
-  (if-let [loc (some available wanted)]
-    (string-as-locale loc)
-    (system-locale)))
+  (if-not (seq wanted)
+    (system-locale)
+    (if-let [loc (some available wanted)]
+      (string-as-locale loc)
+      (system-locale))))
 
 (defn locale-negotiator
   "Ring middleware that performs locale negotiation.
@@ -350,8 +354,8 @@
     ;; @todo lutter 2015-06-03: remove our hand-crafted language
     ;; negotiation and use java.util.Locale/filterTags instead; this would
     ;; remove the gnarly parse-http-accept-header business. Requires Java 8
-    (let [headers (:headers request)
-          parsed  (parse-http-accept-header (get headers "accept-language"))
+    (let [lang (get-in request [:headers "accept-language"] "")
+          parsed  (parse-http-accept-header lang)
           wanted  (mapv first parsed)
           negotiated (negotiate-locale wanted (available-locales))]
       (with-user-locale negotiated (handler request)))))


=====================================
src/puppetlabs/i18n/main.clj
=====================================
@@ -14,7 +14,7 @@
   ;; This code ensures that translators never see this message since
   ;; xgettext doesn't see the string
   (let [dont-do-this "Current Locale: {0}"]
-    (println (tru dont-do-this (.toString (i18n/user-locale)))))
+    (println (tru dont-do-this (str (i18n/user-locale)))))
 
   ;; Very simple localization
   (println (trs "Welcome! This is localized"))


=====================================
test/puppetlabs/i18n/bin_test.clj
=====================================
@@ -3,7 +3,9 @@
             [clojure.string :as str]
             [clojure.test :refer :all]
             [clojure.java.shell :refer [sh]]
-            [puppetlabs.kitchensink.core :as ks]))
+            [puppetlabs.kitchensink.core :as ks])
+  (:import
+   (java.nio.file Path)))
 
 (defn git-head-sha
   []
@@ -21,7 +23,7 @@
     (io/copy (io/file resource) temp-file)
     temp-file))
 
-(defn- path [f] (.getPath f))
+(defn- path [^Path f] (.getPath f))
 
 (deftest add-gitref-test
   (testing "the src/leiningen/i18n/bin/add-gitref.sh script"


=====================================
test/puppetlabs/i18n/core_test.clj
=====================================
@@ -1,8 +1,24 @@
 (ns puppetlabs.i18n.core-test
-  (:require [clojure.test :refer :all]
-            [puppetlabs.i18n.core :refer :all]
-            [clojure.java.io :as io]
-            [clojure.pprint :refer [pprint]]))
+  (:require
+   [clojure.java.io :as io]
+   [clojure.pprint :refer [pprint]]
+   [clojure.test :refer :all]
+   [puppetlabs.i18n.core
+    :refer [as-number
+            available-locales
+            bundle-for-namespace
+            info-map'
+            locale-negotiator
+            negotiate-locale
+            parse-http-accept-header
+            string-as-locale
+            system-locale
+            trs
+            trsn
+            tru
+            trun
+            user-locale
+            with-user-locale]]))
 
 ;; Set the JVM's default locale so we run in a known environment
 (. java.util.Locale setDefault (string-as-locale "en-US"))
@@ -265,7 +281,8 @@
         (check "de" "de_DE, de;q=0.9, en;q=0.8")
         (check "oc" "it, fr"))
       (testing "falls back to system-locale for empty/invalid headers"
-        (map #(check "oc" %) ["" nil "en;q=garbage" ",,," ",;," "xyz" "de-US"])
+        (doseq [x ["" nil "en;q=garbage" ",,," ",;," "xyz" "de-US"]]
+          (check "oc" x))
         (is (= (system-locale) (neg {:headers {}})))
         (is (= (system-locale) (neg {}))))
       (testing "conveys the locale"



View it on GitLab: https://salsa.debian.org/clojure-team/puppetlabs-i18n-clojure/-/commit/22bd84d99b4a2567b4efa0b97b9a39b7d5582a4d

-- 
View it on GitLab: https://salsa.debian.org/clojure-team/puppetlabs-i18n-clojure/-/commit/22bd84d99b4a2567b4efa0b97b9a39b7d5582a4d
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20230122/b464b67c/attachment.htm>


More information about the pkg-java-commits mailing list