diff --git a/assets/languagePatterns/zh_tmp b/assets/languagePatterns/zh_tmp new file mode 100644 index 000000000..e69de29bb diff --git a/assets/resources/application/cs.xml b/assets/resources/application/cs.xml index 738665e91..ffd9dd99f 100644 --- a/assets/resources/application/cs.xml +++ b/assets/resources/application/cs.xml @@ -495,6 +495,9 @@ + + + diff --git a/assets/resources/application/de.xml b/assets/resources/application/de.xml index 568835073..d46e0e6be 100644 --- a/assets/resources/application/de.xml +++ b/assets/resources/application/de.xml @@ -496,6 +496,9 @@ + + + diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml index 0e328e258..4cbfd4b76 100644 --- a/assets/resources/application/en.xml +++ b/assets/resources/application/en.xml @@ -508,6 +508,9 @@ + + + diff --git a/assets/resources/application/fr.xml b/assets/resources/application/fr.xml index 472f90f84..a3c1a6a04 100644 --- a/assets/resources/application/fr.xml +++ b/assets/resources/application/fr.xml @@ -498,6 +498,9 @@ + + + diff --git a/assets/resources/application/hu.xml b/assets/resources/application/hu.xml index 9795df94d..ff5386aab 100644 --- a/assets/resources/application/hu.xml +++ b/assets/resources/application/hu.xml @@ -495,6 +495,9 @@ + + + diff --git a/assets/resources/application/it.xml b/assets/resources/application/it.xml index 87ff16c27..24d33c850 100644 --- a/assets/resources/application/it.xml +++ b/assets/resources/application/it.xml @@ -495,6 +495,9 @@ + + + diff --git a/assets/resources/application/ru.xml b/assets/resources/application/ru.xml index ea7fcb368..3f96bd07c 100644 --- a/assets/resources/application/ru.xml +++ b/assets/resources/application/ru.xml @@ -494,6 +494,9 @@ + + + diff --git a/assets/resources/application/uk.xml b/assets/resources/application/uk.xml index 7fced1fed..99ec438e6 100644 --- a/assets/resources/application/uk.xml +++ b/assets/resources/application/uk.xml @@ -495,6 +495,9 @@ + + + diff --git a/assets/resources/application/vi.xml b/assets/resources/application/vi.xml index 04740c18f..801be74cb 100644 --- a/assets/resources/application/vi.xml +++ b/assets/resources/application/vi.xml @@ -495,6 +495,9 @@ + + + diff --git a/assets/resources/application/zh.xml b/assets/resources/application/zh.xml index ffe28e508..f3d9e0d67 100644 --- a/assets/resources/application/zh.xml +++ b/assets/resources/application/zh.xml @@ -495,6 +495,9 @@ + + + diff --git a/assets/resources/zlibrary/cs.xml b/assets/resources/zlibrary/cs.xml index 13658b9c2..d8a7d10b5 100644 --- a/assets/resources/zlibrary/cs.xml +++ b/assets/resources/zlibrary/cs.xml @@ -80,6 +80,7 @@ + diff --git a/assets/resources/zlibrary/de.xml b/assets/resources/zlibrary/de.xml index ec00cfcb9..c30f74af4 100644 --- a/assets/resources/zlibrary/de.xml +++ b/assets/resources/zlibrary/de.xml @@ -81,6 +81,7 @@ + diff --git a/assets/resources/zlibrary/fr.xml b/assets/resources/zlibrary/fr.xml index 90b2095e8..9dc982404 100644 --- a/assets/resources/zlibrary/fr.xml +++ b/assets/resources/zlibrary/fr.xml @@ -80,6 +80,7 @@ + diff --git a/assets/resources/zlibrary/hu.xml b/assets/resources/zlibrary/hu.xml index 02704903a..ded7d8157 100644 --- a/assets/resources/zlibrary/hu.xml +++ b/assets/resources/zlibrary/hu.xml @@ -80,6 +80,7 @@ + diff --git a/assets/resources/zlibrary/it.xml b/assets/resources/zlibrary/it.xml index c91b7f772..b30597de8 100644 --- a/assets/resources/zlibrary/it.xml +++ b/assets/resources/zlibrary/it.xml @@ -80,6 +80,7 @@ + diff --git a/assets/resources/zlibrary/ru.xml b/assets/resources/zlibrary/ru.xml index b29805247..0fd16790c 100644 --- a/assets/resources/zlibrary/ru.xml +++ b/assets/resources/zlibrary/ru.xml @@ -79,6 +79,7 @@ + diff --git a/assets/resources/zlibrary/uk.xml b/assets/resources/zlibrary/uk.xml index 174bb2f9c..729c338c6 100644 --- a/assets/resources/zlibrary/uk.xml +++ b/assets/resources/zlibrary/uk.xml @@ -80,6 +80,7 @@ + diff --git a/assets/resources/zlibrary/vi.xml b/assets/resources/zlibrary/vi.xml index c2d73be91..8bbc90be1 100644 --- a/assets/resources/zlibrary/vi.xml +++ b/assets/resources/zlibrary/vi.xml @@ -80,6 +80,7 @@ + diff --git a/assets/resources/zlibrary/zh.xml b/assets/resources/zlibrary/zh.xml index 7fb5bf56f..6d54203bd 100644 --- a/assets/resources/zlibrary/zh.xml +++ b/assets/resources/zlibrary/zh.xml @@ -80,6 +80,7 @@ + diff --git a/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java index 1ac9fb317..23ea5e517 100644 --- a/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java @@ -19,6 +19,8 @@ package org.geometerplus.android.fbreader.network; +import java.util.*; + import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; @@ -28,8 +30,10 @@ import android.os.Message; import android.view.*; import android.widget.BaseAdapter; +import org.geometerplus.zlibrary.core.library.ZLibrary; import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.network.ZLNetworkException; +import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.ui.android.R; @@ -39,7 +43,6 @@ import org.geometerplus.fbreader.network.NetworkTree; import org.geometerplus.fbreader.network.NetworkLibrary; public class NetworkLibraryActivity extends NetworkBaseActivity { - private NetworkTree myTree; @Override @@ -85,7 +88,6 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { } private static class Initializator extends Handler { - private NetworkLibraryActivity myActivity; public Initializator(NetworkLibraryActivity activity) { @@ -165,7 +167,6 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { private final class LibraryAdapter extends BaseAdapter { - public final int getCount() { if (!NetworkView.Instance().isInitialized()) { return 0; @@ -178,7 +179,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { if (position == 0) { return NetworkView.Instance().getSearchItemTree(); } else if (position > 0 && position <= size) { - return (NetworkTree) myTree.subTrees().get(position - 1); + return (NetworkTree)myTree.subTrees().get(position - 1); } else if (position == size + 1) { return NetworkView.Instance().getAddCustomCatalogItemTree(); } @@ -205,6 +206,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { private static final int MENU_SEARCH = 1; private static final int MENU_REFRESH = 2; private static final int MENU_ADD_CATALOG = 3; + private static final int MENU_LANGUAGE_FILTER = 4; @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -212,6 +214,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { addMenuItem(menu, MENU_SEARCH, "networkSearch", R.drawable.ic_menu_networksearch); addMenuItem(menu, MENU_ADD_CATALOG, "addCustomCatalog", android.R.drawable.ic_menu_add); addMenuItem(menu, MENU_REFRESH, "refreshCatalogsList", R.drawable.ic_menu_refresh); + addMenuItem(menu, MENU_LANGUAGE_FILTER, "languages", 0); return true; } @@ -223,6 +226,49 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { return true; } + private void runLanguageFilterDialog() { + final NetworkLibrary library = NetworkLibrary.Instance(); + + final List allLanguageCodes = library.languageCodes(); + Collections.sort(allLanguageCodes, new ZLLanguageUtil.CodeComparator()); + final Collection activeLanguageCodes = library.activeLanguageCodes(); + final CharSequence[] languageNames = new CharSequence[allLanguageCodes.size()]; + final boolean[] checked = new boolean[allLanguageCodes.size()]; + + for (int i = 0; i < allLanguageCodes.size(); ++i) { + final String code = allLanguageCodes.get(i); + languageNames[i] = ZLLanguageUtil.languageName(code); + checked[i] = activeLanguageCodes.contains(code); + } + + final DialogInterface.OnMultiChoiceClickListener listener = + new DialogInterface.OnMultiChoiceClickListener() { + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + checked[which] = isChecked; + } + }; + final ZLResource dialogResource = ZLResource.resource("dialog"); + final AlertDialog dialog = new AlertDialog.Builder(this) + .setMultiChoiceItems(languageNames, checked, listener) + .setTitle(dialogResource.getResource("languageFilterDialog").getResource("title").getValue()) + .setPositiveButton(dialogResource.getResource("button").getResource("ok").getValue(), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + final TreeSet newActiveCodes = new TreeSet(new ZLLanguageUtil.CodeComparator()); + for (int i = 0; i < checked.length; ++i) { + if (checked[i]) { + newActiveCodes.add(allLanguageCodes.get(i)); + } + } + library.setActiveLanguageCodes(newActiveCodes); + library.invalidateChildren(); + library.synchronize(); + NetworkView.Instance().fireModelChanged(); + } + }) + .create(); + dialog.show(); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -234,6 +280,9 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { case MENU_REFRESH: refreshCatalogsList(); return true; + case MENU_LANGUAGE_FILTER: + runLanguageFilterDialog(); + return true; default: return true; } diff --git a/src/org/geometerplus/android/fbreader/network/NetworkView.java b/src/org/geometerplus/android/fbreader/network/NetworkView.java index e058f7da5..ea06579c8 100644 --- a/src/org/geometerplus/android/fbreader/network/NetworkView.java +++ b/src/org/geometerplus/android/fbreader/network/NetworkView.java @@ -199,7 +199,6 @@ class NetworkView { */ private static class MinPriorityThreadFactory implements ThreadFactory { - private final ThreadFactory myDefaultThreadFactory = Executors.defaultThreadFactory(); public Thread newThread(Runnable r) { diff --git a/src/org/geometerplus/android/fbreader/preferences/BookInfoActivity.java b/src/org/geometerplus/android/fbreader/preferences/BookInfoActivity.java index 76ebbea1d..53bc44a59 100644 --- a/src/org/geometerplus/android/fbreader/preferences/BookInfoActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/BookInfoActivity.java @@ -19,7 +19,7 @@ package org.geometerplus.android.fbreader.preferences; -import java.util.TreeMap; +import java.util.TreeSet; import android.content.Context; import android.content.Intent; @@ -54,21 +54,19 @@ class LanguagePreference extends ZLStringListPreference { LanguagePreference(Context context, ZLResource rootResource, String resourceKey, Book book) { super(context, rootResource, resourceKey); myBook = book; - final TreeMap map = new TreeMap(); - for (String code : ZLLanguageUtil.languageCodes()) { - map.put(ZLLanguageUtil.languageName(code), code); - } - final int size = map.size(); - String[] codes = new String[size + 1]; - String[] names = new String[size + 1]; + final TreeSet set = new TreeSet(new ZLLanguageUtil.CodeComparator()); + set.addAll(ZLLanguageUtil.languageCodes()); + set.add(ZLLanguageUtil.OTHER_LANGUAGE_CODE); + + final int size = set.size(); + String[] codes = new String[size]; + String[] names = new String[size]; int index = 0; - for (TreeMap.Entry entry : map.entrySet()) { - codes[index] = entry.getValue(); - names[index] = entry.getKey(); + for (String code : set) { + codes[index] = code; + names[index] = ZLLanguageUtil.languageName(code); ++index; } - codes[size] = ZLLanguageUtil.OTHER_LANGUAGE_CODE; - names[size] = ZLLanguageUtil.languageName(codes[size]); setLists(codes, names); String language = myBook.getLanguage(); if (language == null) { diff --git a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java index 15afd5759..eac8ac6d3 100644 --- a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java +++ b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java @@ -24,7 +24,7 @@ import java.io.*; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.encoding.ZLEncodingCollection; -import org.geometerplus.zlibrary.core.util.ZLLanguageUtil; +import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.fbreader.library.Book; import org.geometerplus.fbreader.bookmodel.BookModel; @@ -57,7 +57,7 @@ public class MobipocketPlugin extends PdbPlugin { final int fullNameOffset = (int)PdbUtil.readInt(stream); final int fullNameLength = (int)PdbUtil.readInt(stream); final int languageCode = (int)PdbUtil.readInt(stream); - book.setLanguage(ZLLanguageUtil.languageByCode(languageCode & 0xFF, (languageCode >> 8) & 0xFF)); + book.setLanguage(ZLLanguageUtil.languageByIntCode(languageCode & 0xFF, (languageCode >> 8) & 0xFF)); PdbUtil.skip(stream, 32); int offset = 132; if ((PdbUtil.readInt(stream) & 0x40) != 0) { diff --git a/src/org/geometerplus/fbreader/network/NetworkLibrary.java b/src/org/geometerplus/fbreader/network/NetworkLibrary.java index 178ec16be..f4565f66b 100644 --- a/src/org/geometerplus/fbreader/network/NetworkLibrary.java +++ b/src/org/geometerplus/fbreader/network/NetworkLibrary.java @@ -21,6 +21,7 @@ package org.geometerplus.fbreader.network; import java.util.*; +import org.geometerplus.zlibrary.core.library.ZLibrary; import org.geometerplus.zlibrary.core.util.ZLNetworkUtil; import org.geometerplus.zlibrary.core.options.ZLStringOption; import org.geometerplus.zlibrary.core.network.ZLNetworkManager; @@ -81,11 +82,71 @@ public class NetworkLibrary { void onNewLink(INetworkLink link); } - public final ZLStringOption NetworkSearchPatternOption = new ZLStringOption("NetworkSearch", "Pattern", ""); private final ArrayList myLinks = new ArrayList(); + public List languageCodes() { + final TreeSet languageSet = new TreeSet(); + for (INetworkLink link : myLinks) { + languageSet.add(link.getLanguage()); + } + return new ArrayList(languageSet); + } + + private ZLStringOption myActiveLanguageCodesOption; + private ZLStringOption activeLanguageCodesOption() { + if (myActiveLanguageCodesOption == null) { + final TreeSet defaultCodes = new TreeSet(new ZLLanguageUtil.CodeComparator()); + defaultCodes.addAll(ZLibrary.Instance().defaultLanguageCodes()); + myActiveLanguageCodesOption = + new ZLStringOption( + "Options", + "ActiveLanguages", + commaSeparatedString(defaultCodes) + ); + } + return myActiveLanguageCodesOption; + } + + public Collection activeLanguageCodes() { + return Arrays.asList(activeLanguageCodesOption().getValue().split(",")); + } + + public void setActiveLanguageCodes(Collection codes) { + final TreeSet allCodes = new TreeSet(new ZLLanguageUtil.CodeComparator()); + allCodes.addAll(ZLibrary.Instance().defaultLanguageCodes()); + allCodes.removeAll(languageCodes()); + allCodes.addAll(codes); + activeLanguageCodesOption().setValue(commaSeparatedString(allCodes)); + } + + private String commaSeparatedString(Collection codes) { + final StringBuilder builder = new StringBuilder(); + for (String code : codes) { + builder.append(code); + builder.append(","); + } + if (builder.length() > 0) { + builder.delete(builder.length() - 1, builder.length()); + } + return builder.toString(); + } + + private List activeLinks() { + final LinkedList filteredList = new LinkedList(); + final Collection codes = activeLanguageCodes(); + synchronized (myLinks) { + for (INetworkLink link : myLinks) { + if (link instanceof ICustomNetworkLink || + codes.contains(link.getLanguage())) { + filteredList.add(link); + } + } + } + return filteredList; + } + private final RootTree myRootTree = new RootTree(); private boolean myUpdateChildren = true; @@ -157,7 +218,7 @@ public class NetworkLibrary { toRemove.add(link); } } - myLinks.removeAll(myLinks); + myLinks.removeAll(toRemove); } } @@ -221,7 +282,7 @@ public class NetworkLibrary { public String rewriteUrl(String url, boolean externalUrl) { final String host = ZLNetworkUtil.hostFromUrl(url).toLowerCase(); synchronized (myLinks) { - for (INetworkLink link: myLinks) { + for (INetworkLink link : myLinks) { if (host.contains(link.getSiteName())) { url = link.rewriteUrl(url, externalUrl); } @@ -271,12 +332,10 @@ public class NetworkLibrary { int nodeCount = 0; synchronized (myLinks) { - Collections.sort(myLinks, new LinksComparator()); - for (int i = 0; i < myLinks.size(); ++i) { - INetworkLink link = myLinks.get(i); - /*if (!link.OnOption.getValue()) { - continue; - }*/ + final ArrayList links = new ArrayList(activeLinks()); + Collections.sort(links, new LinksComparator()); + for (int i = 0; i < links.size(); ++i) { + INetworkLink link = links.get(i); boolean processed = false; while (currentNode != null || nodeIterator.hasNext()) { if (currentNode == null) { @@ -299,8 +358,8 @@ public class NetworkLibrary { break; } else { INetworkLink newNodeLink = null; - for (int j = i; j < myLinks.size(); ++j) { - final INetworkLink jlnk = myLinks.get(j); + for (int j = i; j < links.size(); ++j) { + final INetworkLink jlnk = links.get(j); if (linksEqual(nodeLink, jlnk)) { newNodeLink = jlnk; break; @@ -334,13 +393,13 @@ public class NetworkLibrary { currentNode = null; } - for (FBTree tree: toRemove) { + for (FBTree tree : toRemove) { tree.removeSelf(); } } private void updateVisibility() { - for (FBTree tree: myRootTree.subTrees()) { + for (FBTree tree : myRootTree.subTrees()) { if (!(tree instanceof NetworkCatalogTree)) { continue; } @@ -382,10 +441,7 @@ public class NetworkLibrary { }; synchronized (myLinks) { - for (INetworkLink link: myLinks) { - //if (link.OnOption.getValue()) { - // execute next code only if link is enabled - //} + for (INetworkLink link : activeLinks()) { final NetworkOperationData data = link.createOperationData(link, synchronizedListener); final ZLNetworkRequest request = link.simpleSearchRequest(pattern, data); if (request != null) { @@ -403,7 +459,7 @@ public class NetworkLibrary { if (listener.confirmInterrupt()) { return; } - for (NetworkOperationData data: dataList) { + for (NetworkOperationData data : dataList) { ZLNetworkRequest request = data.resume(); if (request != null) { requestList.add(request); @@ -440,7 +496,7 @@ public class NetworkLibrary { public boolean hasCustomLinkTitle(String title, INetworkLink exceptFor) { synchronized (myLinks) { - for (INetworkLink link: myLinks) { + for (INetworkLink link : myLinks) { if (link != exceptFor && link.getTitle().equals(title)) { return true; } @@ -451,7 +507,7 @@ public class NetworkLibrary { public boolean hasCustomLinkSite(String siteName, INetworkLink exceptFor) { synchronized (myLinks) { - for (INetworkLink link: myLinks) { + for (INetworkLink link : myLinks) { if (link != exceptFor && link.getSiteName().equals(siteName)) { return true; } @@ -459,12 +515,4 @@ public class NetworkLibrary { } return false; } - - public List languages() { - final TreeSet languageSet = new TreeSet(); - for (INetworkLink link : myLinks) { - languageSet.add(link.getLanguage()); - } - return new ArrayList(languageSet); - } } diff --git a/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java b/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java index b9611b102..5c2600c7e 100644 --- a/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java +++ b/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java @@ -33,6 +33,33 @@ public abstract class ZLLanguageUtil { private ZLLanguageUtil() { } + public static class CodeComparator implements Comparator { + public int compare(String code0, String code1) { + if (code0 == null) { + return code1 == null ? 0 : -1; + } + if (code1 == null) { + return 1; + } + if (code0.equals(code1)) { + return 0; + } + if (MULTI_LANGUAGE_CODE.equals(code0)) { + return -1; + } + if (MULTI_LANGUAGE_CODE.equals(code1)) { + return 1; + } + if (OTHER_LANGUAGE_CODE.equals(code0)) { + return 1; + } + if (OTHER_LANGUAGE_CODE.equals(code1)) { + return -1; + } + return languageName(code0).compareTo(languageName(code1)); + } + } + public static List languageCodes() { if (ourLanguageCodes.isEmpty()) { TreeSet codes = new TreeSet(); @@ -60,4 +87,139 @@ public abstract class ZLLanguageUtil { public static ZLFile patternsFile() { return ZLResourceFile.createResourceFile("languagePatterns"); } + + public static String languageByIntCode(int languageCode, int subLanguageCode) { + switch (languageCode) { + default: return null; + case 0x01: return "ar"; // Arabic + case 0x02: return "bg"; // Bulgarian + case 0x03: return "ca"; // Catalan + case 0x04: return "zh"; // Chinese + case 0x05: return "cs"; // Czech + case 0x06: return "da"; // Danish + case 0x07: return "de"; // German + case 0x08: return "el"; // Greek + case 0x09: return "en"; // English + case 0x0A: return "es"; // Spanish + case 0x0B: return "fi"; // Finnish + case 0x0C: return "fr"; // French + case 0x0D: return "he"; // Hebrew + case 0x0E: return "hu"; // Hungarian + case 0x0F: return "is"; // Icelandic + case 0x10: return "it"; // Italian + case 0x11: return "ja"; // Japanese + case 0x12: return "ko"; // Korean + case 0x13: return "nl"; // Dutch + case 0x14: return "no"; // Norwegian + case 0x15: return "pl"; // Polish + case 0x16: return "pt"; // Portuguese + case 0x17: return "rm"; // Romansh + case 0x18: return "ro"; // Romanian + case 0x19: return "ru"; // Russian + case 0x1A: + switch (subLanguageCode) { + default: return "sr"; // Serbian + case 0x04: + case 0x10: return "hr"; // Croatian + case 0x14: + case 0x20: + case 0x78: return "bs"; // Bosnian + } + case 0x1B: return "sk"; // Slovak + case 0x1C: return "sq"; // Albanian + case 0x1D: return "sv"; // Swedish + case 0x1E: return "th"; // Thai + case 0x1F: return "tr"; // Turkish + case 0x20: return "ur"; // Urdu + case 0x21: return "id"; // Indonesian + case 0x22: return "uk"; // Ukrainian + case 0x23: return "be"; // Belarusian + case 0x24: return "sl"; // Slovenian + case 0x25: return "et"; // Estonian + case 0x26: return "lv"; // Latvian + case 0x27: return "lt"; // Lithuanian + case 0x28: return "tg"; // Tajik + case 0x29: return "fa"; // Persian (Farsi) + case 0x2A: return "vi"; // Vietnamese + case 0x2B: return "hy"; // Armenian + case 0x2C: return "az"; // Azeri + case 0x2D: return "eu"; // Basque + case 0x2E: return (subLanguageCode == 0x08) + ? "dsb" // Lower Sorbian + : "wen"; // Upper Sorbian + case 0x2F: return "mk"; // Makedonian + case 0x32: return "tn"; // Setswana/Tswana + case 0x34: return "xh"; // Xhosa/isiXhosa + case 0x35: return "zu"; // Zulu/isiZulu + case 0x36: return "af"; // Afrikaans + case 0x37: return "ka"; // Georgian + case 0x38: return "fo"; // Faeroese + case 0x39: return "hi"; // Hindi + case 0x3A: return "mt"; // Maltese + case 0x3B: return "se"; // Sami + case 0x3C: return "ga"; // Irish + case 0x3E: return "ms"; // Malay + case 0x3F: return "kk"; // Kazak + case 0x40: return "ky"; // Kyrgyz + case 0x41: return "sw"; // Swahili + case 0x42: return "tk"; // Turkmen + case 0x43: return "uz"; // Uzbek + case 0x44: return "tt"; // Tatar + case 0x45: return "bn"; // Bengali + case 0x46: return "pa"; // Punjabi + case 0x47: return "gu"; // Gujaratu + case 0x48: return "or"; // Oriya + case 0x49: return "ta"; // Tamil + case 0x4A: return "te"; // Telugi + case 0x4B: return "kn"; // Kannada + case 0x4C: return "ml"; // Malayalam + case 0x4D: return "as"; // Assamese + case 0x4E: return "mr"; // Marathi + case 0x4F: return "sa"; // Sanskrit + case 0x50: return "mn"; // Mongolian + case 0x51: return "bo"; // Tibetian + case 0x52: return "cy"; // Welsh + case 0x53: return "kh"; // Khmer + case 0x54: return "lo"; // Lao + case 0x56: return "gl"; // Galician + case 0x57: return "kok"; // Konkani + case 0x58: return "mni"; // Manipuri + case 0x59: return "sd"; // Sindhi + case 0x5A: return "syr"; // Syriac + case 0x5B: return "si"; // Sinhala + case 0x5D: return "iu"; // Inuktitut + case 0x5E: return "am"; // Amharic + case 0x5F: return "tzm"; // Tamazight + case 0x60: return "ks"; // Kashmiri + case 0x61: return "ne"; // Nepali + case 0x62: return "fy"; // Frisian + case 0x63: return "ps"; // Pashto + case 0x64: return "fil"; // Filipino + case 0x65: return "dv"; // Divehi + case 0x68: return "ha"; // Hausa + case 0x6A: return "yo"; // Yoruba + case 0x6B: return "quz"; // Quechua + case 0x6C: return "ns"; // Northern Sotho + case 0x6D: return "ba"; // Bashkir + case 0x6E: return "lb"; // Luxemburgish + case 0x6F: return "kl"; // Greenlandic + case 0x70: return "ig"; // Igbo + case 0x73: return "ti"; // Tigrinya + case 0x78: return "yi"; // Yi + case 0x7A: return "arn"; // Mapudungun + case 0x7C: return "moh"; // Mohawk + case 0x7E: return "be"; // Breton + case 0x80: return "ug"; // Uighur + case 0x81: return "mi"; // Maori + case 0x82: return "oc"; // Occitan + case 0x83: return "co"; // Corsican + case 0x84: return "gsw"; // Alsatian + case 0x85: return "sah"; // Yakut + case 0x86: return "qut"; // K'iche + case 0x87: return "rw"; // Kinyarwanda + case 0x88: return "wo"; // Wolof + case 0x8C: return "prs"; // Dari + case 0x8D: return "mg"; // Malagasy + } + } } diff --git a/src/org/geometerplus/zlibrary/core/library/ZLibrary.java b/src/org/geometerplus/zlibrary/core/library/ZLibrary.java index f270c858b..e010028aa 100644 --- a/src/org/geometerplus/zlibrary/core/library/ZLibrary.java +++ b/src/org/geometerplus/zlibrary/core/library/ZLibrary.java @@ -19,6 +19,8 @@ package org.geometerplus.zlibrary.core.library; +import java.util.Collection; + import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; public abstract class ZLibrary { @@ -41,4 +43,5 @@ public abstract class ZLibrary { abstract public int getScreenBrightness(); abstract public int getDisplayDPI(); abstract public void openInBrowser(String reference); + abstract public Collection defaultLanguageCodes(); } diff --git a/src/org/geometerplus/zlibrary/core/util/ZLLanguageUtil.java b/src/org/geometerplus/zlibrary/core/util/ZLLanguageUtil.java deleted file mode 100644 index 2c28381c5..000000000 --- a/src/org/geometerplus/zlibrary/core/util/ZLLanguageUtil.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2008-2010 Geometer Plus - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -package org.geometerplus.zlibrary.core.util; - -public abstract class ZLLanguageUtil { - public static String languageByCode(int languageCode, int subLanguageCode) { - switch (languageCode) { - default: return null; - case 0x01: return "ar"; // Arabic - case 0x02: return "bg"; // Bulgarian - case 0x03: return "ca"; // Catalan - case 0x04: return "zh"; // Chinese - case 0x05: return "cs"; // Czech - case 0x06: return "da"; // Danish - case 0x07: return "de"; // German - case 0x08: return "el"; // Greek - case 0x09: return "en"; // English - case 0x0A: return "es"; // Spanish - case 0x0B: return "fi"; // Finnish - case 0x0C: return "fr"; // French - case 0x0D: return "he"; // Hebrew - case 0x0E: return "hu"; // Hungarian - case 0x0F: return "is"; // Icelandic - case 0x10: return "it"; // Italian - case 0x11: return "ja"; // Japanese - case 0x12: return "ko"; // Korean - case 0x13: return "nl"; // Dutch - case 0x14: return "no"; // Norwegian - case 0x15: return "pl"; // Polish - case 0x16: return "pt"; // Portuguese - case 0x17: return "rm"; // Romansh - case 0x18: return "ro"; // Romanian - case 0x19: return "ru"; // Russian - case 0x1A: - switch (subLanguageCode) { - default: return "sr"; // Serbian - case 0x04: - case 0x10: return "hr"; // Croatian - case 0x14: - case 0x20: - case 0x78: return "bs"; // Bosnian - } - case 0x1B: return "sk"; // Slovak - case 0x1C: return "sq"; // Albanian - case 0x1D: return "sv"; // Swedish - case 0x1E: return "th"; // Thai - case 0x1F: return "tr"; // Turkish - case 0x20: return "ur"; // Urdu - case 0x21: return "id"; // Indonesian - case 0x22: return "uk"; // Ukrainian - case 0x23: return "be"; // Belarusian - case 0x24: return "sl"; // Slovenian - case 0x25: return "et"; // Estonian - case 0x26: return "lv"; // Latvian - case 0x27: return "lt"; // Lithuanian - case 0x28: return "tg"; // Tajik - case 0x29: return "fa"; // Persian (Farsi) - case 0x2A: return "vi"; // Vietnamese - case 0x2B: return "hy"; // Armenian - case 0x2C: return "az"; // Azeri - case 0x2D: return "eu"; // Basque - case 0x2E: return (subLanguageCode == 0x08) - ? "dsb" // Lower Sorbian - : "wen"; // Upper Sorbian - case 0x2F: return "mk"; // Makedonian - case 0x32: return "tn"; // Setswana/Tswana - case 0x34: return "xh"; // Xhosa/isiXhosa - case 0x35: return "zu"; // Zulu/isiZulu - case 0x36: return "af"; // Afrikaans - case 0x37: return "ka"; // Georgian - case 0x38: return "fo"; // Faeroese - case 0x39: return "hi"; // Hindi - case 0x3A: return "mt"; // Maltese - case 0x3B: return "se"; // Sami - case 0x3C: return "ga"; // Irish - case 0x3E: return "ms"; // Malay - case 0x3F: return "kk"; // Kazak - case 0x40: return "ky"; // Kyrgyz - case 0x41: return "sw"; // Swahili - case 0x42: return "tk"; // Turkmen - case 0x43: return "uz"; // Uzbek - case 0x44: return "tt"; // Tatar - case 0x45: return "bn"; // Bengali - case 0x46: return "pa"; // Punjabi - case 0x47: return "gu"; // Gujaratu - case 0x48: return "or"; // Oriya - case 0x49: return "ta"; // Tamil - case 0x4A: return "te"; // Telugi - case 0x4B: return "kn"; // Kannada - case 0x4C: return "ml"; // Malayalam - case 0x4D: return "as"; // Assamese - case 0x4E: return "mr"; // Marathi - case 0x4F: return "sa"; // Sanskrit - case 0x50: return "mn"; // Mongolian - case 0x51: return "bo"; // Tibetian - case 0x52: return "cy"; // Welsh - case 0x53: return "kh"; // Khmer - case 0x54: return "lo"; // Lao - case 0x56: return "gl"; // Galician - case 0x57: return "kok"; // Konkani - case 0x58: return "mni"; // Manipuri - case 0x59: return "sd"; // Sindhi - case 0x5A: return "syr"; // Syriac - case 0x5B: return "si"; // Sinhala - case 0x5D: return "iu"; // Inuktitut - case 0x5E: return "am"; // Amharic - case 0x5F: return "tzm"; // Tamazight - case 0x60: return "ks"; // Kashmiri - case 0x61: return "ne"; // Nepali - case 0x62: return "fy"; // Frisian - case 0x63: return "ps"; // Pashto - case 0x64: return "fil"; // Filipino - case 0x65: return "dv"; // Divehi - case 0x68: return "ha"; // Hausa - case 0x6A: return "yo"; // Yoruba - case 0x6B: return "quz"; // Quechua - case 0x6C: return "ns"; // Northern Sotho - case 0x6D: return "ba"; // Bashkir - case 0x6E: return "lb"; // Luxemburgish - case 0x6F: return "kl"; // Greenlandic - case 0x70: return "ig"; // Igbo - case 0x73: return "ti"; // Tigrinya - case 0x78: return "yi"; // Yi - case 0x7A: return "arn"; // Mapudungun - case 0x7C: return "moh"; // Mohawk - case 0x7E: return "be"; // Breton - case 0x80: return "ug"; // Uighur - case 0x81: return "mi"; // Maori - case 0x82: return "oc"; // Occitan - case 0x83: return "co"; // Corsican - case 0x84: return "gsw"; // Alsatian - case 0x85: return "sah"; // Yakut - case 0x86: return "qut"; // K'iche - case 0x87: return "rw"; // Kinyarwanda - case 0x88: return "wo"; // Wolof - case 0x8C: return "prs"; // Dari - case 0x8D: return "mg"; // Malagasy - } - } -} diff --git a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java index 2a32d0760..11e8cba42 100644 --- a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java +++ b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java @@ -24,8 +24,10 @@ import java.util.*; import android.app.Application; import android.content.res.AssetFileDescriptor; +import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.telephony.TelephonyManager; import android.text.format.DateFormat; import android.util.DisplayMetrics; @@ -141,6 +143,33 @@ public final class ZLAndroidLibrary extends ZLibrary { return (int)(160 * metrics.density); } + @Override + public Collection defaultLanguageCodes() { + final TreeSet set = new TreeSet(); + set.add(Locale.getDefault().getLanguage()); + final TelephonyManager manager = (TelephonyManager)myApplication.getSystemService(Context.TELEPHONY_SERVICE); + if (manager != null) { + final String country0 = manager.getSimCountryIso().toLowerCase(); + final String country1 = manager.getNetworkCountryIso().toLowerCase(); + for (Locale locale : Locale.getAvailableLocales()) { + final String country = locale.getCountry().toLowerCase(); + if (country != null && country.length() > 0 && + (country.equals(country0) || country.equals(country1))) { + set.add(locale.getLanguage()); + } + } + if ("ru".equals(country0) || "ru".equals(country1)) { + set.add("ru"); + } else if ("by".equals(country0) || "by".equals(country1)) { + set.add("ru"); + } else if ("ua".equals(country0) || "ua".equals(country1)) { + set.add("ru"); + } + } + set.add("multi"); + return set; + } + private final class AndroidAssetsFile extends ZLResourceFile { private final AndroidAssetsFile myParent;