org.grails.plugins.i18n.I18nGrailsPlugin.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grace-plugin-i18n Show documentation
Show all versions of grace-plugin-i18n Show documentation
Grace Framework : Grace Plugin I18n
/*
* Copyright 2004-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.grails.plugins.i18n
import java.nio.file.Files
import groovy.util.logging.Slf4j
import org.springframework.core.PriorityOrdered
import org.springframework.core.io.Resource
import grails.plugins.Plugin
import grails.util.BuildSettings
import grails.util.GrailsUtil
import org.grails.spring.context.support.ReloadableResourceBundleMessageSource
/**
* Configures Grails' internationalisation support.
*
* @author Graeme Rocher
* @author Michael Yan
* @since 0.4
*/
@Slf4j
class I18nGrailsPlugin extends Plugin implements PriorityOrdered {
String version = GrailsUtil.getGrailsVersion()
def watchedResources = ['file:./grails-app/i18n/**/*.properties',
'file:./app/i18n/**/*.properties']
@Override
Closure doWithSpring() {
{ ->
}
}
@Override
void doWithDynamicMethods() {
String.metaClass.getMessage = { ->
def messageSource = applicationContext.messageSource
messageSource.getMessage(delegate, null, Locale.ENGLISH)
}
String.metaClass.message = { String lang ->
def locale = Locale.forLanguageTag(lang.replace('_', '-'))
def messageSource = applicationContext.messageSource
messageSource.getMessage(delegate, null, locale)
}
String.metaClass.message = { List