Merge pull request #63 from jpinsonault/server-1556-externalize-strings
(SERVER-1556) Externalize strings
This commit is contained in:
commit
827dd2cfcf
6 changed files with 161 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@ target
|
|||
pom.xml
|
||||
.nrepl-port
|
||||
/.lein*
|
||||
/resources/locales.clj
|
||||
/resources/**/Messages*.class
|
||||
|
|
1
Makefile
Normal file
1
Makefile
Normal file
|
@ -0,0 +1 @@
|
|||
include dev-resources/Makefile.i18n
|
129
dev-resources/Makefile.i18n
Normal file
129
dev-resources/Makefile.i18n
Normal file
|
@ -0,0 +1,129 @@
|
|||
# -*- Makefile -*-
|
||||
# This file was generated by the i18n leiningen plugin
|
||||
# Do not edit this file; it will be overwritten the next time you run
|
||||
# lein i18n init
|
||||
#
|
||||
|
||||
# The locale in which our messages are written, and for which we therefore
|
||||
# have messages without any further effort
|
||||
MESSAGE_LOCALE=en
|
||||
|
||||
# The name of the package into which the translations bundle will be placed
|
||||
BUNDLE=puppetlabs.http_client
|
||||
# The list of names of packages covered by the translation bundle;
|
||||
# by default it contains a single package - the same where the translations
|
||||
# bundle itself is placed - but this can be overridden - preferably in
|
||||
# the top level Makefile
|
||||
PACKAGES?=$(BUNDLE)
|
||||
LOCALES=$(basename $(notdir $(wildcard locales/*.po)))
|
||||
BUNDLE_DIR=$(subst .,/,$(BUNDLE))
|
||||
BUNDLE_FILES=$(patsubst %,resources/$(BUNDLE_DIR)/Messages_%.class,$(MESSAGE_LOCALE) $(LOCALES))
|
||||
FIND_SOURCES=find src -name \*.clj
|
||||
# xgettext before 0.19 does not understand --add-location=file. Even CentOS
|
||||
# 7 ships with an older gettext. We will therefore generate full location
|
||||
# info on those systems, and only file names where xgettext supports it
|
||||
LOC_OPT=$(shell xgettext --add-location=file -f - </dev/null >/dev/null 2>&1 && echo --add-location=file || echo --add-location)
|
||||
|
||||
LOCALES_CLJ=resources/locales.clj
|
||||
define LOCALES_CLJ_CONTENTS
|
||||
{
|
||||
:locales #{$(patsubst %,"%",$(MESSAGE_LOCALE) $(LOCALES))}
|
||||
:packages [$(patsubst %,"%",$(PACKAGES))]
|
||||
:bundle $(patsubst %,"%",$(BUNDLE).Messages)
|
||||
}
|
||||
endef
|
||||
export LOCALES_CLJ_CONTENTS
|
||||
|
||||
|
||||
i18n: update-pot msgfmt
|
||||
|
||||
# Update locales/messages.pot
|
||||
update-pot: locales/messages.pot
|
||||
|
||||
locales/messages.pot: $(shell $(FIND_SOURCES)) | locales
|
||||
@tmp=$$(mktemp $@.tmp.XXXX); \
|
||||
$(FIND_SOURCES) \
|
||||
| xgettext --from-code=UTF-8 --language=lisp \
|
||||
--copyright-holder='Puppet <docs@puppet.com>' \
|
||||
--package-name="$(BUNDLE)" \
|
||||
--package-version="$(BUNDLE_VERSION)" \
|
||||
--msgid-bugs-address="docs@puppet.com" \
|
||||
-k \
|
||||
-kmark:1 -ki18n/mark:1 \
|
||||
-ktrs:1 -ki18n/trs:1 \
|
||||
-ktru:1 -ki18n/tru:1 \
|
||||
-ktrun:1,2 -ki18n/trun:1,2 \
|
||||
-ktrsn:1,2 -ki18n/trsn:1,2 \
|
||||
$(LOC_OPT) \
|
||||
--add-comments --sort-by-file \
|
||||
-o $$tmp -f -; \
|
||||
sed -i.bak -e 's/charset=CHARSET/charset=UTF-8/' $$tmp; \
|
||||
sed -i.bak -e 's/POT-Creation-Date: [^\\]*/POT-Creation-Date: /' $$tmp; \
|
||||
rm -f $$tmp.bak; \
|
||||
if ! diff -q -I POT-Creation-Date $$tmp $@ >/dev/null 2>&1; then \
|
||||
mv $$tmp $@; \
|
||||
else \
|
||||
rm $$tmp; touch $@; \
|
||||
fi
|
||||
|
||||
# Run msgfmt over all .po files to generate Java resource bundles
|
||||
# and create the locales.clj file
|
||||
msgfmt: $(BUNDLE_FILES) $(LOCALES_CLJ)
|
||||
|
||||
# force rebuild of locales.clj if its contents is not the
|
||||
# the desired one
|
||||
ifneq ($(shell cat $(LOCALES_CLJ) 2> /dev/null),$(shell echo '$(subst ','\'',$(LOCALES_CLJ_CONTENTS))'))
|
||||
.PHONY: $(LOCALES_CLJ)
|
||||
endif
|
||||
$(LOCALES_CLJ): | resources
|
||||
@echo "Writing $@"
|
||||
@echo "$$LOCALES_CLJ_CONTENTS" > $@
|
||||
|
||||
resources/$(BUNDLE_DIR)/Messages_%.class: locales/%.po | resources
|
||||
msgfmt --java2 -d resources -r $(BUNDLE).Messages -l $(*F) $<
|
||||
|
||||
resources/$(BUNDLE_DIR)/Messages_$(MESSAGE_LOCALE).class: locales/messages.pot | resources
|
||||
msgfmt --java2 -d resources -r $(BUNDLE).Messages -l $(MESSAGE_LOCALE) $<
|
||||
|
||||
# Translators use this when they update translations; this copies any
|
||||
# changes in the pot file into their language-specific po file
|
||||
locales/%.po: locales/messages.pot
|
||||
@if [ -f $@ ]; then \
|
||||
msgmerge -U $@ $< && touch $@; \
|
||||
else \
|
||||
touch $@ && msginit --no-translator -l $(*F) -o $@ -i $<; \
|
||||
fi
|
||||
|
||||
resources locales:
|
||||
@mkdir $@
|
||||
|
||||
help:
|
||||
$(info $(HELP))
|
||||
@echo
|
||||
|
||||
.PHONY: help
|
||||
|
||||
define HELP
|
||||
This Makefile assists in handling i18n related tasks during development. Files
|
||||
that need to be checked into source control are put into the locales/ directory.
|
||||
They are
|
||||
|
||||
locales/messages.pot - the POT file generated by 'make update-pot'
|
||||
locales/$$LANG.po - the translations for $$LANG
|
||||
|
||||
Only the $$LANG.po files should be edited manually; this is usually done by
|
||||
translators.
|
||||
|
||||
You can use the following targets:
|
||||
|
||||
i18n: refresh all the files in locales/ and recompile resources
|
||||
update-pot: extract strings and update locales/messages.pot
|
||||
locales/LANG.po: refresh or create translations for LANG
|
||||
msgfmt: compile the translations into Java classes; this step is
|
||||
needed to make translations available to the Clojure code
|
||||
and produces Java class files in resources/
|
||||
endef
|
||||
# @todo lutter 2015-04-20: for projects that use libraries with their own
|
||||
# translation, we need to combine all their translations into one big po
|
||||
# file and then run msgfmt over that so that we only have to deal with one
|
||||
# resource bundle
|
22
locales/messages.pot
Normal file
22
locales/messages.pot
Normal file
|
@ -0,0 +1,22 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR Puppet <docs@puppet.com>
|
||||
# This file is distributed under the same license as the puppetlabs.http_client package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: puppetlabs.http_client \n"
|
||||
"Report-Msgid-Bugs-To: docs@puppet.com\n"
|
||||
"POT-Creation-Date: \n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: src/clj/puppetlabs/http/client/async.clj
|
||||
msgid "Unsupported request method: {0}"
|
||||
msgstr ""
|
|
@ -21,7 +21,8 @@
|
|||
[commons-io "2.4"]
|
||||
[io.dropwizard.metrics/metrics-core "3.1.2"]
|
||||
|
||||
[puppetlabs/ssl-utils "0.8.1"]]
|
||||
[puppetlabs/ssl-utils "0.8.1"]
|
||||
[puppetlabs/i18n "0.4.3"]]
|
||||
|
||||
:source-paths ["src/clj"]
|
||||
:java-source-paths ["src/java"]
|
||||
|
@ -51,4 +52,5 @@
|
|||
:lein-release {:scm :git
|
||||
:deploy-via :lein-deploy}
|
||||
|
||||
:plugins [[lein-release "1.0.5" :exclusions [org.clojure/clojure]]])
|
||||
:plugins [[lein-release "1.0.5" :exclusions [org.clojure/clojure]]
|
||||
[puppetlabs/i18n "0.4.3"]])
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
(com.codahale.metrics MetricRegistry))
|
||||
(:require [puppetlabs.http.client.common :as common]
|
||||
[schema.core :as schema]
|
||||
[puppetlabs.http.client.metrics :as metrics])
|
||||
[puppetlabs.http.client.metrics :as metrics]
|
||||
[puppetlabs.i18n.core :refer [trs]])
|
||||
(:refer-clojure :exclude (get)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -98,7 +99,7 @@
|
|||
:post HttpMethod/POST
|
||||
:put HttpMethod/PUT
|
||||
:trace HttpMethod/TRACE
|
||||
(throw (IllegalArgumentException. (format "Unsupported request method: %s" (:method opts))))))
|
||||
(throw (IllegalArgumentException. (trs "Unsupported request method: {0}" (:method opts))))))
|
||||
|
||||
(defn- parse-url
|
||||
[{:keys [url query-params]}]
|
||||
|
|
Loading…
Reference in a new issue