Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:19:00+00:00 2026-05-27T01:19:00+00:00

Following this blog article I enabled my application to load i18n messages from the

  • 0

Following this blog article I enabled my application to load i18n messages from the database. It works great. However, I don’t want to manage all messages in the database. So I’d like to be able to say if I don’t find the code in the database, then load it using the default mechanism.

Here is what I have:

class DatabaseMessageSource extends AbstractMessageSource {
  protected MessageFormat resolveCode(String code, Locale locale) {
    Message msg = Message.findByCodeAndLocale(code, locale)
    def format = null
    if (msg) {
      format = new MessageFormat(msg.text, msg.locale)
    }else{
      // What do I do here to grab it from the file
    }
    return format;
  }
}

I tried calling super.resolveCode(code, locale) but that resulted in compile errors. And I’m having a hard time tracking down the implementation of AbstractMessageSource that Grails is using by default to look at the source.

UPDATE: Thanks to doelleri I now realize what I need to do is something like extending the ResourceBundleMessageSource. Unfortunately, there are several issues with this approach. I have the following in my resources.groovy file:

messageSource(DatabaseMessageSource)

First of all, if I simply extend ResourceBundleMessageSource and override the resolveCode method, that method never gets called. So in my else block, calling super.resolveCode is moot.

I then attempted to just implement my DatabaseMessageSource class with all the code from ResourceBundleMessageSource but I’m apparently missing something in resources.groovy because the default bundles aren’t getting wired up.

So at this point, I’m still lost on what I need to do. I want to first check the database. If the code doesn’t exist, revert to the same default behavior as ResourceBundleMessageSource.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:19:00+00:00Added an answer on May 27, 2026 at 1:19 am

    I would propose to keep one bundle-message-source in a new bean and inject it into your DatabaseMessageSource.

    resources.groovy:

    // Place your Spring DSL code here
    beans = {
        messageSource(DatabaseMessageSource) {
            messageBundleMessageSource = ref("messageBundleMessageSource")
        }    
        messageBundleMessageSource(org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource) {
            basenames = "WEB-INF/grails-app/i18n/messages"
        }
    }
    

    DatabaseMessageSource.groovy:

    class DatabaseMessageSource extends AbstractMessageSource {
    
        def messageBundleMessageSource
    
        protected MessageFormat resolveCode(String code, Locale locale) {
             Message msg = Message.findByCodeAndLocale(code, locale)
             def format
             if(msg) {
                 format = new MessageFormat(msg.text, msg.locale)
             }
             else {
                 format = messageBundleMessageSource.resolveCode(code, locale)
             }
             return format;
        }
    }
    

    This way, in fallback solution, the message will be read from the appropriate messages_*.properties file, by just requesting it from one resource bundle message source. Note that you should use the PluginAwareResourceBundleMessageSource, otherwise you could miss some important messages from your plugins.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jokes.db database. This database file imported from using this article., http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ .
I am following this article: http://www.lunametrics.com/blog/2011/12/01/automatic-cross-domain-tracking-revisited/ which leads me to put the following in
I'm following this example: http://www.codinghorror.com/blog/2005/12/getting-started-with-indexing-service.html However, the conversion to dataset shows empty columns for
I'm following the instructions on using xsi:type from this oft-cited blog post: http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html Basically
I have the following regex: RewriteRule ^blogs/([^/]*)/([^/]*) blogs/index.php?blogger=$1&blog=$2 This works fine for the following
I am following the music application article on Yarivs blog . When I go
I have following this blog in setting Xvfb in my ubuntu environment: http://corpocrat.com/2008/08/19/how-to-install-xvfb-x11-server-in-linux-server/ So
http://www.codinghorror.com/blog/2008/04/setting-up-subversion-on-windows.html I am following this as a guide to install subversion. The tutorial at
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I'm trying to reproduce the heatmap presented on this blog by following their tutorial,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.