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

@ -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);
}
/**