mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
Internationalisation support
... but no actual translation files yet.
This commit is contained in:
parent
a2b6d6f72b
commit
8699b7cff4
8 changed files with 67 additions and 113 deletions
|
|
@ -5,6 +5,7 @@
|
|||
[org.clojure/core.memoize "0.5.9"]
|
||||
[org.clojure/data.json "0.2.6"]
|
||||
[org.clojure/tools.logging "0.4.0"]
|
||||
[org.clojars.simon_brooke/internationalisation "1.0.0"]
|
||||
[clj-jgit "0.8.9"]
|
||||
[clj-yaml "0.4.0"]
|
||||
[com.cemerick/url "0.1.1"]
|
||||
|
|
@ -15,6 +16,7 @@
|
|||
[crypto-password "0.2.0"]
|
||||
[environ "1.1.0"]
|
||||
[im.chit/cronj "1.4.4"]
|
||||
[instaparse "1.4.1"]
|
||||
[lib-noir "0.9.9" :exclusions [org.clojure/tools.reader]]
|
||||
[markdown-clj "0.9.99" :exclusions [com.keminglabs/cljx]]
|
||||
[noir-exception "0.2.5"]
|
||||
|
|
@ -32,7 +34,8 @@
|
|||
[lein-environ "1.0.0"]
|
||||
[lein-bower "0.5.1"]
|
||||
[lein-ancient "0.5.5" :exclusions [org.clojure/clojure org.clojure/data.xml]]
|
||||
[lein-marginalia "0.7.1" :exclusions [org.clojure/clojure]]]
|
||||
[lein-marginalia "0.7.1" :exclusions [org.clojure/clojure]]
|
||||
[lein-codox "0.10.3"]]
|
||||
:bower-dependencies [[simplemde "1.11.2"]
|
||||
;; [vega-embed "3.0.0-beta.19"] vega-embed currently not loaded from Bower because of
|
||||
;; dependency conflict which will hopefully be resolved soon.
|
||||
|
|
|
|||
|
|
@ -22,87 +22,13 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; config.edn: a simple configuration map for Smeagol; inspired by Cryogen.
|
||||
;;; This is essentially all the text in the chrome - that which isn't editable
|
||||
;;; through the wiki itself
|
||||
;;; This is top-level configuration.
|
||||
|
||||
;; ; ; ; ; ; ; ; ; ;
|
||||
{:add-user-label "Add new user" ;; label for the add user link on edit users page
|
||||
:change-pass-label "Change password!"
|
||||
;; text of the change password widget itself on the
|
||||
;; change password page
|
||||
:change-pass-link "Change password"
|
||||
;; text of the change password link on the menu
|
||||
:change-pass-prompt "To change your password"
|
||||
;; text of the change password widget prompt on the
|
||||
;; change password page
|
||||
:change-col-hdr "Changes" ;; header for the changes column in history
|
||||
:chpass-bad-match "Your proposed passwords don't match"
|
||||
;; error text if proposed passwords don't match
|
||||
:chpass-fail "Your password was not changed"
|
||||
;; error text on fail other htan too short or bad match
|
||||
:chpass-success "Your password was changed"
|
||||
;; confirmation text on password change
|
||||
:chpass-too-short "You proposed password wasn't long enough: eight characters required"
|
||||
;; error text if proposed password is too short
|
||||
:chpass-title-prefix "Change password for"
|
||||
;; prefix for title of change password page
|
||||
:cookies-about "About cookies" ;; about cookies text
|
||||
:cookies-more "This website stores session information as a 'cookie' on your browser. This helps us show you the content you want to see. This cookie does not identify you, and cannot be read by other websites. It is deleted by your browser as soon as you leave this site. This website does not use any third party cookies, so your visit here cannot be tracked by other websites."
|
||||
;; more about cookies text
|
||||
:default-page-title "Introduction" ;; title of the default page in this wiki
|
||||
:del-col-hdr "Delete" ;; header for delete column on edit users page
|
||||
:del-user-fail "Could not delete user"
|
||||
;; error message on failure to delete user
|
||||
:del-user-success "Successfully deleted user"
|
||||
;; confirmation message on deletion of user
|
||||
:diff-title-prefix "Changes since version"
|
||||
;; prefix for the header of the changes page
|
||||
:edit-col-hdr "Edit" ;; header for edit column on edit users page
|
||||
:edit-page-link "Edit this page"
|
||||
;; text of the edit page link on the content frame
|
||||
:edit-title-prefix "Edit" ;; prefix for title of edit content page
|
||||
:edit-users-link "Edit users" ;; text of the edit users link on the menu
|
||||
:edit-users-title "Select user to edit"
|
||||
;; title of edit users page
|
||||
:email-prompt "Email address" ;; text of the email widget prompt on edit user page
|
||||
:file-upload-link-text "You may link to this file using a link of the form"
|
||||
;; Text introducing the link to an uploaded file
|
||||
:file-upload-prompt "File to upload" ;; prompt string for the file upload widget
|
||||
:file-upload-title "Upload a file" ;; title for the file upload page
|
||||
:is-admin-prompt "Is administrator?"
|
||||
:home-link "Home" ;; text of the home link on the menu
|
||||
:login-label "Log in!" ;; text of the login widget on the login page
|
||||
:login-link "Log in" ;; text of the login link on the menu
|
||||
:login-prompt "To edit this wiki"
|
||||
;; text of the action widget prompt on the login page
|
||||
:logout-label "Log out!" ;; text of the logout widget on the logout page
|
||||
:logout-link "Log out" ;; text of the logout link on the menu
|
||||
:logged-in-as "You are logged in as"
|
||||
;; text of the 'logged in as' label on the menu
|
||||
:history-link "History" ;; text of the history link on the content frame
|
||||
:history-title-prefix "History of" ;; prefix of the title on the history page
|
||||
:new-pass-prompt "New password" ;; text of the new password widget prompt on the change
|
||||
;; password and edit user pages
|
||||
:old-pass-prompt "Your password"
|
||||
;; text of the old password widget prompt on the change
|
||||
;; password page, and password widget on login page
|
||||
:rpt-pass-prompt "And again" ;; text of the new password widget prompt on the change
|
||||
;; password and edit user pages
|
||||
:save-prompt "When you have finished editing"
|
||||
;; text of the save widget label on edit content
|
||||
;; and edit user page
|
||||
:save-label "Save!" ;; text of the save widget itself
|
||||
:save-user-fail "Failed to store user"
|
||||
:save-user-success "Successfully stored user"
|
||||
{
|
||||
:site-title "Smeagol" ;; overall title of the site, used in page headings
|
||||
:username-prompt "Username" ;; text of the username widget prompt on edit user page
|
||||
;; text of the is admin widget prompt on edit user page
|
||||
:user-title-prefix "Edit user" ;; prefix for title of edit user page
|
||||
:vers-col-hdr "Version" ;; header for the version column in history
|
||||
:what-col-hdr "What" ;; header for the what column in history
|
||||
:what-changed-prompt "What have you changed?"
|
||||
;; text of the summary widget prompt on edit
|
||||
;; content page
|
||||
:when-col-hdr "When" ;; header for the when column in history
|
||||
:your-uname-prompt "Your username" ;; text of the username widget prompt on the login page
|
||||
:default-locale "en-GB" ;; default language used for messages
|
||||
:formatters {"vega" smeagol.formatting/process-vega
|
||||
"vis" smeagol.formatting/process-vega
|
||||
"mermaid" smeagol.formatting/process-mermaid}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@
|
|||
:save-label "Save!" ;; text of the save widget itself
|
||||
:save-user-fail "Failed to store user"
|
||||
:save-user-success "Successfully stored user"
|
||||
:site-title "Smeagol" ;; overall title of the site, used in page headings
|
||||
:username-prompt "Username" ;; text of the username widget prompt on edit user page
|
||||
;; text of the is admin widget prompt on edit user page
|
||||
:user-title-prefix "Edit user" ;; prefix for title of edit user page
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
(ns ^{:doc "Format Semagol's enhanced markdown format."
|
||||
:author "Simon Brooke"}
|
||||
smeagol.formatting
|
||||
(:require [clojure.string :as cs]
|
||||
(:require [clojure.data.json :as json]
|
||||
[clojure.string :as cs]
|
||||
[cemerick.url :refer (url url-encode url-decode)]
|
||||
[clj-yaml.core :as yaml]
|
||||
[noir.io :as io]
|
||||
[noir.session :as session]
|
||||
[markdown.core :as md]
|
||||
[taoensso.timbre :as timbre]
|
||||
[smeagol.authenticate :as auth]
|
||||
[clj-yaml.core :as yaml]
|
||||
[clojure.data.json :as json]))
|
||||
))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
(content-type
|
||||
(->> (assoc params
|
||||
(keyword (s/replace template #".html" "-selected")) "active"
|
||||
:config util/config
|
||||
:config (util/get-messages request)
|
||||
:dev (env :dev)
|
||||
:servlet-context
|
||||
(if-let [context (:servlet-context request)]
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
user (session/get :user)]
|
||||
(layout/render "edit-users.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (:edit-users-title util/config)
|
||||
{:title (:edit-users-title (util/get-messages request))
|
||||
:users (auth/list-users)}))))
|
||||
|
||||
(defn delete-user
|
||||
|
|
@ -48,11 +48,11 @@
|
|||
(let [params (keywordize-keys (:params request))
|
||||
target (:target params)
|
||||
deleted (auth/delete-user target)
|
||||
message (if deleted (str (:del-user-success util/config) " " target "."))
|
||||
error (if (not deleted) (str (:del-user-fail util/config) " " target "."))]
|
||||
message (if deleted (str (:del-user-success (util/get-messages request)) " " target "."))
|
||||
error (if (not deleted) (str (:del-user-fail (util/get-messages request)) " " target "."))]
|
||||
(layout/render "edit-users.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (:edit-users-title util/config)
|
||||
{:title (:edit-users-title (util/get-messages request))
|
||||
:message message
|
||||
:error error
|
||||
:users (auth/list-users)}))))
|
||||
|
|
@ -67,9 +67,9 @@
|
|||
password (if (and pass1 (auth/evaluate-password pass1 (:pass2 params))) pass1)
|
||||
stored (if (:email params)
|
||||
(auth/add-user target password (:email params) (:admin params)))
|
||||
message (if stored (str (:save-user-success util/config) " " target "."))
|
||||
message (if stored (str (:save-user-success (util/get-messages request)) " " target "."))
|
||||
error (if (and (:email params) (not stored))
|
||||
(str (:save-user-fail util/config) " " target "."))
|
||||
(str (:save-user-fail (util/get-messages request)) " " target "."))
|
||||
details (auth/fetch-user-details target)]
|
||||
(if message
|
||||
(timbre/info message))
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
(timbre/warn error))
|
||||
(layout/render "edit-user.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (str (:edit-title-prefix util/config) " " target)
|
||||
{:title (str (:edit-title-prefix (util/get-messages request)) " " target)
|
||||
:message message
|
||||
:error error
|
||||
:target target
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
(defn process-source
|
||||
"Process `source-text` and save it to the specified `file-path`, committing it
|
||||
to Git and finally redirecting to wiki-page."
|
||||
[params suffix]
|
||||
[params suffix request]
|
||||
(let [source-text (:src params)
|
||||
page (:page params)
|
||||
file-name (str page suffix)
|
||||
|
|
@ -77,14 +77,14 @@
|
|||
(if
|
||||
(= suffix ".md")
|
||||
(url-encode page)
|
||||
(:default-page-title util/config))))))
|
||||
(util/get-message :default-page-title request))))))
|
||||
|
||||
|
||||
(defn edit-page
|
||||
"Render a page in a text-area for editing. This could have been done in the same function as wiki-page,
|
||||
and that would have been neat, but I couldn't see how to establish security if that were done."
|
||||
([request]
|
||||
(edit-page request (:default-page-title util/config) ".md" "edit.html" "/content/_edit-side-bar.md"))
|
||||
(edit-page request (util/get-message :default-page-title request) ".md" "edit.html" "/content/_edit-side-bar.md"))
|
||||
([request default suffix template side-bar]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
src-text (:src params)
|
||||
|
|
@ -95,11 +95,11 @@
|
|||
(if (not exists?)
|
||||
(timbre/info (format "File '%s' not found; creating a new file" file-path))
|
||||
(timbre/info (format "Opening '%s' for editing" file-path)))
|
||||
(cond src-text (process-source params suffix)
|
||||
(cond src-text (process-source params suffix request)
|
||||
true
|
||||
(layout/render template
|
||||
(merge (util/standard-params request)
|
||||
{:title (str (:edit-title-prefix util/config) " " page)
|
||||
{:title (str (util/get-message :edit-title-prefix request) " " page)
|
||||
:page page
|
||||
:side-bar (md->html (io/slurp-resource side-bar))
|
||||
:content (if exists? (io/slurp-resource (str "/content/" page suffix)) "")
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
[request]
|
||||
(timbre/debug (str "Request map: " request))
|
||||
(let [params (keywordize-keys (:params request))
|
||||
page (or (:page params) (:default-page-title util/config))
|
||||
page (or (:page params) (util/get-message :default-page-title request))
|
||||
file-name (str "/content/" page ".md")
|
||||
file-path (str (io/resource-path) file-name)
|
||||
exists? (.exists (clojure.java.io/as-file file-path))]
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
if any. If none, error?"
|
||||
[request]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
page (url-decode (or (:page params) (:default-page-title util/config)))
|
||||
page (url-decode (or (:page params) (util/get-message :default-page-title request)))
|
||||
file-name (str page ".md")
|
||||
repo-path (str (io/resource-path) "/content/")]
|
||||
(timbre/info (format "Showing history of page '%s'" page))
|
||||
|
|
@ -157,7 +157,7 @@
|
|||
uploaded (if upload (ul/store-upload params))]
|
||||
(layout/render "upload.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (:file-upload-title util/config)
|
||||
{:title (util/get-message :file-upload-title request)
|
||||
:uploaded uploaded
|
||||
:is-image (and
|
||||
uploaded
|
||||
|
|
@ -175,7 +175,7 @@
|
|||
"Render a specific historical version of a page"
|
||||
[request]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
page (url-decode (or (:page params) (:default-page-title util/config)))
|
||||
page (url-decode (or (:page params) (util/get-message :default-page-title request)))
|
||||
version (:version params)
|
||||
file-name (str page ".md")
|
||||
repo-path (str (io/resource-path) "/content/")
|
||||
|
|
@ -183,7 +183,7 @@
|
|||
(timbre/info (format "Showing version '%s' of page '%s'" version page))
|
||||
(layout/render "wiki.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (str (:vers-col-hdr util/config) " " version " of " page)
|
||||
{:title (str (util/get-message :vers-col-hdr request) " " version " of " page)
|
||||
:page page
|
||||
:content (md->html content)}))))
|
||||
|
||||
|
|
@ -192,14 +192,14 @@
|
|||
"Render a diff between two versions of a page"
|
||||
[request]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
page (url-decode (or (:page params) (:default-page-title util/config)))
|
||||
page (url-decode (or (:page params) (util/get-message :default-page-title request)))
|
||||
version (:version params)
|
||||
file-name (str page ".md")
|
||||
repo-path (str (io/resource-path) "/content/")]
|
||||
(timbre/info (format "Showing diff between version '%s' of page '%s' and current" version page))
|
||||
(layout/render "wiki.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (str (:diff-title-prefix util/config)" " version " of " page)
|
||||
{:title (str (util/get-message :diff-title-prefix request)" " version " of " page)
|
||||
:page page
|
||||
:content (d2h/diff2html (hist/diff repo-path file-name version))}))))
|
||||
|
||||
|
|
@ -214,7 +214,7 @@
|
|||
user (session/get :user)
|
||||
redirect-to (or (:redirect-to params) "/wiki")]
|
||||
(cond
|
||||
(= action (:logout-label util/config))
|
||||
(= action (util/get-message :logout-label request))
|
||||
(do
|
||||
(timbre/info (str "User " user " logging out"))
|
||||
(session/remove! :user)
|
||||
|
|
@ -226,7 +226,7 @@
|
|||
true
|
||||
(layout/render "auth.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (if user (str (:logout-link util/config) " " user) (:login-link util/config))
|
||||
{:title (if user (str (util/get-message :logout-link request) " " user) (util/get-message :login-link request))
|
||||
:redirect-to ((:headers request) "referer")})))))
|
||||
|
||||
|
||||
|
|
@ -243,14 +243,14 @@
|
|||
(auth/change-pass user oldpass pass2))]
|
||||
(layout/render "passwd.html"
|
||||
(merge (util/standard-params request)
|
||||
{:title (str (:chpass-title-prefix util/config) " " user)
|
||||
:message (if changed? (:chpass-success util/config))
|
||||
{:title (str (util/get-message :chpass-title-prefix request) " " user)
|
||||
:message (if changed? (util/get-message :chpass-success request))
|
||||
:error (cond
|
||||
(nil? oldpass) nil
|
||||
changed? nil
|
||||
(< (count pass1) 8) (:chpass-too-short util/config)
|
||||
(not (= pass1 pass2)) (:chpass-bad-match util/config)
|
||||
true (:chpass-fail util/config))}))))
|
||||
(< (count pass1) 8) (util/get-message :chpass-too-short request)
|
||||
(not (= pass1 pass2)) (util/get-message :chpass-bad-match request)
|
||||
true (util/get-message :chpass-fail request))}))))
|
||||
|
||||
|
||||
(defroutes wiki-routes
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
smeagol.util
|
||||
(:require [noir.session :as session]
|
||||
[noir.io :as io]
|
||||
[scot.weft.i18n.core :as i18n]
|
||||
[taoensso.timbre :as timbre]
|
||||
[smeagol.authenticate :as auth]
|
||||
[smeagol.formatting :refer [md->html]]))
|
||||
|
||||
|
|
@ -47,3 +49,26 @@
|
|||
:header (md->html (io/slurp-resource "/content/_header.md"))
|
||||
:version (System/getProperty "smeagol.version")}))
|
||||
|
||||
|
||||
(defn raw-get-messages
|
||||
"Return the most acceptable messages collection we have given the
|
||||
`Accept-Language` header in this `request`."
|
||||
[request]
|
||||
(merge
|
||||
(i18n/get-messages
|
||||
((:headers request) "accept-language")
|
||||
(str (io/resource-path) "../i18n")
|
||||
"en-GB")
|
||||
config))
|
||||
|
||||
|
||||
(def get-messages (memoize raw-get-messages))
|
||||
|
||||
(defn get-message
|
||||
[message-key request]
|
||||
(let [messages (get-messages request)]
|
||||
(if
|
||||
(map? messages)
|
||||
(or (messages message-key) message-key)
|
||||
message-key)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue