Sign in

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

Register | Forgot password

Recent blogs

RSS - Blogs
December 24, 2008
The year has almost ended...
December 9, 2008
5 Spring pitfalls
December 9, 2008
Like A Version
October 22, 2008
New certification process
October 17, 2008
Search quest [3/3] - improvements

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



markvc | 07-07-2008 20:19

Why are the kana and kanji in reply message converted to question marks, while you are able to put them in your blog? I suppose life just isn't fair



patricka | 08-07-2008 11:02

My guess would be: no NTEXT field in the database?



jasper | 08-07-2008 11:56

It will save your hide later on!


Hiney is the correct term here



pgoultiaev | 08-07-2008 16:21

Kawaii!



jbogers | 15-07-2008 13:21

<c:forEach var="page" items="${pageCollectionElement.pages}">

Shouldn't that be var="item" for the rest to work?

yoroshiku ^^


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:

December 9, 2008
Like A Version
August 19, 2008
Stop making sense
August 4, 2008
Namaste!
May 20, 2008
All amped up
May 7, 2008
No soup for you!
April 16, 2008
Live in effect
April 14, 2008
Lacking chemistry
March 20, 2008
About cars and software
March 17, 2008
Scope, que?!
March 11, 2008
Maven FTW!


Share:

del.icio.us
digg
Technorati
Slashdot
Reddit
YahooMyWeb
NewsVine
ekudos
© 2008 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.