I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit c57552f4 authored by zzz's avatar zzz
Browse files

* Console: Handle ISO-639-2 language codes (ticket #1229)

parent 96b4c6b2
No related branches found
No related tags found
No related merge requests found
...@@ -53,19 +53,20 @@ public class CSSHelper extends HelperBase { ...@@ -53,19 +53,20 @@ public class CSSHelper extends HelperBase {
/** /**
* change default language for the router AND save it * change default language for the router AND save it
* @param lang xx OR xx_XX * @param lang xx OR xx_XX OR xxx OR xxx_XX
*/ */
public void setLang(String lang) { public void setLang(String lang) {
// Protected with nonce in css.jsi // Protected with nonce in css.jsi
if (lang != null) { if (lang != null && lang.length() > 0) {
Map m = new HashMap(2); Map m = new HashMap(2);
if (lang.length() == 2) { int under = lang.indexOf('_');
if (under < 0) {
m.put(Messages.PROP_LANG, lang.toLowerCase(Locale.US)); m.put(Messages.PROP_LANG, lang.toLowerCase(Locale.US));
m.put(Messages.PROP_COUNTRY, ""); m.put(Messages.PROP_COUNTRY, "");
_context.router().saveConfig(m, null); _context.router().saveConfig(m, null);
} else if (lang.length() == 5) { } else if (under > 0 && lang.length() > under + 1) {
m.put(Messages.PROP_LANG, lang.substring(0, 2).toLowerCase(Locale.US)); m.put(Messages.PROP_LANG, lang.substring(0, under).toLowerCase(Locale.US));
m.put(Messages.PROP_COUNTRY, lang.substring(3, 5).toUpperCase(Locale.US)); m.put(Messages.PROP_COUNTRY, lang.substring(under + 1).toUpperCase(Locale.US));
_context.router().saveConfig(m, null); _context.router().saveConfig(m, null);
} }
} }
......
...@@ -70,6 +70,7 @@ public class ConfigUIHelper extends HelperBase { ...@@ -70,6 +70,7 @@ public class ConfigUIHelper extends HelperBase {
* See http://en.wikipedia.org/wiki/ISO_639-1 . * See http://en.wikipedia.org/wiki/ISO_639-1 .
* Any language-specific flag added to the icon set must be * Any language-specific flag added to the icon set must be
* added to the top-level build.xml for the updater. * added to the top-level build.xml for the updater.
* As of 0.9.12, ISO 639-2 three-letter codes are supported also.
*/ */
private static final String langs[][] = { private static final String langs[][] = {
{ "ar", "lang_ar", _x("Arabic"), null }, { "ar", "lang_ar", _x("Arabic"), null },
...@@ -138,7 +139,8 @@ public class ConfigUIHelper extends HelperBase { ...@@ -138,7 +139,8 @@ public class ConfigUIHelper extends HelperBase {
buf.append("checked=\"checked\" "); buf.append("checked=\"checked\" ");
buf.append("value=\"").append(lang).append("\">") buf.append("value=\"").append(lang).append("\">")
.append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(langs[i][1]).append("\"> "); .append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(langs[i][1]).append("\"> ");
String slang = lang.length() > 2 ? lang.substring(0, 2) : lang; int under = lang.indexOf('_');
String slang = (under > 0) ? lang.substring(0, under) : lang;
buf.append(Messages.getDisplayLanguage(slang, langs[i][2], _context)); buf.append(Messages.getDisplayLanguage(slang, langs[i][2], _context));
String name = langs[i][3]; String name = langs[i][3];
if (name != null) { if (name != null) {
......
...@@ -135,7 +135,7 @@ public abstract class Translate { ...@@ -135,7 +135,7 @@ public abstract class Translate {
} }
/** /**
* Two-letter lower case * Two- or three-letter lower case
* @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) {
...@@ -192,7 +192,7 @@ public abstract class Translate { ...@@ -192,7 +192,7 @@ public abstract class Translate {
* by langCode, using the current language. * by langCode, using the current language.
* Uses translation if available, then JVM Locale.getDisplayLanguage() if available, else default param. * Uses translation if available, then JVM Locale.getDisplayLanguage() if available, else default param.
* *
* @param langCode two-letter lower-case * @param langCode two- or three-letter lower-case
* @param dflt e.g. "English" * @param dflt e.g. "English"
* @since 0.9.5 * @since 0.9.5
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment