Don't throw exception if no valid file found; instead log it, and return nil.
This commit is contained in:
parent
a574b527c0
commit
53124ab1a8
|
@ -133,7 +133,7 @@
|
|||
* `default-locale` should be a locale specifier to use if no acceptable locale can be
|
||||
identified.
|
||||
|
||||
Returns a map of message keys to strings."
|
||||
Returns a map of message keys to strings; if no useable file is found, returns nil."
|
||||
{:doc/format :markdown}
|
||||
[^String accept-language-header ^String resource-path ^String default-locale]
|
||||
(let [file-path (first
|
||||
|
@ -143,6 +143,7 @@
|
|||
#(find-language-file-name % resource-path)
|
||||
(acceptable-languages accept-language-header))))]
|
||||
(timbre/debug (str "Found i18n file at '" file-path "'"))
|
||||
(try
|
||||
(read-string
|
||||
(slurp
|
||||
(or
|
||||
|
@ -150,7 +151,10 @@
|
|||
(.getAbsolutePath
|
||||
(io/file
|
||||
resource-path
|
||||
(str default-locale ".edn"))))))))
|
||||
(str default-locale ".edn"))))))
|
||||
(catch Exception any
|
||||
(timbre/error (str "Failed to load internationalisation because " (.getMessage any)))
|
||||
nil))))
|
||||
|
||||
|
||||
(def get-messages
|
||||
|
|
|
@ -203,4 +203,7 @@
|
|||
(is
|
||||
(=
|
||||
"Ceci n'est pas une pipe."
|
||||
(:pipe (get-messages "en-GB;q=0.9, fr-FR" "resources/i18n" "en-GB"))))))
|
||||
(:pipe (get-messages "en-GB;q=0.9, fr-FR" "resources/i18n" "en-GB"))))
|
||||
(is
|
||||
(= nil (get-messages "xx-XX;q=0.5, yy-YY" "resources/i18n" "zz-ZZ"))
|
||||
"If no usable file is found, an exception should not be thrown.")))
|
||||
|
|
Loading…
Reference in a new issue