I want to generate some localized html files as part of my build and deployment. As a simple test, I tried this task
task i18n(description:“i18n test”) << {
def locales = [Locale.ENGLISH, Locale.JAPANESE, Locale.GERMAN]
def keys = [ “s1”, “s2”, “s3” ]
[locales, keys].combinations().each{ locale, key ->
def labels = ResourceBundle.getBundle(‘html’, locale)
println “Locale = ${locale.toString()}, key = $key, value = ${labels.getString(key)}”
} }
But it says Can’t find bundle for base name html, locale en_US. I put the resource bundles in the same directory as the build.gradle file (html.properties, html_en.properties, etc). However, it seems that gradle does not try to load the resource bundles from that directory, but rather tries to get them from the gradle classLoader. I’m not sure where that might be, but it is probably outside of source control. Is there a convenient way to get localized messages from property files from within the gradle build script?