forked from I2P_Developers/i2p.i2p
Add multilanguage support for index.jsp
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.FileUtil;
|
||||
|
||||
@ -7,6 +10,7 @@ public class ContentHelper {
|
||||
private String _page;
|
||||
private int _maxLines;
|
||||
private boolean _startAtBeginning;
|
||||
private String _lang;
|
||||
private RouterContext _context;
|
||||
/**
|
||||
* Configure this bean to query a particular router context
|
||||
@ -28,6 +32,7 @@ public class ContentHelper {
|
||||
public void setStartAtBeginning(String moo) {
|
||||
_startAtBeginning = Boolean.valueOf(""+moo).booleanValue();
|
||||
}
|
||||
public void setLang(String l) { _lang = l; }
|
||||
|
||||
public void setMaxLines(String lines) {
|
||||
if (lines != null) {
|
||||
@ -41,14 +46,14 @@ public class ContentHelper {
|
||||
}
|
||||
}
|
||||
public String getContent() {
|
||||
String str = FileUtil.readTextFile(_page, _maxLines, _startAtBeginning);
|
||||
String str = FileUtil.readTextFile(filename(), _maxLines, _startAtBeginning);
|
||||
if (str == null)
|
||||
return "";
|
||||
else
|
||||
return str;
|
||||
}
|
||||
public String getTextContent() {
|
||||
String str = FileUtil.readTextFile(_page, _maxLines, _startAtBeginning);
|
||||
String str = FileUtil.readTextFile(filename(), _maxLines, _startAtBeginning);
|
||||
if (str == null)
|
||||
return "";
|
||||
else {
|
||||
@ -66,4 +71,27 @@ public class ContentHelper {
|
||||
return sb.append("</pre>").toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert file.ext to file_lang.ext if it exists.
|
||||
* Get lang from either the cgi lang param or from the default locale.
|
||||
*/
|
||||
private String filename() {
|
||||
int lastdot = _page.lastIndexOf('.');
|
||||
if (lastdot <= 0)
|
||||
return _page;
|
||||
String lang = _lang;
|
||||
if (lang == null || lang.length() <= 0) {
|
||||
lang = Locale.getDefault().getLanguage();
|
||||
if (lang == null || lang.length() <= 0)
|
||||
return _page;
|
||||
}
|
||||
if (lang.equals("en"))
|
||||
return _page;
|
||||
String newname = _page.substring(0, lastdot) + '_' + lang + _page.substring(lastdot);
|
||||
File newfile = new File(newname);
|
||||
if (newfile.exists())
|
||||
return newname;
|
||||
return _page;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user