Solr
  1. Solr
  2. SOLR-2035

Add Velocity's ResourceTool to allow for i18n string lookups

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Response Writers
    • Labels:
      None

      Description

      Being able to look up string resources through Java's ResourceBundle facility can be really useful in Velocity templates (through VelocityResponseWriter). Velocity Tools includes a ResourceTool.

      1. SOLR-2035.patch
        3 kB
        Erik Hatcher

        Activity

        Hide
        Erik Hatcher added a comment - - edited

        This patch adds a custom ResourceTool subclass to the Velocity context. A custom subclass is needed in order to wire in SolrResourceLoader's ClassLoader facility.

        After applying this patch, a path needs to be added to SolrResourceLoader via solrconfig.xml, like this:

        <lib path="./conf/velocity"/>
        

        Then in conf/velocity, add a resources_en_US.properties file (or whatever your system default locale is) in the conf/velocity directory, something like this:

        title=English Title
        

        Then in a Velocity template, use:

        $resource.title
        

        See http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/ResourceTool.html for more details on how to use Velocity's ResourceTool.

        NOTE This patch currently only works with the default system locale. There's surely some way to allow configurability of the Locale, though nothing totally trivial jumped out at me on how to do it.

        Show
        Erik Hatcher added a comment - - edited This patch adds a custom ResourceTool subclass to the Velocity context. A custom subclass is needed in order to wire in SolrResourceLoader's ClassLoader facility. After applying this patch, a path needs to be added to SolrResourceLoader via solrconfig.xml, like this: <lib path= "./conf/velocity" /> Then in conf/velocity, add a resources_en_US.properties file (or whatever your system default locale is) in the conf/velocity directory, something like this: title=English Title Then in a Velocity template, use: $resource.title See http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/ResourceTool.html for more details on how to use Velocity's ResourceTool. NOTE This patch currently only works with the default system locale . There's surely some way to allow configurability of the Locale, though nothing totally trivial jumped out at me on how to do it.

          People

          • Assignee:
            Erik Hatcher
            Reporter:
            Erik Hatcher
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development