diff --git a/ChangeLog b/ChangeLog index 733f28192..22dd07e7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ ===== 1.7.4 (Mar ??, 2013) ===== * Book/bookmark deserializer: SAX instead of our own XML parser * Georgian localization (by Bookland.ge) +* Interface language option ===== 1.7.3 (Mar 04, 2013) ===== * Library service does not work in background after program closing diff --git a/assets/data/help/MiniHelp.ka.fb2 b/assets/data/help/MiniHelp.ka.fb2 index fdeb54727..b8755840b 100644 --- a/assets/data/help/MiniHelp.ka.fb2 +++ b/assets/data/help/MiniHelp.ka.fb2 @@ -12,5 +12,6 @@

უფრო მეტი ინფორმაციისთვის პროგრამა FBReader-ის შესახებ, ასევე, სხვადასხვა მოწყობილობებისთვის ვერსიების გადმოსაწერად ეწვიეთჩვენ საიტს.

შეტყობინებეი ახალი ვერსიების და სხვა ინფორმაციების შესახებ ქვეყნდება twitter'ზე.

თუ გსურთ ავტორებთან დაკავშირება, მოგვწერეთ ელექტრონული წერილი.

+

ქართული თარგმანის ავტორია კომპანია წიგნის სამყარო www.bookland.ge.

