Sign in

E-mail *, (xx@domain.com)
Password *

Register | Forgot password

Blogs

  • Bram de Kruijff
  • Ivo Ladage
  • Mark van Cuijk
  • Martin van Mierloo
  • Martijn van Berkum
  • Michel Teunissen
  • Patrick Atoon

Recent blogs

RSS - Blogs
March 9, 2010
State of OSGi in the Java world
March 4, 2010
Reach more people with Google Translate
March 3, 2010
Get My Advice
February 26, 2010
What? Where!?!
February 11, 2010
Split it!

All Blogs...


Japanese encore (日本のアンコール)

July 7, 2008

Life as webdesigner is hard, isn't it? One day the requirements say this, the next day they say something else. We can save ourselves some hardships by not hardcoding everything into the design, as I will demonstrate below.

For example, let's take a look at my first attempt of a very basic presentation for a pagecollection element:


<%-- Patrick's Very Basic pageCollectionElement.jspf --%>
<%@ page language="java" session="false" buffer="none" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.gx.nl/taglib/wm" prefix="wm" %>
<c:set var="pageCollectionElement" value="${presentationcontext.element}" />
<ul>
<c:forEach var="page" items="${pageCollectionElement.pages}">
    <%-- This is where the action is --%>
    <wm:link var="link" reference="${item}" />
    <li>${link.htmlTag}</li>
</c:forEach>
</ul>

Cute, isn't it?

Now I would like to just print the name without a link and print "Read more" linked behind it. That's just how I like my page collections. Call me crazy.

One way to do that, would be to make the code like this:


    <%-- This is where the action is --%>
    <c:set var="pageTitle" value="${item.current.title}" />
    <wm:link var="link" title="Read more" reference="${item}" />
    <li>${pageTitle} (${link.htmlTag})</li>
Perfect! Just the way I want it.

But wait a minute... The "Read more" text is now fixed for this design. If the same presentation is used on the Japanese site, it will still say "Read more" instead of "多くを読みなさい".


Luckily there is a way to avoid this: use text labels. By using text labels, strings can be retrieved from GX WebManager, where a webmaster can define which text should be used for which language. There are a few rules to abide by when using text labels:


  • A text label can only consist of the characters 'a' to 'z', '0' to '9' and '_'. No other characters are allowed.
  • A text label must be unique among all labels. The smart thing to do is to prepend something unique to the string. In my example, "read_more" may already be in use, so I'll use "pa_read_more".
  • The text "project." (including the dot) should be prepended.

Using these rules, I end up with the aptly named text label "project.pa_read_more".


My code becomes something like this:


    <%-- This is where the action is --%>
    <c:set var="pageTitle" value="${item.current.title}" />
    <wm:text var="readMoreText" label="project.pa_read_more">
    <wm:link var="link" title="${readMoreText}" reference="${item}" />
    <li>${pageTitle} (${link.htmlTag})</li>
When used for the first time, the label does not exist. GX WebManager creates the label so it can be edited. In the mean time, GX WebManager will display the label name as a replacement: "project.pa_read_more".

Note: if you ever see these kind of texts printed on your page, that means you need to go to "Configure > Language labels..." and fill in suitable texts.

So all we now need to do is head over to "Configure > Language labels", select "English" as language and scroll down to "pa_read_more" and edit in "Read more". Or select "Japanese" as language and fill in "多くを読みなさい".


And presto! No more need to change the presentation code for each and every language version. So... whenever you encounter hardcoded text in a layout, be sure to use text labels. Think: "wm:text is my friend! " It will save your hide later on!


Later,

Patrick


About the Author

Return to all blogs

 

Patrick Atoon

Patrick Atoon has gained nuff respect as one of the most experienced web architects in the GX Webmanager community or even the global hip hop community for that matter.

Read all Patricks blog entries

Other blog entries:

February 26, 2010
What? Where!?!
September 3, 2009
Do the Right Thing
June 18, 2009
wm:link secrets
March 2, 2009
Server side represent! (Part 2)
February 4, 2009
Server side represent!
January 15, 2009
Making cache
December 9, 2008
Like A Version
August 19, 2008
Stop making sense
August 4, 2008
Namaste!
May 20, 2008
All amped up


Share:

del.icio.us
digg
Technorati
Slashdot
Reddit
YahooMyWeb
NewsVine
ekudos
© 2010 GX creative online development B.V.

Disclaimer

This website (GXdeveloperweb.com) may discuss or contain opinions, (sample) coding, software or other information that does not include GX official interfaces, instructions or guidelines and therefore is not supported by GX. Changes made based on this information are not supported.  GX will not be held liable for any damages caused by using or misusing the information, software, instructions, code or methods suggested on this website, and anyone using these methods does so at his/her own risk. GX offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this website, including any liability resulting from incompatibility between the content of this website and the materials and services offered by GX. By using this website you will not hold, or seek to hold, GX responsible or liable with respect to the content of this website.