You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Vikram Reddy <vi...@gmail.com> on 2007/05/03 14:38:35 UTC

I18N Tag Library

Did any one use I18N Tag Library from Apache,  I have a question on that.

I have some of the labels hardcoded in the java bean whcih are displayed on
the UI, not sure how I can convert them, Can any one throw some light on
this please.. I would really appreciate that.
in my jsp page, I am simply using this tag : <i18n:message key="label.name"
/> ..

- V

Re: I18N Tag Library

Posted by Vikram Reddy <vi...@gmail.com>.
I have very labels which are displayed on the UI and they are set in my java
code (back end bean), not sure how to make those labels i18n complaint..

On 5/3/07, José Navas <jn...@gmail.com> wrote:
>
> Sorry, you are right.
>
> The message tag in i18n does the same thing.
>
> What is that you want to do? Is it to avoid the string "label.name" in
> the code? Or is it know how to create the bundles for each language?
>
>
>
> On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> >
> > I am not using jstl taglib, I am using i18n tag library from jakartha
> ....
> >
> > On 5/3/07, José Navas <jn...@gmail.com> wrote:
> > >
> > > Do you mean internationalize them?
> > >
> > > If this is the case, one way to do it may be using resource files for
> > the
> > > labels
> > > in your bean (one resource file per language), and use the tag message
> > > from
> > > the fmt jstl taglib.
> > >
> > > Hope this helps
> > > Navas
> > >
> > > On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> > > >
> > > > Did any one use I18N Tag Library from Apache,  I have a question on
> > > that.
> > > >
> > > > I have some of the labels hardcoded in the java bean whcih are
> > displayed
> > > > on
> > > > the UI, not sure how I can convert them, Can any one throw some
> light
> > on
> > > > this please.. I would really appreciate that.
> > > > in my jsp page, I am simply using this tag : <i18n:message key="
> > > label.name
> > > > "
> > > > /> ..
> > > >
> > > > - V
> > > >
> > >
> >
>

Re: I18N Tag Library

Posted by José Navas <jn...@gmail.com>.
Sorry, you are right.

The message tag in i18n does the same thing.

What is that you want to do? Is it to avoid the string "label.name" in
the code? Or is it know how to create the bundles for each language?



On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
>
> I am not using jstl taglib, I am using i18n tag library from jakartha ....
>
> On 5/3/07, José Navas <jn...@gmail.com> wrote:
> >
> > Do you mean internationalize them?
> >
> > If this is the case, one way to do it may be using resource files for
> the
> > labels
> > in your bean (one resource file per language), and use the tag message
> > from
> > the fmt jstl taglib.
> >
> > Hope this helps
> > Navas
> >
> > On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> > >
> > > Did any one use I18N Tag Library from Apache,  I have a question on
> > that.
> > >
> > > I have some of the labels hardcoded in the java bean whcih are
> displayed
> > > on
> > > the UI, not sure how I can convert them, Can any one throw some light
> on
> > > this please.. I would really appreciate that.
> > > in my jsp page, I am simply using this tag : <i18n:message key="
> > label.name
> > > "
> > > /> ..
> > >
> > > - V
> > >
> >
>

Re: I18N Tag Library

Posted by Vikram Reddy <vi...@gmail.com>.
I am not using jstl taglib, I am using i18n tag library from jakartha ....

On 5/3/07, José Navas <jn...@gmail.com> wrote:
>
> Do you mean internationalize them?
>
> If this is the case, one way to do it may be using resource files for the
> labels
> in your bean (one resource file per language), and use the tag message
> from
> the fmt jstl taglib.
>
> Hope this helps
> Navas
>
> On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> >
> > Did any one use I18N Tag Library from Apache,  I have a question on
> that.
> >
> > I have some of the labels hardcoded in the java bean whcih are displayed
> > on
> > the UI, not sure how I can convert them, Can any one throw some light on
> > this please.. I would really appreciate that.
> > in my jsp page, I am simply using this tag : <i18n:message key="
> label.name
> > "
> > /> ..
> >
> > - V
> >
>

Re: I18N Tag Library

Posted by José Navas <jn...@gmail.com>.
Do you mean internationalize them?

If this is the case, one way to do it may be using resource files for the
labels
in your bean (one resource file per language), and use the tag message from
the fmt jstl taglib.

Hope this helps
Navas

On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
>
> Did any one use I18N Tag Library from Apache,  I have a question on that.
>
> I have some of the labels hardcoded in the java bean whcih are displayed
> on
> the UI, not sure how I can convert them, Can any one throw some light on
> this please.. I would really appreciate that.
> in my jsp page, I am simply using this tag : <i18n:message key="label.name
> "
> /> ..
>
> - V
>

Re: I18N Tag Library

Posted by José Navas <jn...@gmail.com>.
If what you are trying to do is read the resources file, you can use this
class

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package net.bac.com.cbk.common.util;

import java.io.InputStream;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

