Kawai Wiki

Compare Revisions

Ignore whitespace Rev 139 → Rev 140

/trunk/src/main/java/org/kawai/model/Language.java
1,6 → 1,7
package org.kawai.model;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
 
111,4 → 112,8
}
return null;
}
public static List<Language> all() {
return LANGUAGES;
}
}
/trunk/src/main/java/org/kawai/AppManager.java
135,7 → 135,8
for(int i = 0; i < languages.size(); i++) {
String[] array = languages.get(i);
Language l = new Language(i + 1, array[0], array[1], array[2]);
Language l = new Language(i + 1, array[0], array[1], array.length >= 3 ? array[2] : null);
Language.add(l);
addLocale(l.getLocale());
}
/trunk/src/main/java/org/kawai/tag/ListFlags.java
New file
0,0 → 1,53
package org.kawai.tag;
 
import java.util.Locale;
 
import javax.servlet.jsp.JspException;
 
import org.kawai.model.Language;
import org.mentawai.i18n.LocaleManager;
import org.mentawai.tag.i18n.RewriteWithLoc;
import org.mentawai.tag.util.PrintTag;
 
public class ListFlags extends PrintTag {
public String getStringToPrint() throws JspException {
/*
<mtw:isLocale value="pt">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #ccc;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #fff;" /></a>
</mtw:isLocale>
<mtw:isLocale value="en">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #fff;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #ccc;" /></a>
</mtw:isLocale>
*/
LocaleManager.decideLocale(req, res); // force the locale to be chosen from param or cookie...
Locale selectedLocale = LocaleManager.getLocale(req, false);
String cp = req.getContextPath();
StringBuilder sb = new StringBuilder(1024);
 
for(Language lang : Language.all()) {
Locale loc = lang.getLocale();
boolean selected = lang.getLocale().equals(selectedLocale);
 
RewriteWithLoc tag = new RewriteWithLoc();
tag.setPageContext(pageContext);
tag.setLoc(loc.toString());
tag.setTagsToExclude("revision");
tag.doStartTag();
String href = tag.getStringToPrint();
sb.append("<a href=\"").append(href).append("\">");
sb.append("<img src=\"").append(cp).append("/uploads/images/").append(lang.getImageFile()).append("\" border=\"0\" width=\"20\" height=\"13\" style=\"border: 3px solid ");
if (selected) sb.append("#ccc");
else sb.append("#fff");
sb.append("; \" /></a>\n");
}
return sb.toString();
}
}
/trunk/src/main/webapp/WEB-INF/tld/taglib.tld
38,4 → 38,11
</attribute>
</tag>
<tag>
<name>listFlags</name>
<tag-class>org.kawai.tag.ListFlags</tag-class>
<body-content>empty</body-content>
<display-name></display-name>
</tag>
</taglib>
/trunk/src/main/webapp/show_page.jsp
1074,6 → 1074,7
<a href="<mtw:contextPath/>/Logout.mtw">Logout</a> (<mtw:out value="sessionUser.username" />)
</mtw:isLogged>
&nbsp;
<%--
<mtw:isLocale value="pt">
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #ccc;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #fff;" /></a>
1082,6 → 1083,8
<a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #fff;" /></a>
<a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #ccc;" /></a>
</mtw:isLocale>
--%>
<k:listFlags />
&nbsp;&nbsp;&nbsp;
</td>
</tr>