Update: Add language param to news fetch, to support translated news (ticket #1425)

This commit is contained in:
zzz
2015-06-18 15:05:48 +00:00
parent cd62d7170c
commit 20c796e87a

View File

@ -40,6 +40,7 @@ import net.i2p.util.PortMapper;
import net.i2p.util.ReusableGZIPInputStream;
import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.SSLEepGet;
import net.i2p.util.Translate;
import net.i2p.util.VersionComparator;
/**
@ -94,8 +95,13 @@ class NewsFetcher extends UpdateRunner {
}
for (URI uri : _urls) {
String origURL = uri.toString();
String newsURL = addLang(origURL);
try {
_currentURI = new URI(newsURL);
} catch (URISyntaxException use) {
_currentURI = uri;
String newsURL = uri.toString();
}
if (_tempFile.exists())
_tempFile.delete();
@ -130,6 +136,29 @@ class NewsFetcher extends UpdateRunner {
}
}
/**
* Add a query param for the local language to get translated news
* @since 0.9.21
*/
private String addLang(String url) {
if (url.contains("?lang=") || url.contains("&lang="))
return url;
String lang = Translate.getLanguage(_context);
if (lang.equals("en"))
return url;
StringBuilder buf = new StringBuilder();
buf.append(url);
if (url.contains("?"))
buf.append("&lang=");
else
buf.append("?lang=");
buf.append(lang);
String co = Translate.getCountry(_context);
if (co.length() > 0)
buf.append('_').append(co);
return buf.toString();
}
// Fake XML parsing
// Line must contain this, and full entry must be on one line
private static final String VERSION_PREFIX = "<i2p.release ";