/** @modelguid {ABE1E037-8252-4018-A711-8DD57641A3A0} */
public abstract class PropertyLoader
{
    /**
     * Looks up a resource named 'name' in the classpath. The resource must
map
     * to a file with .properties extention. The name is assumed to be
absolute
     * and can use either "/" or "." for package segment separation with an
     * optional leading "/" and optional ".properties" suffix. Thus, the
     * following names refer to the same resource:
     * <pre>
     * some.pkg.Resource
     * some.pkg.Resource.properties
     * some/pkg/Resource
     * some/pkg/Resource.properties
     * /some/pkg/Resource
     * /some/pkg/Resource.properties
     * </pre>
     *
     * @param name classpath resource name [may not be null]
     * @param loader classloader through which to load the resource [null
     * is equivalent to the application loader]
     *
     * @return resource converted to java.util.Properties [may be null if
the
     * resource was not found and THROW_ON_LOAD_FAILURE is false]
     * @throws IllegalArgumentException if the resource was not found and
     * THROW_ON_LOAD_FAILURE is true
     * @modelguid {1156E969-3D21-490F-A08D-D9F7524E3A91}
     */
    public static Properties loadProperties (String name, ClassLoader
loader)
    {
        if (name == null)
            throw new IllegalArgumentException ("null input: name");

        if (name.startsWith ("/"))
            name = name.substring (1);

        if (name.endsWith (SUFFIX))
            name = name.substring (0, name.length () - SUFFIX.length ());

        Properties result = null;

        InputStream in = null;
        try
        {
            if (loader == null) loader = ClassLoader.getSystemClassLoader();

            if (LOAD_AS_RESOURCE_BUNDLE)
            {
                name = name.replace ('/', '.');
                // Throws MissingResourceException on lookup failures:
                final ResourceBundle rb = ResourceBundle.getBundle (name,
                    Locale.getDefault (), loader);

                result = new Properties ();
                for (Enumeration keys = rb.getKeys (); keys.hasMoreElements();)
                {
                    final String key = (String) keys.nextElement ();
                    final String value = rb.getString (key);

                    result.put (key, value);
                }
            }
            else
            {
                name = name.replace ('.', '/');

                if (! name.endsWith (SUFFIX)) {
                    name = name.concat (SUFFIX);
                }

                // Returns null on lookup failures:
                in = loader.getResourceAsStream (name);
                if (in != null)
                {
                    result = new Properties ();
                    result.load (in); // Can throw IOException
                }
            }
        }
        catch (Exception e)
        {
            result = null;
        }
        finally
        {
            if (in != null) try { in.close (); } catch (Throwable ignore) {}
        }

        if (THROW_ON_LOAD_FAILURE && (result == null))
        {
            throw new IllegalArgumentException ("could not load [" + name +
"]"+
                " as " + (LOAD_AS_RESOURCE_BUNDLE
                ? "a resource bundle"
                : "a classloader resource"));
        }

        return result;
    }

    /**
     * A convenience overload of {@link #loadProperties(String,
ClassLoader)}
     * that uses the current thread's context classloader.
     * @modelguid {B449C763-826B-4D7E-AC76-5E5CE9DF2C5D}
     */
    public static Properties loadProperties (final String name)
    {
        return loadProperties (name,
            Thread.currentThread ().getContextClassLoader ());
    }

    /** @modelguid {8C0F147E-6C55-4051-A646-E5772906A475} */
    private static final boolean THROW_ON_LOAD_FAILURE = true;
    /** @modelguid {D57C850C-12BB-4B4A-98F5-84BBDC3F4069} */
    private static final boolean LOAD_AS_RESOURCE_BUNDLE = false;
    /** @modelguid {D238B664-59AF-4954-A4A9-B0729280FA50} */
    private static final String SUFFIX = ".properties";
} // End of class

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Hope this helps
Navas

On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
>
> Sure, I am making my application I18n complinat, reading all the labels
> from
> the resources, I am using I18n tag libary from jakartha,
>
> I am replacing all of my labels with i18n tag like <i18n:message key="
> label.name">, <i18n:message key="label.age"> etc, it is working fine.
>
> But I have some labels which are hardcoded in the Backend (Java file) and
> and they are displayed on the UI I am struck how to use this tag in the
> back
> end java class.
>
> I read the documennation, nothing was mentioned about this. let me know if
> you have any questions.
>
> V
>
>
>
>
>
> On 5/3/07, Rashmi Rubdi <ra...@gmail.com> wrote:
> >
> > On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> > > Did any one use I18N Tag Library from Apache,  I have a question on
> > that.
> > >
> > > I have some of the labels hardcoded in the java bean whcih are
> displayed
> > on
> > > the UI, not sure how I can convert them, Can any one throw some light
> on
> >
> > The description  of the problem is a little vague, it would help to
> > know adequate relevant details.
> >
> > The documentation on the taglibs and examples in i18n-examples.war
> > might have some solutions
> >
> > > this please.. I would really appreciate that.
> > > in my jsp page, I am simply using this tag : <i18n:message key="
> > label.name"
> > > /> ..
> > >
> > > - V
> > >
> >
> > -Regards
> > Rashmi
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> >
> >
>

