Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/graphql/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private String msgImpl(String msgKey, Object[] msgArgs) {
} catch (MissingResourceException e) {
assertShouldNeverHappen("There must be a resource bundle key called %s", msgKey);
}
return new MessageFormat(msgPattern).format(msgArgs);
// format any arguments (eg numbers) with the same locale as the message rather than the JVM default locale
return new MessageFormat(msgPattern, locale).format(msgArgs);
}
}
19 changes: 19 additions & 0 deletions src/test/groovy/graphql/i18n/I18nTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ class I18nTest extends Specification {
message == "Validierungsfehler ({0}) : Type definition '{1}' ist nicht ausführbar"
}

def "message arguments are formatted with the message locale not the JVM default locale"() {
// Slovenian formats -1 with a unicode minus sign and groups thousands with a dot
def originalDefault = Locale.getDefault()
def originalFormatDefault = Locale.getDefault(Locale.Category.FORMAT)
Locale.setDefault(Locale.forLanguageTag("sl-SI"))

when:
def englishMessage = I18n.i18n(BundleType.Parsing, Locale.ENGLISH).msg("InvalidSyntaxMoreTokens.noMessage", -1, 1234)
def germanMessage = I18n.i18n(BundleType.Parsing, Locale.GERMAN).msg("InvalidSyntaxMoreTokens.noMessage", -1, 1234)

then:
englishMessage.endsWith("Offending token at line -1 column 1,234")
germanMessage.endsWith("Ungültiges Token in Zeile -1 Spalte 1.234")

cleanup:
Locale.setDefault(originalDefault)
Locale.setDefault(Locale.Category.FORMAT, originalFormatDefault)
}

def "integration test of valid messages"() {
def sdl = """
type Query {
Expand Down