Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ORCH-1232) Add a standard function for marking strings for extraction #18

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -81,6 +81,13 @@ patterns and need to be escaped with another single quote:
;; The following will produce "He's going to the store"
(trs "He''s going to the store")

### Separating message extraction from translation

In some cases, messages need to be generated separately from when they're
translated; this is common in specialized `def` forms or when defining a
constant for reuse. In that case, use the `mark` macro to mark strings for
xgettext extraction, and the standard `trs`/`tru` at the translation site.

### Development tools

Extracting messages and building ResourceBundles requires the command line tools
Expand Down
15 changes: 11 additions & 4 deletions locales/de.po
Expand Up @@ -17,21 +17,28 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: src/puppetlabs/i18n/main.clj:6
msgid "I do not speak German"
msgstr "Ich spreche kein Deutsch"

#. Very simple localization
#: src/puppetlabs/i18n/main.clj:18
#: src/puppetlabs/i18n/main.clj:21
msgid "Welcome! This is localized"
msgstr "Willkommen ! Draußen nur Kännchen"

#: src/puppetlabs/i18n/main.clj:22
#: src/puppetlabs/i18n/main.clj:28
msgid "There is one bottle of beer on the wall."
msgid_plural "There are {0} bottles of beer on the wall."
msgstr[0] "Es gibt eine Flasche Bier an der Wand."
msgstr[1] "Es gibt {0} Flaschen Bier an der Wand."

#: src/puppetlabs/i18n/main.clj:29
#: src/puppetlabs/i18n/main.clj:35
msgid "It took {0} programmers {1} months to implement this"
msgstr "{0} Programmierer brauchten {1} Monat(e) um das zu implementieren"

#: src/puppetlabs/i18n/main.clj:34
#: src/puppetlabs/i18n/main.clj:40
msgid "There are {0,number,integer} bicycles in Beijing"
msgstr "In Peking gibt es {0,number,integer} Fahrräder"

#~ msgid "This is another test string"
#~ msgstr "german german german german german"
12 changes: 8 additions & 4 deletions locales/messages.pot
Expand Up @@ -18,21 +18,25 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: src/puppetlabs/i18n/main.clj:6
msgid "I do not speak German"
msgstr ""

#. Very simple localization
#: src/puppetlabs/i18n/main.clj:18
#: src/puppetlabs/i18n/main.clj:21
msgid "Welcome! This is localized"
msgstr ""

#: src/puppetlabs/i18n/main.clj:22
#: src/puppetlabs/i18n/main.clj:28
msgid "There is one bottle of beer on the wall."
msgid_plural "There are {0} bottles of beer on the wall."
msgstr[0] ""
msgstr[1] ""

#: src/puppetlabs/i18n/main.clj:29
#: src/puppetlabs/i18n/main.clj:35
msgid "It took {0} programmers {1} months to implement this"
msgstr ""

#: src/puppetlabs/i18n/main.clj:34
#: src/puppetlabs/i18n/main.clj:40
msgid "There are {0,number,integer} bicycles in Beijing"
msgstr ""
1 change: 1 addition & 0 deletions src/leiningen/i18n/Makefile
Expand Up @@ -45,6 +45,7 @@ locales/messages.pot: $(shell $(FIND_SOURCES)) | locales
--msgid-bugs-address "docs@puppet.com" \
-ktrs:1 -ki18n/trs:1 \
-ktru:1 -ki18n/tru:1 \
-kmark:1 -ki18n/mark:1 \
-ktrun:1,2 -ki18n/trun:1,2 \
-ktrsn:1,2 -ki18n/trsn:1,2 \
--add-comments -o $tmp -f -; \
Expand Down
4 changes: 4 additions & 0 deletions src/puppetlabs/i18n/core.clj
Expand Up @@ -256,6 +256,10 @@
[& args]
`(translate-plural ~(namespace-munge *ns*) (system-locale) ~@args))

;; Mark a message for extraction, without translation. This is useful when
;; strings are defined at compile time but need to be translated at run time.
(def mark identity)

;;
;; Ring middleware for language negotiation
;;
Expand Down
7 changes: 6 additions & 1 deletion src/puppetlabs/i18n/main.clj
@@ -1,7 +1,9 @@
(ns puppetlabs.i18n.main
"Some I18N examples"
(:gen-class)
(:require [puppetlabs.i18n.core :as i18n :refer [tru trs trsn]]))
(:require [puppetlabs.i18n.core :as i18n :refer [tru trs trsn mark]]))

(def ^:const const-string (mark "I do not speak German"))

;; Some simple examples of using tru/trs
;; The unit tests rely on the message catalog and translation generated for
Expand All @@ -17,6 +19,9 @@
;; Very simple localization
(println (trs "Welcome! This is localized"))

;; Localizing a previously-extracted string
(println (tru const-string))

;; Very simple plural system localization
(doseq [beers (range 5 0 -1)]
(println (trsn "There is one bottle of beer on the wall."
Expand Down