You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Muthu Velappan <mu...@aspiresys.com> on 2009/12/10 06:53:17 UTC

RE: Localization in struts 2

Hi,

>From your struts.xml, it seems that u added "i18n" interceptor only for
"index" Action and that’s the reason why u get localized text in its result
index.jsp.

If you want this to be applied through out ur entire project, then create a
interceptor stack like this struts.xml and use that as part of your actions

<package name="default" extends="struts-default">
   <interceptors>
            <interceptor-stack name="myI18nStack">
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="basicStack"/>
            </interceptor-stack>
    </interceptors>

<default-interceptor-ref name="myI18nStack"/> 

<action>
....
....
</action>
</package>

Regards,
Muthu

PS: I suggest you to post the message to Struts user group rather than
individual e-mail's. With this, you have a possibility of getting inputs
from larger group rather than specific individual. 

-----Original Message-----
From: saravanan@elogic.co.in [mailto:saravanan@elogic.co.in] 
Sent: Thursday, December 10, 2009 10:34 AM
To: muthu.velappan@aspiresys.com
Subject: RE: Localization in struts 2

Hi Muthu,
 
           I would like to know about Localization in struts 2 with examples
. I tried from sample

code( Strut2i18n) it's working. In my application, Once the user select the
language. it will reflect
in all other jsp. Now it's working.. but need to change in browser settings.


      In action file,
 
request.getSession().setAttribute(org.apache.struts.Globals.LOCALE_KEY, new
java.util.Locale("fr","FR"));

 Struts.xml,

        <action name="index" class="com.kogent.IndexAction">
		<interceptor-ref name="i18n"/>
		<interceptor-ref name="basicStack"/>
			<result name="success">index.jsp</result>
		</action>

    In Index.jsp, 
              	<s:textfield name="username" key="app.username" size="15"
labelposition="top" />

      In other jsp,  I just copied the same code <s:textfield
name="username" key="app.username" size="15" labelposition="top" /> , not
getting the actual result.


           Can  you provide some suggestion.


