From bcd064629d31a07e07641e11d09979674269e0aa Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 1 Apr 2012 22:07:26 +0200 Subject: [PATCH] Locale provided in args is now taken into account when rendering. --- grails-app/i18n/messages_fr.properties | 1 + .../rendering/document/XhtmlDocumentService.groovy | 2 +- grails-app/views/_simple.gsp | 1 + .../plugin/rendering/RenderingServiceSpec.groovy | 4 ++-- .../rendering/pdf/PdfRenderingServiceSpec.groovy | 10 ++++++++++ 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 grails-app/i18n/messages_fr.properties diff --git a/grails-app/i18n/messages_fr.properties b/grails-app/i18n/messages_fr.properties new file mode 100644 index 0000000..4d826a3 --- /dev/null +++ b/grails-app/i18n/messages_fr.properties @@ -0,0 +1 @@ +label = french \ No newline at end of file diff --git a/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy b/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy index 5bdaf92..b02750f 100644 --- a/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy +++ b/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy @@ -65,7 +65,7 @@ class XhtmlDocumentService { protected generateXhtml(Map args) { def xhtmlWriter = new StringWriter() - RenderEnvironment.with(grailsApplication.mainContext, xhtmlWriter) { + RenderEnvironment.with(grailsApplication.mainContext, xhtmlWriter, args.locale) { createTemplate(args).make(args.model).writeTo(xhtmlWriter) } diff --git a/grails-app/views/_simple.gsp b/grails-app/views/_simple.gsp index 95352cb..0566766 100644 --- a/grails-app/views/_simple.gsp +++ b/grails-app/views/_simple.gsp @@ -19,5 +19,6 @@

This is a PDF!

${var}

+

Locale specific content: ${message(code: 'label')}

\ No newline at end of file diff --git a/test/integration/grails/plugin/rendering/RenderingServiceSpec.groovy b/test/integration/grails/plugin/rendering/RenderingServiceSpec.groovy index 3486e9e..a17d41f 100644 --- a/test/integration/grails/plugin/rendering/RenderingServiceSpec.groovy +++ b/test/integration/grails/plugin/rendering/RenderingServiceSpec.groovy @@ -42,7 +42,7 @@ abstract class RenderingServiceSpec extends IntegrationSpec { then: notThrown(Exception) } - + def renderTemplateInPlugin() { when: renderer.render(pluginTemplate) @@ -63,7 +63,7 @@ abstract class RenderingServiceSpec extends IntegrationSpec { then: thrown(UnknownTemplateException) } - + def renderToResponse() { given: diff --git a/test/integration/grails/plugin/rendering/pdf/PdfRenderingServiceSpec.groovy b/test/integration/grails/plugin/rendering/pdf/PdfRenderingServiceSpec.groovy index a542996..02af473 100644 --- a/test/integration/grails/plugin/rendering/pdf/PdfRenderingServiceSpec.groovy +++ b/test/integration/grails/plugin/rendering/pdf/PdfRenderingServiceSpec.groovy @@ -32,6 +32,16 @@ class PdfRenderingServiceSpec extends RenderingServiceSpec { def getRenderer() { pdfRenderingService } + + def renderWithLocaleArgument(){ + given: + def response = createMockResponse() + when: + renderer.render(getSimpleTemplate([locale: Locale.FRENCH]), response) + def matcher = new PDFTextStripper().getText(PDDocument.load(new ByteArrayInputStream(response.contentAsByteArray))) =~ /french/ + then: + matcher.size() == 1 + } protected extractTextLines(Map renderArgs) { extractTextLines(createPdf(renderArgs))