diff --git a/assets/resources/application/be.xml b/assets/resources/application/be.xml index 795473053..91e19bf6f 100644 --- a/assets/resources/application/be.xml +++ b/assets/resources/application/be.xml @@ -288,6 +288,7 @@ + @@ -322,8 +323,8 @@ - - + + diff --git a/assets/resources/application/bg.xml b/assets/resources/application/bg.xml index b0cb27f7c..6db75a48f 100644 --- a/assets/resources/application/bg.xml +++ b/assets/resources/application/bg.xml @@ -287,6 +287,7 @@ + diff --git a/assets/resources/application/ca.xml b/assets/resources/application/ca.xml index 05e0b0c5b..2f942a034 100644 --- a/assets/resources/application/ca.xml +++ b/assets/resources/application/ca.xml @@ -286,6 +286,7 @@ + diff --git a/assets/resources/application/cs.xml b/assets/resources/application/cs.xml index f8cbf547c..9ed60b3e6 100644 --- a/assets/resources/application/cs.xml +++ b/assets/resources/application/cs.xml @@ -291,6 +291,7 @@ + diff --git a/assets/resources/application/de.xml b/assets/resources/application/de.xml index 5d53b2093..14915a37d 100644 --- a/assets/resources/application/de.xml +++ b/assets/resources/application/de.xml @@ -276,6 +276,7 @@ + diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml index 152f0e78f..c246360cf 100644 --- a/assets/resources/application/en.xml +++ b/assets/resources/application/en.xml @@ -282,6 +282,7 @@ + diff --git a/assets/resources/application/es.xml b/assets/resources/application/es.xml index 1b1c7f2db..5de9d5186 100644 --- a/assets/resources/application/es.xml +++ b/assets/resources/application/es.xml @@ -286,6 +286,7 @@ + diff --git a/assets/resources/application/fr.xml b/assets/resources/application/fr.xml index 6e4a9de07..4446f926a 100644 --- a/assets/resources/application/fr.xml +++ b/assets/resources/application/fr.xml @@ -275,6 +275,7 @@ + diff --git a/assets/resources/application/gl.xml b/assets/resources/application/gl.xml index be608cd81..91a1ad9f7 100644 --- a/assets/resources/application/gl.xml +++ b/assets/resources/application/gl.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/hu.xml b/assets/resources/application/hu.xml index d6bdf0bf4..60205c5f3 100644 --- a/assets/resources/application/hu.xml +++ b/assets/resources/application/hu.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/it.xml b/assets/resources/application/it.xml index 897f48d24..efbd53ddf 100644 --- a/assets/resources/application/it.xml +++ b/assets/resources/application/it.xml @@ -273,6 +273,7 @@ + diff --git a/assets/resources/application/ka.xml b/assets/resources/application/ka.xml index a423f8e97..9579bcc91 100644 --- a/assets/resources/application/ka.xml +++ b/assets/resources/application/ka.xml @@ -287,6 +287,7 @@ + diff --git a/assets/resources/application/nb.xml b/assets/resources/application/nb.xml index a85fde890..32bad393c 100644 --- a/assets/resources/application/nb.xml +++ b/assets/resources/application/nb.xml @@ -282,6 +282,7 @@ + diff --git a/assets/resources/application/nl.xml b/assets/resources/application/nl.xml index 2b16f87da..0db3256b1 100644 --- a/assets/resources/application/nl.xml +++ b/assets/resources/application/nl.xml @@ -282,6 +282,7 @@ + diff --git a/assets/resources/application/pl.xml b/assets/resources/application/pl.xml index ce6d7f1c7..c93974538 100644 --- a/assets/resources/application/pl.xml +++ b/assets/resources/application/pl.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/pt.xml b/assets/resources/application/pt.xml index b2c2f60be..f7064b275 100644 --- a/assets/resources/application/pt.xml +++ b/assets/resources/application/pt.xml @@ -284,6 +284,7 @@ + diff --git a/assets/resources/application/ro.xml b/assets/resources/application/ro.xml index 657d5ffff..48c5aaa55 100644 --- a/assets/resources/application/ro.xml +++ b/assets/resources/application/ro.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/ru.xml b/assets/resources/application/ru.xml index dc3da156f..4eed68b5c 100644 --- a/assets/resources/application/ru.xml +++ b/assets/resources/application/ru.xml @@ -287,6 +287,7 @@ + diff --git a/assets/resources/application/sr.xml b/assets/resources/application/sr.xml index b9dea9643..92d7e5c5e 100644 --- a/assets/resources/application/sr.xml +++ b/assets/resources/application/sr.xml @@ -282,6 +282,7 @@ + diff --git a/assets/resources/application/th.xml b/assets/resources/application/th.xml index 2b730b48d..276fca7ea 100644 --- a/assets/resources/application/th.xml +++ b/assets/resources/application/th.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/tr.xml b/assets/resources/application/tr.xml index 323bbfa9b..05265f483 100644 --- a/assets/resources/application/tr.xml +++ b/assets/resources/application/tr.xml @@ -282,6 +282,7 @@ + diff --git a/assets/resources/application/uk.xml b/assets/resources/application/uk.xml index fa2200126..bbb04d104 100644 --- a/assets/resources/application/uk.xml +++ b/assets/resources/application/uk.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/vi.xml b/assets/resources/application/vi.xml index 196a9ba26..b3e749b2d 100644 --- a/assets/resources/application/vi.xml +++ b/assets/resources/application/vi.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/zh.xml b/assets/resources/application/zh.xml index 95aa473df..e7b53f01f 100644 --- a/assets/resources/application/zh.xml +++ b/assets/resources/application/zh.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/application/zh_TW.xml b/assets/resources/application/zh_TW.xml index 509133f9c..d16b733e4 100644 --- a/assets/resources/application/zh_TW.xml +++ b/assets/resources/application/zh_TW.xml @@ -272,6 +272,7 @@ + diff --git a/assets/resources/lang.xml b/assets/resources/lang.xml new file mode 100644 index 000000000..c62661712 --- /dev/null +++ b/assets/resources/lang.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/resources/zlibrary/be.xml b/assets/resources/zlibrary/be.xml index 0e2247a94..f602ca100 100644 --- a/assets/resources/zlibrary/be.xml +++ b/assets/resources/zlibrary/be.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/bg.xml b/assets/resources/zlibrary/bg.xml index 469e4e414..f557766ee 100644 --- a/assets/resources/zlibrary/bg.xml +++ b/assets/resources/zlibrary/bg.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/ca.xml b/assets/resources/zlibrary/ca.xml index d5401558b..3e5311bc9 100644 --- a/assets/resources/zlibrary/ca.xml +++ b/assets/resources/zlibrary/ca.xml @@ -68,6 +68,7 @@ + diff --git a/assets/resources/zlibrary/cs.xml b/assets/resources/zlibrary/cs.xml index 694ad310e..2a135c37d 100644 --- a/assets/resources/zlibrary/cs.xml +++ b/assets/resources/zlibrary/cs.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/de.xml b/assets/resources/zlibrary/de.xml index 61a264eaa..eac0e9f62 100644 --- a/assets/resources/zlibrary/de.xml +++ b/assets/resources/zlibrary/de.xml @@ -67,6 +67,7 @@ + diff --git a/assets/resources/zlibrary/en.xml b/assets/resources/zlibrary/en.xml index 93c84f19b..7483f022a 100644 --- a/assets/resources/zlibrary/en.xml +++ b/assets/resources/zlibrary/en.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/es.xml b/assets/resources/zlibrary/es.xml index 5597cd548..53b27cdb9 100644 --- a/assets/resources/zlibrary/es.xml +++ b/assets/resources/zlibrary/es.xml @@ -69,6 +69,7 @@ + diff --git a/assets/resources/zlibrary/fr.xml b/assets/resources/zlibrary/fr.xml index 7156a53b4..52a62c274 100644 --- a/assets/resources/zlibrary/fr.xml +++ b/assets/resources/zlibrary/fr.xml @@ -69,6 +69,7 @@ + diff --git a/assets/resources/zlibrary/gl.xml b/assets/resources/zlibrary/gl.xml index 8ba379990..3d5d0f3ac 100644 --- a/assets/resources/zlibrary/gl.xml +++ b/assets/resources/zlibrary/gl.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/hu.xml b/assets/resources/zlibrary/hu.xml index f33135c07..bf50a7790 100644 --- a/assets/resources/zlibrary/hu.xml +++ b/assets/resources/zlibrary/hu.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/it.xml b/assets/resources/zlibrary/it.xml index 2ad77c76e..7999a6bf3 100644 --- a/assets/resources/zlibrary/it.xml +++ b/assets/resources/zlibrary/it.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/ka.xml b/assets/resources/zlibrary/ka.xml index 5c40183f4..2e7879a1d 100644 --- a/assets/resources/zlibrary/ka.xml +++ b/assets/resources/zlibrary/ka.xml @@ -47,7 +47,7 @@ - + @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/nb.xml b/assets/resources/zlibrary/nb.xml index 065b1c42a..b722e61e3 100644 --- a/assets/resources/zlibrary/nb.xml +++ b/assets/resources/zlibrary/nb.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/nl.xml b/assets/resources/zlibrary/nl.xml index 0cb582332..339480ead 100644 --- a/assets/resources/zlibrary/nl.xml +++ b/assets/resources/zlibrary/nl.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/pl.xml b/assets/resources/zlibrary/pl.xml index ea435bf49..1ca63a534 100644 --- a/assets/resources/zlibrary/pl.xml +++ b/assets/resources/zlibrary/pl.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/pt.xml b/assets/resources/zlibrary/pt.xml index c558ecaef..68ebf7fa4 100644 --- a/assets/resources/zlibrary/pt.xml +++ b/assets/resources/zlibrary/pt.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/ro.xml b/assets/resources/zlibrary/ro.xml index 4d3cd8727..15f20d2e4 100644 --- a/assets/resources/zlibrary/ro.xml +++ b/assets/resources/zlibrary/ro.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/ru.xml b/assets/resources/zlibrary/ru.xml index 3dac9fe4e..0e40bfdc0 100644 --- a/assets/resources/zlibrary/ru.xml +++ b/assets/resources/zlibrary/ru.xml @@ -64,6 +64,7 @@ + diff --git a/assets/resources/zlibrary/sr.xml b/assets/resources/zlibrary/sr.xml index 3405d3985..0fbfefe7c 100644 --- a/assets/resources/zlibrary/sr.xml +++ b/assets/resources/zlibrary/sr.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/th.xml b/assets/resources/zlibrary/th.xml index 142cc96bc..f941bc3c0 100644 --- a/assets/resources/zlibrary/th.xml +++ b/assets/resources/zlibrary/th.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/tr.xml b/assets/resources/zlibrary/tr.xml index 239429928..9fcbb186f 100644 --- a/assets/resources/zlibrary/tr.xml +++ b/assets/resources/zlibrary/tr.xml @@ -58,12 +58,13 @@ - + + diff --git a/assets/resources/zlibrary/uk.xml b/assets/resources/zlibrary/uk.xml index 770911c28..563491a4f 100644 --- a/assets/resources/zlibrary/uk.xml +++ b/assets/resources/zlibrary/uk.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/vi.xml b/assets/resources/zlibrary/vi.xml index b597bf2c9..b6f4b2afe 100644 --- a/assets/resources/zlibrary/vi.xml +++ b/assets/resources/zlibrary/vi.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/zh.xml b/assets/resources/zlibrary/zh.xml index a686b47f0..15feba638 100644 --- a/assets/resources/zlibrary/zh.xml +++ b/assets/resources/zlibrary/zh.xml @@ -65,6 +65,7 @@ + diff --git a/assets/resources/zlibrary/zh_TW.xml b/assets/resources/zlibrary/zh_TW.xml index e5ed71f27..c4f64fe83 100644 --- a/assets/resources/zlibrary/zh_TW.xml +++ b/assets/resources/zlibrary/zh_TW.xml @@ -65,6 +65,7 @@ + diff --git a/scripts/resources/update.sh b/scripts/resources/update.sh index 787ca5841..4eed0f741 100755 --- a/scripts/resources/update.sh +++ b/scripts/resources/update.sh @@ -8,6 +8,7 @@ fi for file in ../../assets/resources/$part/*.xml; do xsltproc clean.xslt $file > `basename $file`; + egrep "[^%]%[^%s01]" $file done for file in *.xml; do diff $file en.xml > `basename $file .xml`.diff; diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java index 5fa977d58..235a9f6de 100644 --- a/src/org/geometerplus/android/fbreader/FBReader.java +++ b/src/org/geometerplus/android/fbreader/FBReader.java @@ -529,6 +529,7 @@ public final class FBReader extends Activity { case REQUEST_PREFERENCES: case REQUEST_BOOK_INFO: if (resultCode != RESULT_DO_NOTHING) { + invalidateOptionsMenu(); final Book book = BookInfoActivity.bookByIntent(data); if (book != null) { getCollection().bindToService(this, new Runnable() { diff --git a/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java b/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java index 39d6ac836..84b3ab600 100644 --- a/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java +++ b/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java @@ -39,6 +39,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile; import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.image.ZLLoadableImage; import org.geometerplus.zlibrary.core.resources.ZLResource; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.ui.android.R; @@ -261,9 +262,9 @@ public class BookInfoActivity extends Activity { setupInfoPair(R.id.book_tags, "tags", buffer, tagNames.size()); String language = book.getLanguage(); if (!ZLLanguageUtil.languageCodes().contains(language)) { - language = ZLLanguageUtil.OTHER_LANGUAGE_CODE; + language = Language.OTHER_CODE; } - setupInfoPair(R.id.book_language, "language", ZLLanguageUtil.languageName(language)); + setupInfoPair(R.id.book_language, "language", new Language(language).Name); } private void setupAnnotation(Book book) { diff --git a/src/org/geometerplus/android/fbreader/network/action/LanguageFilterAction.java b/src/org/geometerplus/android/fbreader/network/action/LanguageFilterAction.java index 2794ecec6..3885ca59b 100644 --- a/src/org/geometerplus/android/fbreader/network/action/LanguageFilterAction.java +++ b/src/org/geometerplus/android/fbreader/network/action/LanguageFilterAction.java @@ -25,6 +25,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.core.resources.ZLResource; @@ -42,16 +43,20 @@ public class LanguageFilterAction extends RootAction { public void run(NetworkTree tree) { final NetworkLibrary library = NetworkLibrary.Instance(); - final List allLanguageCodes = library.languageCodes(); - Collections.sort(allLanguageCodes, new ZLLanguageUtil.CodeComparator()); + final List allLanguages = new ArrayList(); + for (String code : library.languageCodes()) { + allLanguages.add(new Language(code)); + } + Collections.sort(allLanguages); final Collection activeLanguageCodes = library.activeLanguageCodes(); - final CharSequence[] languageNames = new CharSequence[allLanguageCodes.size()]; - final boolean[] checked = new boolean[allLanguageCodes.size()]; + final CharSequence[] languageNames = new CharSequence[allLanguages.size()]; + final boolean[] checked = new boolean[allLanguages.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); + int index = 0; + for (Language language : allLanguages) { + languageNames[index] = language.Name; + checked[index] = activeLanguageCodes.contains(language.Code); + ++index; } final DialogInterface.OnMultiChoiceClickListener listener = @@ -66,13 +71,17 @@ public class LanguageFilterAction extends RootAction { .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()); + final TreeSet newActiveLanguages = new TreeSet(); for (int i = 0; i < checked.length; ++i) { if (checked[i]) { - newActiveCodes.add(allLanguageCodes.get(i)); + newActiveLanguages.add(allLanguages.get(i)); } } - library.setActiveLanguageCodes(newActiveCodes); + final List codes = new ArrayList(newActiveLanguages.size()); + for (Language language : newActiveLanguages) { + codes.add(language.Code); + } + library.setActiveLanguageCodes(codes); library.synchronize(); } }) diff --git a/src/org/geometerplus/android/fbreader/preferences/EditBookInfoActivity.java b/src/org/geometerplus/android/fbreader/preferences/EditBookInfoActivity.java index 243f96b8f..129456c69 100644 --- a/src/org/geometerplus/android/fbreader/preferences/EditBookInfoActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/EditBookInfoActivity.java @@ -26,6 +26,7 @@ import android.content.Intent; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.encodings.Encoding; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.core.resources.ZLResource; @@ -57,40 +58,35 @@ class BookTitlePreference extends ZLStringPreference { } } -class LanguagePreference extends ZLStringListPreference { +class BookLanguagePreference extends LanguagePreference { private final Book myBook; - LanguagePreference(Context context, ZLResource rootResource, String resourceKey, Book book) { - super(context, rootResource, resourceKey); - myBook = book; - final TreeSet set = new TreeSet(new ZLLanguageUtil.CodeComparator()); - set.addAll(ZLTextHyphenator.Instance().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 (String code : set) { - codes[index] = code; - names[index] = ZLLanguageUtil.languageName(code); - ++index; + private static List languages() { + final TreeSet set = new TreeSet(); + for (String code : ZLTextHyphenator.Instance().languageCodes()) { + set.add(new Language(code)); } - setLists(codes, names); + set.add(new Language(Language.OTHER_CODE)); + return new ArrayList(set); + } + + BookLanguagePreference(Context context, ZLResource rootResource, String resourceKey, Book book) { + super(context, rootResource, resourceKey, languages()); + myBook = book; final String language = myBook.getLanguage(); if (language == null || !setInitialValue(language)) { - setInitialValue(ZLLanguageUtil.OTHER_LANGUAGE_CODE); + setInitialValue(Language.OTHER_CODE); } } @Override - protected void onDialogClosed(boolean result) { - super.onDialogClosed(result); - if (result) { - final String value = getValue(); - myBook.setLanguage(value.length() > 0 ? value : null); - ((EditBookInfoActivity)getContext()).updateResult(); - } + protected void init() { + } + + @Override + protected void setLanguage(String code) { + myBook.setLanguage(code.length() > 0 ? code : null); + ((EditBookInfoActivity)getContext()).updateResult(); } } @@ -186,7 +182,7 @@ public class EditBookInfoActivity extends ZLPreferenceActivity { myInitialized = true; addPreference(new BookTitlePreference(EditBookInfoActivity.this, Resource, "title", myBook)); - addPreference(new LanguagePreference(EditBookInfoActivity.this, Resource, "language", myBook)); + addPreference(new BookLanguagePreference(EditBookInfoActivity.this, Resource, "language", myBook)); addPreference(new EncodingPreference(EditBookInfoActivity.this, Resource, "encoding", myBook)); } }); diff --git a/src/org/geometerplus/android/fbreader/preferences/LanguagePreference.java b/src/org/geometerplus/android/fbreader/preferences/LanguagePreference.java new file mode 100644 index 000000000..fc1767fdf --- /dev/null +++ b/src/org/geometerplus/android/fbreader/preferences/LanguagePreference.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2009-2013 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.android.fbreader.preferences; + +import java.util.*; + +import android.content.Context; + +import org.geometerplus.zlibrary.core.language.Language; +import org.geometerplus.zlibrary.core.resources.ZLResource; + +abstract class LanguagePreference extends ZLStringListPreference { + LanguagePreference( + Context context, ZLResource rootResource, String resourceKey, List languages + ) { + super(context, rootResource, resourceKey); + + final int size = languages.size(); + String[] codes = new String[size]; + String[] names = new String[size]; + int index = 0; + for (Language l : languages) { + codes[index] = l.Code; + names[index] = l.Name; + ++index; + } + setLists(codes, names); + init(); + } + + @Override + protected void onDialogClosed(boolean result) { + super.onDialogClosed(result); + if (result) { + setLanguage(getValue()); + } + } + + protected abstract void init(); + protected abstract void setLanguage(String code); +} diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index e38fd049b..cb9d4e593 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -20,11 +20,13 @@ package org.geometerplus.android.fbreader.preferences; import android.content.Intent; +import android.net.Uri; import android.view.KeyEvent; import org.geometerplus.zlibrary.core.application.ZLKeyBindings; import org.geometerplus.zlibrary.core.options.ZLIntegerOption; import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption; +import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.text.view.style.*; @@ -83,6 +85,24 @@ public class PreferenceActivity extends ZLPreferenceActivity { directoriesScreen.addOption(Paths.WallpapersDirectoryOption(), "wallpapers"); final Screen appearanceScreen = createPreferenceScreen("appearance"); + appearanceScreen.addPreference(new LanguagePreference( + this, appearanceScreen.Resource, "language", ZLResource.languages() + ) { + @Override + protected void init() { + setInitialValue(ZLResource.LanguageOption.getValue()); + } + + @Override + protected void setLanguage(String code) { + if (!code.equals(ZLResource.LanguageOption.getValue())) { + ZLResource.LanguageOption.setValue(code); + startActivity(new Intent( + Intent.ACTION_VIEW, Uri.parse("fbreader-action:preferences#appearance") + )); + } + } + }); appearanceScreen.addPreference(new ZLStringChoicePreference( this, appearanceScreen.Resource, "screenOrientation", androidLibrary.OrientationOption, androidLibrary.allOrientations() diff --git a/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java b/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java index e7492cab9..03139d689 100644 --- a/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java +++ b/src/org/geometerplus/fbreader/network/AbstractNetworkLink.java @@ -21,7 +21,7 @@ package org.geometerplus.fbreader.network; import java.util.*; -import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.network.ZLNetworkRequest; import org.geometerplus.fbreader.network.urlInfo.*; @@ -141,7 +141,7 @@ public abstract class AbstractNetworkLink implements INetworkLink { } private static int getLanguageOrder(String language) { - if (ZLLanguageUtil.MULTI_LANGUAGE_CODE.equals(language)) { + if (Language.MULTI_CODE.equals(language)) { return 1; } if (language.equals(Locale.getDefault().getLanguage())) { diff --git a/src/org/geometerplus/fbreader/network/NetworkLibrary.java b/src/org/geometerplus/fbreader/network/NetworkLibrary.java index 2e61ec8a1..4468707d0 100644 --- a/src/org/geometerplus/fbreader/network/NetworkLibrary.java +++ b/src/org/geometerplus/fbreader/network/NetworkLibrary.java @@ -26,8 +26,10 @@ import org.geometerplus.zlibrary.core.library.ZLibrary; import org.geometerplus.zlibrary.core.util.ZLNetworkUtil; import org.geometerplus.zlibrary.core.util.MimeType; import org.geometerplus.zlibrary.core.image.ZLImage; +import org.geometerplus.zlibrary.core.options.ZLStringListOption; import org.geometerplus.zlibrary.core.options.ZLStringOption; import org.geometerplus.zlibrary.core.network.ZLNetworkException; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.core.resources.ZLResource; @@ -99,44 +101,42 @@ public class NetworkLibrary { return new ArrayList(languageSet); } - private ZLStringOption myActiveLanguageCodesOption; - private ZLStringOption activeLanguageCodesOption() { + private ZLStringListOption myActiveLanguageCodesOption; + private ZLStringListOption activeLanguageCodesOption() { if (myActiveLanguageCodesOption == null) { - final TreeSet defaultCodes = new TreeSet(new ZLLanguageUtil.CodeComparator()); - defaultCodes.addAll(ZLibrary.Instance().defaultLanguageCodes()); myActiveLanguageCodesOption = - new ZLStringOption( + new ZLStringListOption( "Options", "ActiveLanguages", - commaSeparatedString(defaultCodes) + ZLibrary.Instance().defaultLanguageCodes(), + "," ); } return myActiveLanguageCodesOption; } - public Collection activeLanguageCodes() { - return Arrays.asList(activeLanguageCodesOption().getValue().split(",")); + public List activeLanguageCodes() { + return activeLanguageCodesOption().getValue(); } public void setActiveLanguageCodes(Collection codes) { - final TreeSet allCodes = new TreeSet(new ZLLanguageUtil.CodeComparator()); + final TreeSet allCodes = new TreeSet(); allCodes.addAll(ZLibrary.Instance().defaultLanguageCodes()); allCodes.removeAll(languageCodes()); allCodes.addAll(codes); - activeLanguageCodesOption().setValue(commaSeparatedString(allCodes)); - invalidateChildren(); - } - private String commaSeparatedString(Collection codes) { - final StringBuilder builder = new StringBuilder(); - for (String code : codes) { - builder.append(code); - builder.append(","); + // sort codes + final TreeSet languages = new TreeSet(); + for (String code : allCodes) { + languages.add(new Language(code)); } - if (builder.length() > 0) { - builder.delete(builder.length() - 1, builder.length()); + final ArrayList codesList = new ArrayList(languages.size()); + for (Language l : languages) { + codesList.add(l.Code); } - return builder.toString(); + + activeLanguageCodesOption().setValue(codesList); + invalidateChildren(); } List activeLinks() { diff --git a/src/org/geometerplus/zlibrary/core/language/Language.java b/src/org/geometerplus/zlibrary/core/language/Language.java new file mode 100644 index 000000000..fcd151f18 --- /dev/null +++ b/src/org/geometerplus/zlibrary/core/language/Language.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2009-2013 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.language; + +import org.geometerplus.zlibrary.core.resources.ZLResource; + +public class Language implements Comparable { + public static final String OTHER_CODE = "other"; + public static final String MULTI_CODE = "multi"; + public static final String SYSTEM_CODE = "system"; + + private static enum Order { + Before, + Normal, + After + } + + public final String Code; + public final String Name; + private final String mySortKey; + private final Order myOrder; + + public Language(String code) { + this(code, ZLResource.resource("language").getResource(code).getValue()); + } + + public Language(String code, String name) { + Code = code; + Name = name; + mySortKey = name; + if (SYSTEM_CODE.equals(code)) { + myOrder = Order.Before; + } else if (MULTI_CODE.equals(code) || OTHER_CODE.equals(code)) { + myOrder = Order.After; + } else { + myOrder = Order.Normal; + } + } + + public int compareTo(Language other) { + final int diff = myOrder.compareTo(other.myOrder); + return diff != 0 ? diff : mySortKey.compareTo(other.mySortKey); + } + + @Override + public boolean equals(Object lang) { + if (this == lang) { + return true; + } + if (!(lang instanceof Language)) { + return false; + } + return Code.equals(((Language)lang).Code); + } + + @Override + public int hashCode() { + return Code.hashCode(); + } +} diff --git a/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java b/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java index 86a005704..4722dec9e 100644 --- a/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java +++ b/src/org/geometerplus/zlibrary/core/language/ZLLanguageUtil.java @@ -25,41 +25,11 @@ import org.geometerplus.zlibrary.core.filesystem.*; import org.geometerplus.zlibrary.core.resources.ZLResource; public abstract class ZLLanguageUtil { - public static final String OTHER_LANGUAGE_CODE = "other"; - public static final String MULTI_LANGUAGE_CODE = "multi"; - private static ArrayList ourLanguageCodes = new ArrayList(); 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 String defaultLanguageCode() { return Locale.getDefault().getLanguage(); } @@ -86,10 +56,6 @@ public abstract class ZLLanguageUtil { return Collections.unmodifiableList(ourLanguageCodes); } - public static String languageName(String code) { - return ZLResource.resource("language").getResource(code).getValue(); - } - public static ZLFile patternsFile() { return ZLResourceFile.createResourceFile("languagePatterns"); } diff --git a/src/org/geometerplus/zlibrary/core/library/ZLibrary.java b/src/org/geometerplus/zlibrary/core/library/ZLibrary.java index debd1ab13..ac89a4cf1 100644 --- a/src/org/geometerplus/zlibrary/core/library/ZLibrary.java +++ b/src/org/geometerplus/zlibrary/core/library/ZLibrary.java @@ -19,7 +19,7 @@ package org.geometerplus.zlibrary.core.library; -import java.util.Collection; +import java.util.List; import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; import org.geometerplus.zlibrary.core.options.ZLStringOption; @@ -55,7 +55,7 @@ public abstract class ZLibrary { abstract public int getDisplayDPI(); abstract public int getPixelWidth(); abstract public int getPixelHeight(); - abstract public Collection defaultLanguageCodes(); + abstract public List defaultLanguageCodes(); abstract public boolean supportsAllOrientations(); public String[] allOrientations() { diff --git a/src/org/geometerplus/zlibrary/core/resources/ZLResource.java b/src/org/geometerplus/zlibrary/core/resources/ZLResource.java index d7b52db83..86e25a868 100644 --- a/src/org/geometerplus/zlibrary/core/resources/ZLResource.java +++ b/src/org/geometerplus/zlibrary/core/resources/ZLResource.java @@ -19,9 +19,37 @@ package org.geometerplus.zlibrary.core.resources; +import java.util.*; + +import org.geometerplus.zlibrary.core.filesystem.ZLFile; +import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; +import org.geometerplus.zlibrary.core.language.Language; +import org.geometerplus.zlibrary.core.options.ZLStringOption; + abstract public class ZLResource { public final String Name; + public static final ZLStringOption LanguageOption = + new ZLStringOption("LookNFeel", "Language", Language.SYSTEM_CODE); + + private static final List ourLanguages = new LinkedList(); + public static List languages() { + if (ourLanguages.isEmpty()) { + final ZLResource resource = ZLResource.resource("language-self"); + final ZLFile dir = ZLResourceFile.createResourceFile("resources/application"); + for (ZLFile file : dir.children()) { + final String name = file.getShortName(); + if (name.endsWith(".xml")) { + final String code = name.substring(0, name.length() - 4); + ourLanguages.add(new Language(code, resource.getResource(code).getValue())); + } + } + ourLanguages.add(new Language(Language.SYSTEM_CODE)); + Collections.sort(ourLanguages); + } + return Collections.unmodifiableList(ourLanguages); + } + public static ZLResource resource(String key) { ZLTreeResource.buildTree(); if (ZLTreeResource.ourRoot == null) { diff --git a/src/org/geometerplus/zlibrary/core/resources/ZLTreeResource.java b/src/org/geometerplus/zlibrary/core/resources/ZLTreeResource.java index b3dd110ec..db0ca1f76 100644 --- a/src/org/geometerplus/zlibrary/core/resources/ZLTreeResource.java +++ b/src/org/geometerplus/zlibrary/core/resources/ZLTreeResource.java @@ -21,9 +21,10 @@ package org.geometerplus.zlibrary.core.resources; import java.util.*; +import org.geometerplus.zlibrary.core.filesystem.*; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.xml.ZLStringMap; import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter; -import org.geometerplus.zlibrary.core.filesystem.*; final class ZLTreeResource extends ZLResource { private static interface Condition { @@ -132,20 +133,39 @@ final class ZLTreeResource extends ZLResource { } } + private static void setInterfaceLanguage() { + final String custom = LanguageOption.getValue(); + final String language; + final String country; + if (Language.SYSTEM_CODE.equals(custom)) { + final Locale locale = Locale.getDefault(); + language = locale.getLanguage(); + country = locale.getCountry(); + } else { + final int index = custom.indexOf('_'); + if (index == -1) { + language = custom; + country = null; + } else { + language = custom.substring(0, index); + country = custom.substring(index + 1); + } + } + if ((language != null && !language.equals(ourLanguage)) || + (country != null && !country.equals(ourCountry))) { + ourLanguage = language; + ourCountry = country; + loadData(); + } + } + private static void updateLanguage() { final long timeStamp = System.currentTimeMillis(); if (timeStamp > ourTimeStamp + 1000) { synchronized (ourLock) { if (timeStamp > ourTimeStamp + 1000) { ourTimeStamp = timeStamp; - final String language = Locale.getDefault().getLanguage(); - final String country = Locale.getDefault().getCountry(); - if ((language != null && !language.equals(ourLanguage)) || - (country != null && !country.equals(ourCountry))) { - ourLanguage = language; - ourCountry = country; - loadData(); - } + setInterfaceLanguage(); } } } @@ -154,6 +174,7 @@ final class ZLTreeResource extends ZLResource { private static void loadData(ResourceTreeReader reader, String fileName) { reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/zlibrary/" + fileName)); reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/application/" + fileName)); + reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/lang.xml")); } private static void loadData() { diff --git a/src/org/geometerplus/zlibrary/text/hyphenation/ZLTextTeXHyphenator.java b/src/org/geometerplus/zlibrary/text/hyphenation/ZLTextTeXHyphenator.java index 8e15e4cd4..9fd367e81 100644 --- a/src/org/geometerplus/zlibrary/text/hyphenation/ZLTextTeXHyphenator.java +++ b/src/org/geometerplus/zlibrary/text/hyphenation/ZLTextTeXHyphenator.java @@ -21,6 +21,7 @@ package org.geometerplus.zlibrary.text.hyphenation; import java.util.*; +import org.geometerplus.zlibrary.core.language.Language; import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; @@ -54,7 +55,7 @@ final class ZLTextTeXHyphenator extends ZLTextHyphenator { } public void load(String language) { - if (language == null || ZLLanguageUtil.OTHER_LANGUAGE_CODE.equals(language)) { + if (language == null || Language.OTHER_CODE.equals(language)) { language = ZLLanguageUtil.defaultLanguageCode(); } if (language == null || language.equals(myLanguage)) { diff --git a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java index fcfc6214e..281a726e6 100644 --- a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java +++ b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidLibrary.java @@ -188,7 +188,7 @@ public final class ZLAndroidLibrary extends ZLibrary { } @Override - public Collection defaultLanguageCodes() { + public List defaultLanguageCodes() { final TreeSet set = new TreeSet(); set.add(Locale.getDefault().getLanguage()); final TelephonyManager manager = (TelephonyManager)myApplication.getSystemService(Context.TELEPHONY_SERVICE); @@ -211,7 +211,7 @@ public final class ZLAndroidLibrary extends ZLibrary { } } set.add("multi"); - return set; + return new ArrayList(set); } @Override