Muthu Velappan wrote:
> 
> 
> I agree with Vishnu if the project is small, say 20-25 Actions spread
> around
> 3-5 packages for the entire project. If it goes beyond that I would
> include
> a properties file named "package.properties" for each package and split
> the
> internationalization text based on each packages. I believe this will be
> more manageable than having a single properties file with 1000's of
> line...
> 
> ~Muthu
> 
> -----Original Message-----
> From: Vishnu Vyasan Nelliparmbil [mailto:vishnu@MUN.GOV.BH]  
> Sent: Monday, June 22, 2009 12:33 PM
> To: Struts Users Mailing List
> Subject: RE: Localization in struts 2
> 
> 
> 
> The best way would be to keep the properties file in the root folder and
> pecify the path in struts-config.
> So that you don’t have to write for all the packages.
> 
> Keep an another properties file with name <filename>_FR.properties for
> french  where you will define all the hindi properties.
> 
> 
> 
> 
> 
> -----Original Message-----
> From: Johnson nickel [mailto:saravanan@elogic.co.in] 
> Sent: 22 June 2009 09:58
> To: user@struts.apache.org
> Subject: RE: Localization in struts 2
> 
> 
> 
> Hi,
>       I have tried the sample project 'Struts2i18n' it's working fine.
> But,
> in my application
> i have different packages like, com.company.model, com.company.pojo etc.,
> I need write properties file for all the packages. In
> struts.properties,whether, i need to define
> 
> struts.custom.i18n.resources=com.kogent.ResourceBundle 
> struts.custom.i18n.resources=com.company.model
> struts.custom.i18n.resources=com.company.pojo 
> 
> And one more thing,for ex, If user select hindi 
> index.action?request_locale=hi Hindi 
> 
> i need to change all hindi text in throughout my application all the jsp
> pages. 
> Can you  give me suggestion
> 
> 
> 
>  
> 
> Muthu Velappan wrote:
>> 
>> I think if an app has to support internationalization then all text
>> should
>> be written from properties file and not through static images content.
>> So,
>> I
>> would be remove images and try to get write all text from properties file
>> only.
>>  
>> For Dynamic Data Issue - I believe you fetch the content from database.
>> If
>> you want to show them also in hindi then you should maintain that in db
>> as
>> well. For example: you want show all countries in English as well hindi. 
>> 
>> Then your countries table should be like this
>> 
>> Countryid  	name 			name_hi
>> name_fr 
>> 1		India	  <Hindi Translated Content>   <French Translated
>> content>
>> 2		UK                   -do-			-do-
>> 3		USA                  -do-			-do-
>> and so no...
>> 
>> While fetching you have to pass the ISO language code along with request
>> and
>> fetch data from respective column. This is one way of solving your issue.
>> I
>> don’t know how much of dynamic content you want to show like this. If you
>> have a very huge list then this would be a very difficult job to
>> complete.
>> 
>> Regards,
>> Muthu
>> 
>> -----Original Message-----
>> From: Johnson nickel [mailto:saravanan@elogic.co.in] 
>> Sent: Thursday, June 18, 2009 1:15 PM
>> To: user@struts.apache.org
>> Subject: RE: Localization in struts 2
>> 
>> 
>> 
>> Thank you.. it's working fine. I have other issue.. in my application
>> most
> 
>> of the places i used the images. I want to change images(like
>> username,password) also in hindi. 
>> 
>> And, using this method, i can display the text from properties file only.
>> in
>> my application
>> i have some dynamic data to add some data..for that i need to display in
>> hindi only..
>> 
>> Can you me a suggestions it will be helpful for further work. I 'm using
>> struts 2 framework.
>> 
>> 
>> Muthu Velappan wrote:
>>> 
>>> Try this...
>>> 
>>> Take a copy of ur current properties file and name it as
>>> hinditext.txt(save
>>> it in UTF-8 format)
>>> 
>>> Now open command prompt and go to your <JAVA_HOME>/bin folder and run
>>> this
>>> command 
>>> 
>>> native2ascii -encoding UTF-8 <full path of hinditext.txt file>
>>> <app_hi.properties>
>>> 
>>> Now rename this app_hi.properties file with respect to ur application
>>> properties file and copy to the required place. Restart the server you
>>> should be able to see the hindi text properly in browser.
>>> 
>>> Hope this solves your problem.
>>> 
>>> Thanks,
>>> Muthu
>>> 
>>> -----Original Message-----
>>> From: Johnson nickel [mailto:saravanan@elogic.co.in] 
>>> Sent: Thursday, June 18, 2009 12:28 PM
>>> To: user@struts.apache.org
>>> Subject: Re: Localization in struts 2
>>> 
>>> 
>>> I have tried to copy the properties files text and opening in notepad
>>> while saving i had selected the encoding type as UTF-8. But still i'm
>>> not
> 
>>> able to see the hindi text in browser.
>>> 
>>> And in my jsp i have added ,
>>>  <%@ page language="java" pageEncoding="utf-8"
>>> contentType="text/html;charset=utf-8"%> 
>>> <meta equiv="Content-Type" content="text/html; charset=UTF-8">
>>> 
>>> 
>>> 
>>> Girish Naik wrote:
>>>> 
>>>> Is the Hindi text specified in the file in UTF8 format? ie /u0092 etc.
>>>> 
>>>> 
>>>> 
>>>> Regards,
>>>> ---------------------------------------------------------
>>>> Girish Naik
>>>> Mobile:-+91-09740091638
>>>> girish.naik@gmail.com
>>>> 
>>>> Mitch
>>>> Hedberg<http://www.brainyquote.com/quotes/authors/m/mitch_hedberg.html>
>>>> - "I drank some boiling water because I wanted to whistle."
>>>> 
>>>> On Thu, Jun 18, 2009 at 10:45 AM, Johnson nickel
>>>> <sa...@elogic.co.in>wrote:
>>>> 
>>>>>
>>>>> Hi all,
>>>>>
>>>>>        I have tried the Struts2i18n sample project it's working fine.
>>>>> But
>>>>> i
>>>>> need to
>>>>> implement local language in the same manner. I have created
>>>>> ResourceBundle_Hi.properties for
>>>>> hindi language. I had specified the hindi text in this file. when i
>>>>> try
>>>>> to
>>>>> execute the application
>>>>> it shows some नाम: or ???. It's not actually taken the proper
>>>>> file.Give me a suggestions for this
>>>>> issue
>>>>> --
>>>>> View this message in context:
>>>>>
http://www.nabble.com/Localization-in-struts-2-tp24086510p24086510.html
>>>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>> 
>>>> 
>>> 
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/Localization-in-struts-2-tp24086510p24087439.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Localization-in-struts-2-tp24086510p24088035.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Localization-in-struts-2-tp24086510p24142528.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
Quoted from: 
http://old.nabble.com/Localization-in-struts-2-tp24086510p24142705.html




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