Package net.i2p.util
Class Translate
java.lang.Object
net.i2p.util.Translate
- Direct Known Subclasses:
Messages
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
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.
- Since:
- 0.7.9
- Author:
- zzz, from a base generated by eclipse.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clear the cache.static String
getCountry
(I2PAppContext ctx) Two-letter upper case or ""static String
getDisplayLanguage
(String langCode, String dflt, I2PAppContext ctx, String bun) Return the "display language", e.g.static String
getLanguage
(I2PAppContext ctx) Two- or three-letter lower casestatic String
getString
(int n, String s, String p, I2PAppContext ctx, String bun) Use GNU ngettext For .po file format see http://www.gnu.org/software/gettext/manual/gettext.html.gz#Translating-plural-formsstatic String
for {0} and {1}static String
getString
(String s, Object o, I2PAppContext ctx, String bun) translate a string with a parameter This is a lot more expensive than getString(s, ctx), so use sparingly.static String
getString
(String key, I2PAppContext ctx, String bun) lang in routerconsole.lang property, else current localestatic String
getString
(String s, I2PAppContext ctx, String bun, Object... oArray) Varargsstatic boolean
Is this a right-to-left language?static boolean
isRTL
(I2PAppContext ctx) Are we configured for a right-to-left language?static void
setLanguage
(String lang, String country) Only for use by standalone apps in App Context.
-
Field Details
-
PROP_LANG
- See Also:
-
PROP_COUNTRY
- Since:
- 0.9.10
- See Also:
-
-
Constructor Details
-
Translate
public Translate()
-
-
Method Details
-
getString
lang in routerconsole.lang property, else current locale -
getString
translate a string with a parameter This is a lot more expensive than getString(s, ctx), so use sparingly.- Parameters:
s
- string to be translated containing {0} The {0} will be replaced by the parameter. Single quotes must be doubled, i.e. ' -> '' in the string.o
- parameter, not translated. To translate parameter also, use _t("foo {0} bar", _t("baz")) Do not double the single quotes in the parameter. Use autoboxing to call with ints, longs, floats, etc.
-
getString
for {0} and {1} -
getString
Varargs- Parameters:
oArray
- parameters- Since:
- 0.9.8
-
getString
Use GNU ngettext For .po file format see http://www.gnu.org/software/gettext/manual/gettext.html.gz#Translating-plural-forms- Parameters:
n
- how manys
- singluar string, optionally with {0} e.g. "one tunnel"p
- plural string optionally with {0} e.g. "{0} tunnels"- Since:
- 0.7.14
-
getLanguage
Two- or three-letter lower case- Returns:
- lang in routerconsole.lang property, else current locale
-
isRTL
Are we configured for a right-to-left language?- Returns:
- true for supported RTL languages
- Since:
- 0.9.46
-
isRTL
Is this a right-to-left language?- Parameters:
lang
- Two- or three-letter lower case- Returns:
- true for supported RTL languages
- Since:
- 0.9.46
-
getCountry
Two-letter upper case or ""- Returns:
- country in routerconsole.country property, else current locale
- Since:
- 0.9.10
-
setLanguage
Only for use by standalone apps in App Context. NOT for use in Router Context. Does not persist, apps must implement their own persistence. Does NOT override context properties.- Parameters:
lang
- Two- or three-letter lower case, or null for defaultcountry
- Two-letter upper case, or null for default, or "" for none- Since:
- 0.9.27
-
getDisplayLanguage
public static String getDisplayLanguage(String langCode, String dflt, I2PAppContext ctx, String bun) Return the "display language", e.g. "English" for the language specified by langCode, using the current language. Uses translation if available, then JVM Locale.getDisplayLanguage() if available, else default param.- Parameters:
langCode
- two- or three-letter lower-casedflt
- e.g. "English"- Since:
- 0.9.5
-
clearCache
public static void clearCache()Clear the cache. Call this after adding new bundles to the classpath.- Since:
- 0.7.12
-