Dakota Jack wrote: There are several levels to the i18n problem. The simplest is just picking the correct string to output on a particular page such as a title.How does this solve the i18n problem? <snip> On Mon, 17 Jan 2005 03:07:27 -0600, Kishore Senji <[EMAIL PROTECTED]> wrote:On Mon, 17 Jan 2005 17:54:55 +0900, Sylvain ~ <[EMAIL PROTECTED]> wrote:By the way, I don"t want to have ONE internationilized title for all my pages, so I can't do that, it would have been too simple !! I have many pages, having different i18n titles,You can extend the main.layout and override the title for the different pages like so<definition name="main.layout" path="/WEB-INF/jsp/layout_main.jsp"> <put name="title" value="main.title" /> <put name="header" value="/WEB-INF/jsp/layout_header.jsp" /> <put name="footer" value="/WEB-INF/jsp/layout_footer.jsp" /> </definition> <definition name="login.layout" extends="main.layout"> <put name="title" value="login.title"/> <put name="body" value="/WEB-INF/jsp/loginform.jsp" /> </definition></snip> If you have different pages and want different results by overriding, that is a different issue altogether. Overriding does not solve the i18n problem at all so far as I can see. I really prefer Lesaint's solution to mine. I do something entirely different than either of them but different than your approach too. I make the title tag's value dynamic in the layout, e.g. <title><c:out value='${state.title}'/></title>. I like this because it does not tie itself to Tiles, although maybe I should switch to what Lesaint is doing. How come the French seem to be so adept at GUIs? Maybe there is just a deep sense of style in the French psyche? This isn't necessarilly tying yourself to tiles, you could specify the title key in your action or each individual .jsp page. It certainly makes it easier to maintain. Just match up keys in tiles to keys in your application.properties files and .jsp files. Easiest way to demonstrate is a few examples: application_en_US.properties: login.title=Hello application_en_NZ.properties: login.title=Hi Mate application_en.properties: login.title=Hi In Tiles, we use the examples above because they are fine: <definition name="main.layout" path="/WEB-INF/jsp/layout_main.jsp"> <put name="title" value="main.title" /> <put name="header" value="/WEB-INF/jsp/layout_header.jsp" /> <put name="footer" value="/WEB-INF/jsp/layout_footer.jsp" /> </definition> <definition name="login.layout" extends="main.layout"> <put name="title" value="login.title"/> <put name="body" value="/WEB-INF/jsp/loginform.jsp" /> </definition>In your layout.jsp page we use the following: <title> <tiles:importAttribute name="title" /> <bean:message name="title" scope="page" /> </title>That name="title" will look up the applications.properties file and pick the string depending on your locale. So we should see either "Hello","Hi Mate", or "Hi". This can also be done in JSTL (may have to set the resource bundle to be the same one struts uses) <title> <tiles:importAttribute name="title" /> <fmt:message key="${title}" /> </title>Now you say your titles need to be dynamic - it really depends on what information changes in this title. This is the next harder step in i18n, but it isn't too difficult to do: application_en_US.properties: login.title=Hello {0} {1} application_en_NZ.properties: login.title={1}, Hi Mate application_en.properties: login.title=Hi {0} {1} Above we have put in the {0} substitution points where the information will appear. If we want {1} to be their title eg Mr Mrs and {0} to be a person's name. <title> <tiles:importAttribute name="title" /> <bean:message name="title" arg0="Mr" arg1="Smith" scope="page" /> </title>or in JSTL (assuming we have a user object with user's name and title) <fmt:message key="${title}"> <fmt:param value="${user.title}"/> <fmt:param value="${user.name}"/> </fmt:message> We should end up with output en_US: Hello Mr Smith en_NZ: Smith, Hi Mate en: Hi Mr Smith It get's trickier when part of the text should change based on numbers eg 0 files, 1 file, 2 files as {0} file wouldn't work But the above should deal with most of the common uses -- Jason Lea |
No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.7.0 - Release Date: 2005.01.17
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]