Back out previous checkin adding override fields to Translate;

we can set language and country with System properties in app context.
Back out previous checkin bundling countries translations in
i2psnark standalone; use Locale to translate country names.
This commit is contained in:
zzz
2016-06-18 17:49:28 +00:00
parent e6f111c5fc
commit 4ee66c8218
4 changed files with 26 additions and 25 deletions

View File

@ -213,7 +213,9 @@
<zipfileset src="../../systray/java/build/systray.jar" />
<!-- Countries translations. The i2psnark translations are in the war but it's easier to put these here -->
<!-- 300KB just to translate "Brazil", but why not... -->
<!--
<fileset dir="../../routerconsole/java/build/obj" includes="net/i2p/router/countries/*.class" />
-->
<manifest>
<attribute name="Main-Class" value="org.klomp.snark.standalone.RunStandalone"/>
<attribute name="Implementation-Version" value="${full.version}" />

View File

@ -1,5 +1,7 @@
package org.klomp.snark.standalone;
import java.util.Locale;
import net.i2p.I2PAppContext;
import net.i2p.util.Translate;
@ -12,7 +14,7 @@ public class ConfigUIHelper {
private static final String CHECKED = " selected=\"selected\" ";
private static final String BUNDLE_NAME = "org.klomp.snark.web.messages";
private static final String COUNTRY_BUNDLE_NAME = "net.i2p.router.countries.messages";
//private static final String COUNTRY_BUNDLE_NAME = "net.i2p.router.countries.messages";
/**
* Each language has the ISO code, the flag, the name, and the optional country name.
@ -107,8 +109,12 @@ public class ConfigUIHelper {
buf.append(Translate.getDisplayLanguage(slang, langs[i][2], ctx, BUNDLE_NAME));
String name = langs[i][3];
if (name != null) {
String cou = (under > 0) ? lang.substring(under + 1) : lang;
Locale cur = new Locale(current);
Locale loc = new Locale(slang, cou);
buf.append(" (")
.append(Translate.getString(name, ctx, COUNTRY_BUNDLE_NAME))
//.append(Translate.getString(name, ctx, COUNTRY_BUNDLE_NAME))
.append(loc.getDisplayCountry(cur))
.append(')');
}
buf.append("</option>\n");

View File

@ -1834,8 +1834,7 @@
</target> -->
<!-- standalone i2psnark zip -->
<!-- console dependency for countries bundle -->
<target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray, buildRouterConsole" >
<target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray" >
<ant dir="apps/i2psnark/java" target="standalone" />
<copy file="apps/i2psnark/java/i2psnark-standalone.zip" todir="." />
</target>

View File

@ -18,7 +18,11 @@ import net.i2p.util.ConcurrentHashSet;
* Translate strings efficiently.
* We don't include an English or default ResourceBundle, we simply check
* for "en" and return the original string.
* Support real-time language changing with the routerconsole.lang property.
* Support real-time language changing with the routerconsole.lang
* and routerconsole.country properties.
*
* To change language in router context, set the context properties PROP_LANG and PROP_COUNTRY.
* To change language in app context, set the System properties PROP_LANG and PROP_COUNTRY.
*
* @author zzz, from a base generated by eclipse.
* @since 0.7.9
@ -31,10 +35,6 @@ public abstract class Translate {
private static final String _localeLang = Locale.getDefault().getLanguage();
/** non-null, two-letter upper case, may be "" */
private static final String _localeCountry = Locale.getDefault().getCountry();
/** App context only, two- or three-letter lower case, may be null */
private static String _overrideLang = null;
/** App context only, two-letter upper case, may be "" or null */
private static String _overrideCountry = null;
private static final Map<String, ResourceBundle> _bundles = new ConcurrentHashMap<String, ResourceBundle>(16);
private static final Set<String> _missing = new ConcurrentHashSet<String>(16);
/** use to look for untagged strings */
@ -143,12 +143,6 @@ public abstract class Translate {
* @return lang in routerconsole.lang property, else current locale
*/
public static String getLanguage(I2PAppContext ctx) {
if (!ctx.isRouterContext()) {
synchronized(Translate.class) {
if (_overrideLang != null)
return _overrideLang;
}
}
String lang = ctx.getProperty(PROP_LANG);
if (lang == null || lang.length() <= 0)
lang = _localeLang;
@ -161,12 +155,6 @@ public abstract class Translate {
* @since 0.9.10
*/
public static String getCountry(I2PAppContext ctx) {
if (!ctx.isRouterContext()) {
synchronized(Translate.class) {
if (_overrideCountry != null)
return _overrideCountry;
}
}
// property may be empty so we don't have a non-default
// language and a default country
return ctx.getProperty(PROP_COUNTRY, _localeCountry);
@ -176,15 +164,21 @@ public abstract class Translate {
* Only for use by standalone apps in App Context.
* NOT for use in Router Context.
* Does not persist, apps must implement their own persistence.
* Overrides in all contexts.
* Does NOT override context properties.
*
* @param lang Two- or three-letter lower case, or null for default
* @param country Two-letter upper case, or null for default, or "" for none
* @since 0.9.27
*/
public synchronized static void setLanguage(String lang, String country) {
_overrideLang = lang;
_overrideCountry = country;
public static void setLanguage(String lang, String country) {
if (lang != null)
System.setProperty(PROP_LANG, lang);
else
System.clearProperty(PROP_LANG);
if (country != null)
System.setProperty(PROP_COUNTRY, country);
else
System.clearProperty(PROP_COUNTRY);
}
/**