Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Groovy leverages Java's I18N features. Here is a Swing example using Dates, Numbers and Locales:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.swing.SwingBuilder import static javax.swing.JFrame.EXIT_ON_CLOSE as EXIT import static java.text.NumberFormat.getNumberInstance as numberFormat import static java.text.DateFormat.getDateInstance as dateFormat import static java.text.DateFormat.FULL def locales = [ new Locale("en", "US"), new Locale("ja","JP"), new Locale("iw","IL"), new Locale("hi","IN"), new Locale("th","TH","TH"), new Locale("de", "DE"), new Locale("es", "ES"), new Locale("zh", "CN"), new Locale("it", "IT") ] def swing = new SwingBuilder() int row = 0 def d = new Date() def frame = swing.frame(title:'Frame', size:[300,300], defaultCloseOperation:EXIT) { tableLayout { locales.each { loc -> tr { td { label(numberFormat(loc).format(++row)) } td { label(loc.toString()) } td { label(loc.getDisplayLanguage(loc)) } td { label(dateFormat(FULL, loc).format(d)) } } } } } frame.pack() frame.show() </pre></td></tr></table> <p>Which should look something like this:<br /> <img class="confluence-embedded-image" src="/download/attachments/231080206/i18n.gif?version=1&modificationDate=1369494870077" data-image-src="/download/attachments/231080206/i18n.gif?version=1&modificationDate=1369494870077" data-linked-resource-id="231376253" data-linked-resource-type="attachment" data-linked-resource-default-alias="i18n.gif" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080206" title="null > i18n.gif"></p> <p>You can also use properties files to capture language strings. Using the <code>LablesBundle.properties</code>, <code>LablesBundle.properties_de</code> and <code>LablesBundle_fr.properties</code> files from <a href="http://java.sun.com/docs/books/tutorial/i18n/resbundle/propfile.html">this</a> tutorial. We can then use this code:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def locales = [Locale.FRENCH, Locale.GERMAN, Locale.ENGLISH] def keys = [ "s1", "s2", "s3", "s4" ] [locales, keys].combinations().each{ loc, key -> def labels = ResourceBundle.getBundle("LabelsBundle", loc) println "Locale = ${loc.toString()}, key = $key, value = ${labels.getString(key)}" } </pre></td></tr></table> <p>To produce this result:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="none" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bm9uZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> Locale = fr, key = s1, value = Ordinateur Locale = de, key = s1, value = Computer Locale = en, key = s1, value = computer Locale = fr, key = s2, value = Disque dur Locale = de, key = s2, value = Platte Locale = en, key = s2, value = disk Locale = fr, key = s3, value = Moniteur Locale = de, key = s3, value = Monitor Locale = en, key = s3, value = monitor Locale = fr, key = s4, value = Clavier Locale = de, key = s4, value = Tastatur Locale = en, key = s4, value = keyboard </pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced