public RelevantLanguageSorter(List<Book> installedDocuments) { relevantLanguages = new HashSet<>(); String defaultLanguageCode = Locale.getDefault().getLanguage(); relevantLanguages.add(defaultLanguageCode); relevantLanguages.addAll(Arrays.asList(MAJOR_LANGUAGE_CODES)); for (Book doc : installedDocuments) { Language lang = doc.getLanguage(); if (lang!=null) { relevantLanguages.add(lang.getCode()); } } }
/** can we enable the main menu search button */ @Override public boolean isSearchable() { try { //TODO allow japanese search - japanese bibles use smartcn which is not available return !"ja".equals(getCurrentDocument().getLanguage().getCode()); } catch (Exception e) { Log.w(TAG, "Missing language code", e); return true; } } }
private List<Locale> calculateLocalePreferenceList(Book fromBook) { //calculate preferred locales to use for speech // Set preferred language to the same language as the book. // Note that a language may not be available, and so we have a preference list String bookLanguageCode = fromBook.getLanguage().getCode(); Log.d(TAG, "Book has language code:"+bookLanguageCode); List<Locale> localePreferenceList = new ArrayList<>(); if (bookLanguageCode.equals(Locale.getDefault().getLanguage())) { // for people in UK the UK accent is preferable to the US accent localePreferenceList.add( Locale.getDefault() ); } // try to get the native country for the lang String countryCode = getDefaultCountryCode(bookLanguageCode); if (countryCode!=null) { localePreferenceList.add( new Locale(bookLanguageCode, countryCode)); } // Speak ancient greek with modern greece. if(bookLanguageCode.equals("grc")) { bookLanguageCode = "el"; } // finally just add the language of the book localePreferenceList.add( new Locale(bookLanguageCode)); return localePreferenceList; }
/** a spinner has changed so refilter the doc list */ private void populateLanguageList() { try { // temporary Set to remove duplicate Languages Set<Language> langSet = new HashSet<>(); if (allDocuments!=null && allDocuments.size()>0) { Log.d(TAG, "initialising language list"); for (Book doc : allDocuments) { langSet.add(doc.getLanguage()); } List<Language> sortedLanguages = sortLanguages(langSet); languageList.clear(); languageList.addAll(sortedLanguages); langArrayAdapter.notifyDataSetChanged(); } } catch (Exception e) { Log.e(TAG, "Error initialising view", e); Toast.makeText(this, getString(R.string.error)+" "+e.getMessage(), Toast.LENGTH_SHORT).show(); } }
@Override public void setBook(Book newBook) { book = newBook; stemmerName = null; if (book != null) { // stemmer name are same as language name, in most cases pickStemmer(book.getLanguage().getCode()); } }
@Override public boolean equals(Object obj) { // The real bit ... Book thatBook = ((BookKey)obj).book; return book.getBookCategory().equals(thatBook.getBookCategory()) && book.getAbbreviation().equals(thatBook.getAbbreviation()) && book.getLanguage().equals(thatBook.getLanguage()); }
for (Book doc : allDocuments) { BookFilter filter = DOCUMENT_TYPE_SPINNER_FILTERS[selectedDocumentFilterNo]; if (filter.test(doc) && doc.getLanguage().equals(lang)) { displayedDocuments.add(doc);
Locale sortLocale = new Locale(book.getLanguage().getCode()); String target = searchRequest.toLowerCase(sortLocale);
if (doc.getLanguage()==null) { Log.d(TAG, "Ignoring "+doc.getInitials()+" because it has no language"); iter.remove();
protected Language getDefaultLanguage() { // get the current language code String langCode = Locale.getDefault().getLanguage(); if (!new Language(langCode).isValidLanguage()) { langCode = Locale.ENGLISH.getLanguage(); } // create the JSword Language for current lang Language localLanguage = new Language(langCode); Log.d(TAG, "Local language is:"+localLanguage); // check a bible exists in current lang otherwise use english boolean foundBibleInLocalLanguage = false; for (Book book : getAllDocuments()) { if (book.getBookCategory().equals(BookCategory.BIBLE) && localLanguage.equals(book.getLanguage())) { foundBibleInLocalLanguage = true; break; } } // if no bibles exist in current lang then fall back to default language (English) so the user will not see an initially empty list if (!foundBibleInLocalLanguage) { Log.d(TAG, "No bibles found in local language so falling back to default lang"); localLanguage = Language.DEFAULT_LANG; } return localLanguage; }
private ArrayList<SpeakCommand> getSpeakCommandsForVerse(SpeakSettings settings, Book book, Key key) { try { BookData data = new BookData(book, key); Element frag = data.getOsisFragment(false); Document doc = frag.getDocument(); if (doc == null) { doc = new Document(frag); } SAXEventProvider osissep = new JDOMSAXEventProvider(doc); ContentHandler osisHandler = new OsisToBibleSpeak(settings, book.getLanguage().getCode()); osissep.provideSAXEvents(osisHandler); return ((OsisToBibleSpeak) osisHandler).getSpeakCommands(); } catch (Exception e) { Log.e(TAG, "Error getting text from book" , e); return new ArrayList<>(); } }
public AbstractBookAnalyzer createAnalyzer(Book book) { AbstractBookAnalyzer newObject = null; Language lang = book == null ? null : book.getLanguage(); if (lang != null) { String aClass = getAnalyzerValue(lang); log.debug("Creating analyzer:{} BookLang:{}", aClass, lang); if (aClass != null) { try { newObject = ReflectionUtil.construct(aClass); } catch (ReflectiveOperationException e) { log.error("Configuration error in AnalyzerFactory properties", e); } } } if (newObject == null) { newObject = new SimpleLuceneAnalyzer(); } // Configure the analyzer newObject.setBook(book); newObject.setDoStemming(getDefaultStemmingProperty()); newObject.setDoStopWords(getDefaultStopWordProperty()); return newObject; }
/** * This is an example of the different ways to select a Book from the * selection available. * * @see org.crosswire.common.config.Config * @see Books */ public void pickBible() { // The Default Bible - JSword does everything it can to make this work Book book = Books.installed().getBook(BIBLE_NAME); // And you can find out more too: System.out.println(book.getLanguage()); // If you want a greater selection of Books: List<Book> books = Books.installed().getBooks(); book = books.get(0); // Or you can narrow the range a bit books = Books.installed().getBooks(BookFilters.getOnlyBibles()); book = books.get(0); // There are implementations of BookFilter for all sorts of things in // the BookFilters class // If you are wanting to get really fancy you can implement your own // BookFilter easily List<Book> test = Books.installed().getBooks(new MyBookFilter("ESV")); book = test.get(0); if (book != null) { System.out.println(book.getInitials()); } // If you want to know about new books as they arrive: Books.installed().addBooksListener(new MyBooksListener()); }
String prevName = firstBook.getInitials(); showDiffs[i - 1] = comparingBooks && BookCategory.BIBLE.equals(category) && category.equals(prevCategory) && book.getLanguage().equals(firstBook.getLanguage()) && !book.getInitials().equals(prevName);
Book book = books[i]; cell = OSISUtil.factory().createCell(); Language lang = book.getLanguage(); if (lang != null) { cell.setAttribute(OSISUtil.OSIS_ATTR_LANG, lang.getCode(), Namespace.XML_NAMESPACE); lang = book.getLanguage(); cell.setAttribute(OSISUtil.OSIS_ATTR_LANG, lang.getCode(), Namespace.XML_NAMESPACE); row.addContent(cell);
osisToHtmlParameters.setLanguageCode(book.getLanguage().getCode()); osisToHtmlParameters.setModuleBasePath(book.getBookMetaData().getLocation());