Re: I18N Tag Library

Posted by Vikram Reddy <vi...@gmail.com>.
I got it working, thanks guys for all your responses ..

On 5/3/07, Rashmi Rubdi <ra...@gmail.com> wrote:
>
> On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> > Sure, I am making my application I18n complinat, reading all the labels
> from
> > the resources, I am using I18n tag libary from jakartha,
> >
> > I am replacing all of my labels with i18n tag like <i18n:message key="
> > label.name">, <i18n:message key="label.age"> etc, it is working fine.
> >
> > But I have some labels which are hardcoded in the Backend (Java file)
> and
> > and they are displayed on the UI I am struck how to use this tag in the
> back
> > end java class.
>
> Ok, now the problem is a little clear to me. It would be more clear if
> you could illustrate with sample code. It is difficult to know what's
> the problem without all the information.
>
> From what I know, tag libs are only meant to be used on JSP or other
> front end technologies, they cannot be used directly inside Java
> classes.
>
> If you want to access data from Backend or middle application layer
> into the JSP then it can be done with the jsp:useBean and
> jsp:getProperty tag, as long as the Java class is a valid JavaBean
> that means it should follow the JavaBean notation strictly.
>
> You would use the MVC/ Front Controller pattern which uses Servlets to
> control JSPs, inside the JSP get the JavaBean from request scope.
>
> > I read the documennation, nothing was mentioned about this. let me know
> if
> > you have any questions.
>
> The documentation only covers JSPs/ Front end as it should.
>
> >
> > V
>
> Regards
> Rashmi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>

Re: I18N Tag Library

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> Sure, I am making my application I18n complinat, reading all the labels from
> the resources, I am using I18n tag libary from jakartha,
>
> I am replacing all of my labels with i18n tag like <i18n:message key="
> label.name">, <i18n:message key="label.age"> etc, it is working fine.
>
> But I have some labels which are hardcoded in the Backend (Java file) and
> and they are displayed on the UI I am struck how to use this tag in the back
> end java class.

Ok, now the problem is a little clear to me. It would be more clear if
you could illustrate with sample code. It is difficult to know what's
the problem without all the information.

>From what I know, tag libs are only meant to be used on JSP or other
front end technologies, they cannot be used directly inside Java
classes.

If you want to access data from Backend or middle application layer
into the JSP then it can be done with the jsp:useBean and
jsp:getProperty tag, as long as the Java class is a valid JavaBean
that means it should follow the JavaBean notation strictly.

You would use the MVC/ Front Controller pattern which uses Servlets to
control JSPs, inside the JSP get the JavaBean from request scope.

> I read the documennation, nothing was mentioned about this. let me know if
> you have any questions.

The documentation only covers JSPs/ Front end as it should.

>
> V

Regards
Rashmi

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: I18N Tag Library

Posted by Vikram Reddy <vi...@gmail.com>.
Sure, I am making my application I18n complinat, reading all the labels from
the resources, I am using I18n tag libary from jakartha,

I am replacing all of my labels with i18n tag like <i18n:message key="
label.name">, <i18n:message key="label.age"> etc, it is working fine.

But I have some labels which are hardcoded in the Backend (Java file) and
and they are displayed on the UI I am struck how to use this tag in the back
end java class.

I read the documennation, nothing was mentioned about this. let me know if
you have any questions.

V





On 5/3/07, Rashmi Rubdi <ra...@gmail.com> wrote:
>
> On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> > Did any one use I18N Tag Library from Apache,  I have a question on
> that.
> >
> > I have some of the labels hardcoded in the java bean whcih are displayed
> on
> > the UI, not sure how I can convert them, Can any one throw some light on
>
> The description  of the problem is a little vague, it would help to
> know adequate relevant details.
>
> The documentation on the taglibs and examples in i18n-examples.war
> might have some solutions
>
> > this please.. I would really appreciate that.
> > in my jsp page, I am simply using this tag : <i18n:message key="
> label.name"
> > /> ..
> >
> > - V
> >
>
> -Regards
> Rashmi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>

Re: I18N Tag Library

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 5/3/07, Vikram Reddy <vi...@gmail.com> wrote:
> Did any one use I18N Tag Library from Apache,  I have a question on that.
>
> I have some of the labels hardcoded in the java bean whcih are displayed on
> the UI, not sure how I can convert them, Can any one throw some light on

The description  of the problem is a little vague, it would help to
know adequate relevant details.

The documentation on the taglibs and examples in i18n-examples.war
might have some solutions

> this please.. I would really appreciate that.
> in my jsp page, I am simply using this tag : <i18n:message key="label.name"
> /> ..
>
> - V
>

-Regards
Rashmi

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org