forked from I2P_Developers/i2p.i2p
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:
@ -213,7 +213,9 @@
|
|||||||
<zipfileset src="../../systray/java/build/systray.jar" />
|
<zipfileset src="../../systray/java/build/systray.jar" />
|
||||||
<!-- Countries translations. The i2psnark translations are in the war but it's easier to put these here -->
|
<!-- 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... -->
|
<!-- 300KB just to translate "Brazil", but why not... -->
|
||||||
|
<!--
|
||||||
<fileset dir="../../routerconsole/java/build/obj" includes="net/i2p/router/countries/*.class" />
|
<fileset dir="../../routerconsole/java/build/obj" includes="net/i2p/router/countries/*.class" />
|
||||||
|
-->
|
||||||
<manifest>
|
<manifest>
|
||||||
<attribute name="Main-Class" value="org.klomp.snark.standalone.RunStandalone"/>
|
<attribute name="Main-Class" value="org.klomp.snark.standalone.RunStandalone"/>
|
||||||
<attribute name="Implementation-Version" value="${full.version}" />
|
<attribute name="Implementation-Version" value="${full.version}" />
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.klomp.snark.standalone;
|
package org.klomp.snark.standalone;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.Translate;
|
import net.i2p.util.Translate;
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ public class ConfigUIHelper {
|
|||||||
|
|
||||||
private static final String CHECKED = " selected=\"selected\" ";
|
private static final String CHECKED = " selected=\"selected\" ";
|
||||||
private static final String BUNDLE_NAME = "org.klomp.snark.web.messages";
|
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.
|
* 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));
|
buf.append(Translate.getDisplayLanguage(slang, langs[i][2], ctx, BUNDLE_NAME));
|
||||||
String name = langs[i][3];
|
String name = langs[i][3];
|
||||||
if (name != null) {
|
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(" (")
|
buf.append(" (")
|
||||||
.append(Translate.getString(name, ctx, COUNTRY_BUNDLE_NAME))
|
//.append(Translate.getString(name, ctx, COUNTRY_BUNDLE_NAME))
|
||||||
|
.append(loc.getDisplayCountry(cur))
|
||||||
.append(')');
|
.append(')');
|
||||||
}
|
}
|
||||||
buf.append("</option>\n");
|
buf.append("</option>\n");
|
||||||
|
@ -1834,8 +1834,7 @@
|
|||||||
</target> -->
|
</target> -->
|
||||||
|
|
||||||
<!-- standalone i2psnark zip -->
|
<!-- standalone i2psnark zip -->
|
||||||
<!-- console dependency for countries bundle -->
|
<target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray" >
|
||||||
<target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray, buildRouterConsole" >
|
|
||||||
<ant dir="apps/i2psnark/java" target="standalone" />
|
<ant dir="apps/i2psnark/java" target="standalone" />
|
||||||
<copy file="apps/i2psnark/java/i2psnark-standalone.zip" todir="." />
|
<copy file="apps/i2psnark/java/i2psnark-standalone.zip" todir="." />
|
||||||
</target>
|
</target>
|
||||||
|
@ -18,7 +18,11 @@ import net.i2p.util.ConcurrentHashSet;
|
|||||||
* Translate strings efficiently.
|
* Translate strings efficiently.
|
||||||
* We don't include an English or default ResourceBundle, we simply check
|
* We don't include an English or default ResourceBundle, we simply check
|
||||||
* for "en" and return the original string.
|
* 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.
|
* @author zzz, from a base generated by eclipse.
|
||||||
* @since 0.7.9
|
* @since 0.7.9
|
||||||
@ -31,10 +35,6 @@ public abstract class Translate {
|
|||||||
private static final String _localeLang = Locale.getDefault().getLanguage();
|
private static final String _localeLang = Locale.getDefault().getLanguage();
|
||||||
/** non-null, two-letter upper case, may be "" */
|
/** non-null, two-letter upper case, may be "" */
|
||||||
private static final String _localeCountry = Locale.getDefault().getCountry();
|
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 Map<String, ResourceBundle> _bundles = new ConcurrentHashMap<String, ResourceBundle>(16);
|
||||||
private static final Set<String> _missing = new ConcurrentHashSet<String>(16);
|
private static final Set<String> _missing = new ConcurrentHashSet<String>(16);
|
||||||
/** use to look for untagged strings */
|
/** use to look for untagged strings */
|
||||||
@ -143,12 +143,6 @@ public abstract class Translate {
|
|||||||
* @return lang in routerconsole.lang property, else current locale
|
* @return lang in routerconsole.lang property, else current locale
|
||||||
*/
|
*/
|
||||||
public static String getLanguage(I2PAppContext ctx) {
|
public static String getLanguage(I2PAppContext ctx) {
|
||||||
if (!ctx.isRouterContext()) {
|
|
||||||
synchronized(Translate.class) {
|
|
||||||
if (_overrideLang != null)
|
|
||||||
return _overrideLang;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String lang = ctx.getProperty(PROP_LANG);
|
String lang = ctx.getProperty(PROP_LANG);
|
||||||
if (lang == null || lang.length() <= 0)
|
if (lang == null || lang.length() <= 0)
|
||||||
lang = _localeLang;
|
lang = _localeLang;
|
||||||
@ -161,12 +155,6 @@ public abstract class Translate {
|
|||||||
* @since 0.9.10
|
* @since 0.9.10
|
||||||
*/
|
*/
|
||||||
public static String getCountry(I2PAppContext ctx) {
|
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
|
// property may be empty so we don't have a non-default
|
||||||
// language and a default country
|
// language and a default country
|
||||||
return ctx.getProperty(PROP_COUNTRY, _localeCountry);
|
return ctx.getProperty(PROP_COUNTRY, _localeCountry);
|
||||||
@ -176,15 +164,21 @@ public abstract class Translate {
|
|||||||
* Only for use by standalone apps in App Context.
|
* Only for use by standalone apps in App Context.
|
||||||
* NOT for use in Router Context.
|
* NOT for use in Router Context.
|
||||||
* Does not persist, apps must implement their own persistence.
|
* 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 lang Two- or three-letter lower case, or null for default
|
||||||
* @param country Two-letter upper case, or null for default, or "" for none
|
* @param country Two-letter upper case, or null for default, or "" for none
|
||||||
* @since 0.9.27
|
* @since 0.9.27
|
||||||
*/
|
*/
|
||||||
public synchronized static void setLanguage(String lang, String country) {
|
public static void setLanguage(String lang, String country) {
|
||||||
_overrideLang = lang;
|
if (lang != null)
|
||||||
_overrideCountry = country;
|
System.setProperty(PROP_LANG, lang);
|
||||||
|
else
|
||||||
|
System.clearProperty(PROP_LANG);
|
||||||
|
if (country != null)
|
||||||
|
System.setProperty(PROP_COUNTRY, country);
|
||||||
|
else
|
||||||
|
System.clearProperty(PROP_COUNTRY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user