Skip to content

Commit

Permalink
Added Esperanto translation of about page. Fixed language code
Browse files Browse the repository at this point in the history
  • Loading branch information
wildeyedskies committed Aug 7, 2017
1 parent ab7de6f commit 932fc59
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 25 deletions.
Binary file modified app/src/main/assets/data.db
Binary file not shown.
2 changes: 2 additions & 0 deletions app/src/main/java/org/mcxa/vortaro/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.mcxa.vortaro

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_about.*

Expand All @@ -19,6 +20,7 @@ class AboutActivity : AppCompatActivity() {
supportActionBar?.setDisplayShowHomeEnabled(true)
}

about_content.movementMethod = LinkMovementMethod.getInstance()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/java/org/mcxa/vortaro/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,38 @@ class DatabaseHelper(private val context: Context) :
object: AsyncTask<Void,Void,HashMap<Int, WordModel>>() {
override fun doInBackground(vararg p0: Void?): HashMap<Int, WordModel> {
val wordmap = HashMap<Int, WordModel>()
db.rawQuery("SELECT * FROM es " +
"INNER JOIN en ON es.rowid=en.esrow " +
"LEFT JOIN trans ON es.esword=trans.verb " +
"LEFT JOIN ety ON es.esword=ety.word " +
"WHERE es.esword=? OR es.esword=? OR es.rowid IN " +
"(SELECT es.rowid FROM es INNER JOIN en ON es.rowid=en.esrow WHERE en.enword=? OR en.enword=?)",
db.rawQuery("SELECT * FROM eo " +
"INNER JOIN en ON eo.rowid=en.eorow " +
"LEFT JOIN trans ON eo.eoword=trans.verb " +
"LEFT JOIN ety ON eo.eoword=ety.word " +
"WHERE eo.eoword=? OR eo.eoword=? OR eo.rowid IN " +
"(SELECT eo.rowid FROM eo INNER JOIN en ON eo.rowid=en.eorow WHERE en.enword=? OR en.enword=?)",
arrayOf(exactTerm, normalizedTerm, exactTerm, "to " + exactTerm)
).use { cursor ->

while (cursor.moveToNext()) {
val esrow = cursor.getInt(cursor.getColumnIndexOrThrow("esrow"))
val eorow = cursor.getInt(cursor.getColumnIndexOrThrow("eorow"))
// if the wordmap already has the Esperanto word, then just add the english def
if (wordmap.containsKey(esrow)) {
if (wordmap.containsKey(eorow)) {
// grab the english values
val word = cursor.getString(cursor.getColumnIndexOrThrow("enword"))
val elaboration = cursor.getString(cursor.getColumnIndexOrThrow("el"))
val elbefore = cursor.getInt(cursor.getColumnIndexOrThrow("elbefore"))

wordmap.get(esrow)?.en?.add(EnModel(word, elaboration, when(elbefore) {
wordmap.get(eorow)?.en?.add(EnModel(word, elaboration, when(elbefore) {
0 -> false
1 -> true
else -> null
}))
// add a new word model and english definition
} else {
val esword = cursor.getString(cursor.getColumnIndexOrThrow("esword"))
val eoword = cursor.getString(cursor.getColumnIndexOrThrow("eoword"))
val enword = cursor.getString(cursor.getColumnIndexOrThrow("enword"))
val elaboration = cursor.getString(cursor.getColumnIndexOrThrow("el"))
val elbefore = cursor.getInt(cursor.getColumnIndexOrThrow("elbefore"))
val etymology = cursor.getString(cursor.getColumnIndexOrThrow("ety"))
val trans = cursor.getInt(cursor.getColumnIndexOrThrow("trans"))
Log.d(TAG, "found $esword, $enword, $elaboration, $elbefore, $etymology, $trans")
Log.d(TAG, "found $eoword, $enword, $elaboration, $elbefore, $etymology, $trans")

val enmodels = LinkedList<EnModel>()
enmodels.add(EnModel(enword, elaboration, when(elbefore) {
Expand All @@ -112,7 +112,7 @@ class DatabaseHelper(private val context: Context) :
else -> null
}))

wordmap.put(esrow, WordModel(esword, enmodels, etymology ?: "",when(trans) {
wordmap.put(eorow, WordModel(eoword, enmodels, etymology ?: "",when(trans) {
2 -> true
1 -> false
else -> null
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/org/mcxa/vortaro/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ class MainActivity : AppCompatActivity() {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
val w = word_view.adapter as WordAdapter
if (!s.isNullOrEmpty()) {
dbHelper?.search(s.toString(), word_view.adapter as WordAdapter)
dbHelper?.search(s.toString(), w)
} else {
w.words.beginBatchedUpdates();
// remove items at end, to avoid unnecessary array shifting
while (w.words.size() > 0) {
w.words.removeItemAt(w.words.size() - 1);
}
w.words.endBatchedUpdates()
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
android:textSize="20sp"/>

<TextView
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/about_header"
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
<string name="menu_about">About</string>
<string name="about_header">About Senreta Vortaro</string>
<string name="about_contents">
Senreta Vortaro (Offline Dictionary) is an english-esperanto dictionary app inspired by the
En: Senreta Vortaro (offline dictionary) is an English-Esperanto dictionary app inspired by the
web page Tuja Vortaro. It is designed to be easy to use for beginners.\n\n
This app is open source under the Apache2 License and the data sources are freely available
under Creative Commons licenses.

Senreta Vortaro was created by Ian Mcxa. The source code is available on
<a href="https://github.com/ianmcxa/vortaro">Github</a> under the Apache2 License. The dictionary
data is licenced under Creative Commons.\n\n

Eo: Senreta Vortaro estas angla-Esperanta vortara aplikaĵo. La dinamika retpaĝo, Tuja Vortaro,
inspiris ĝin. Senreta Vortaro estas kreita por esti facile uzata de komencantoj.\n\n

Senreta Vortaro estas verko de Ian Mcxa. La fontkodo estas havebla ĉe
<a href="https://github.com/ianmcxa/vortaro">Github</a> per la Apache2 permesilo. La vortaraj
dataoj estas permesitaj per Creative Commons.
</string>
</resources>
18 changes: 9 additions & 9 deletions dictionary-src/buildDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ def build_espdic(conn):
print('parsing espdic...')
# now let's parse the file into the database
for line in espdic_in:
es, en = line.strip().split(' : ')
eo, en = line.strip().split(' : ')

# insert the Esperanto word
c.execute('''insert into es values (?)''', (es,))
esrow = c.lastrowid
c.execute('''insert into eo values (?)''', (eo,))
eorow = c.lastrowid

# some entries have es : (description in English)
# this case needs to be handled specially
if (en.startswith('(') and en.endswith(')')):
c.execute('''insert into en values (?,?,?,?)''', (esrow, '', en, 0))
c.execute('''insert into en values (?,?,?,?)''', (eorow, '', en, 0))
else:
# regex taken from https://stackoverflow.com/questions/26633452/how-to-split-by-commas-that-are-not-within-parentheses
enlist = re.split(r',\s*(?![^()]*\))', en)
Expand All @@ -74,7 +74,7 @@ def build_espdic(conn):
elbefore = 0
el = None

c.execute('''insert into en values (?,?,?,?)''', (esrow, enword, el, elbefore))
c.execute('''insert into en values (?,?,?,?)''', (eorow, enword, el, elbefore))

espdic_in.close()
conn.commit()
Expand Down Expand Up @@ -113,16 +113,16 @@ def create_tables(conn):
c.execute('''create table trans
(verb text primary key, trans integer) without rowid''')
# Esperanto words
c.execute('''create table es
(esword text)''')
c.execute('''create table eo
(eoword text)''')
# English words
# Note that esindx refers to the rowid in the Esperanto table
# el is the elaboration that may be before or after a word, denoted by elbefore
c.execute('''create table en
(esrow integer, enword text, el text, elbefore integer)''')
(eorow integer, enword text, el text, elbefore integer)''')
# we index the english words because we also want to search on them
c.execute('''create index enword on en (enword)''')
c.execute('''create index esrow on en (esrow)''')
c.execute('''create index eorow on en (eorow)''')

# commit and close our transaction
conn.commit()
Expand Down

0 comments on commit 932fc59

Please sign in to comment.