1. Dave Ray
  2. j18n


Meikel Brandmeyer  committed a5070b2

Check if the key exists before retrieval

  • Participants
  • Parent commits c804b53
  • Branches default

Comments (0)

Files changed (1)

File src/main/clojure/j18n/core.clj

View file
  • Ignore whitespace
     (when-let [nspace (namespace message)]
       (::bundle (meta (the-ns (symbol nspace)))))))
+(def ^{:private true :tag java.util.HashSet} bundle-keys
+  (memoize
+    (fn [^ResourceBundle bundle]
+      (.keySet bundle))))
 (defn translate*
   "Translate the given message in the given bundle. For resolution rules see
   translate. However, if message is a string or an unqualified keyword, the
    (let [bundle @(resolve (message-to-bundle message))]
      (translate* message bundle)))
   ([message ^ResourceBundle bundle]
-   (.getString bundle (name message))))
+   (let [message (name message)]
+     (when (.contains (bundle-keys bundle) message)
+       (.getString bundle (name message))))))
 (defmacro translate
   "Translate the given message. Message may be a qualified or non-qualified