Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > KOReader

Notices

Reply
 
Thread Tools Search this Thread
Old 02-18-2016, 01:25 AM   #1
nachox77
Junior Member
nachox77 began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Feb 2016
Device: Kindle PW3
Change Wikipedia Language

Hello.

I was wondering if is possible to change the lenguage of the wikipedia search. Instead of searching in wikipedia in English I want to search in Spanish.

Also I'm looking for Dictionaries in an appropriate format to KOReader.

Thanks in advance
nachox77 is offline   Reply With Quote
Old 02-18-2016, 10:14 AM   #2
Ken Maltby
Wizard
Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.Ken Maltby ought to be getting tired of karma fortunes by now.
 
Ken Maltby's Avatar
 
Posts: 4,465
Karma: 6900052
Join Date: Dec 2009
Location: The Heart of Texas
Device: Boox Note2, AuraHD, PDA,
Quote:
Originally Posted by nachox77 View Post
Hello.

I was wondering if is possible to change the lenguage of the wikipedia search. Instead of searching in wikipedia in English I want to search in Spanish.

Also I'm looking for Dictionaries in an appropriate format to KOReader.

Thanks in advance
I would suspect that the URL for Wikipedia would include a language reference. For the desktop sites it looks like this https://es.wikipedia.org/wiki/Wikipedia:Portada

If you look at "/koreader/frontend/ui/Wikipedia.lua" there is a provision for changing the variable that defines the language. I don't know how that works, but you could change the "default_lang = "en" to "es".

KOReader uses Stardict files. There are a number of them on the internet, including translation dictionaries.

Luck;
Ken
Ken Maltby is offline   Reply With Quote
Advert
Old 02-18-2016, 06:16 PM   #3
nachox77
Junior Member
nachox77 began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Feb 2016
Device: Kindle PW3
Here is the wikipedia.lua file with default values:

Quote:
local JSON = require("json")
local DEBUG = require("dbg")

--[[
-- Query wikipedia using Wikimedia Web API.
-- http://en.wikipedia.org/w/api.php?ac...=&titles=hello
--]]

local Wikipedia = {
wiki_server = "https://%s.wikipedia.org",
wiki_path = "/w/api.php",
wiki_params = {
action = "query",
prop = "extracts",
format = "json",
exintro = "",
explaintext = "",
redirects = "",
},
default_lang = "en",
}

function Wikipedia:getWikiServer(lang)
return string.format(self.wiki_server, lang or self.default_lang)
end

--[[
-- return decoded JSON table from Wikipedia
--]]
function Wikipedia:loadPage(text, lang, intro, plain)
local socket = require('socket')
local url = require('socket.url')
local http = require('socket.http')
local https = require('ssl.https')
local ltn12 = require('ltn12')

local request, sink = {}, {}
local query = ""
self.wiki_params.exintro = intro and "" or nil
self.wiki_params.explaintext = plain and "" or nil
for k,v in pairs(self.wiki_params) do
query = query .. k .. '=' .. v .. '&'
end
local parsed = url.parse(self:getWikiServer(lang))
parsed.path = self.wiki_path
parsed.query = query .. "titles=" .. url.escape(text)

-- HTTP request
request['url'] = url.build(parsed)
request['method'] = 'GET'
request['sink'] = ltn12.sink.table(sink)
DEBUG("request", request)
http.TIMEOUT, https.TIMEOUT = 10, 10
local httpRequest = parsed.scheme == 'http' and http.request or https.request
local code, headers, status = socket.skip(1, httpRequest(request))

-- raise error message when network is unavailable
if headers == nil then
error("Network is unreachable")
end

if status ~= "HTTP/1.1 200 OK" then
DEBUG("HTTP status not okay:", status)
return
end

local content = table.concat(sink)
if content ~= "" and string.sub(content, 1,1) == "{" then
local ok, result = pcall(JSON.decode, content)
if ok and result then
DEBUG("wiki result", result)
return result
else
DEBUG("error:", result)
end
else
DEBUG("not JSON:", content)
end
end

-- extract intro passage in wiki page
function Wikipedia:wikintro(text, lang)
local result = self:loadPage(text, lang, true, true)
if result then
local query = result.query
if query then
return query.pages
end
end
end

return Wikipedia
I changed both variables:
default_lang="es" //instead of "en"
wiki_server="https://es.wikipedia.org" //instead of "https://%s.wikipedia.org"

(I don't know what means "%", it doesn´t look like a joker char)

And it doesn´t work, it keep giving me english text as answers. May be i'm losing some variable
nachox77 is offline   Reply With Quote
Old 02-19-2016, 08:04 AM   #4
Alan_S
Evangelist
Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.
 
Alan_S's Avatar
 
Posts: 440
Karma: 1084584
Join Date: Aug 2007
Location: Sisak, Croatia
Device: Kobo Aura H2O, Kobo Aura ONE
Try to change only default_lang="es", leave wiki_server alone.

%s means that some variable is in question. Probably the default language one. On the other hand, why hardcoding language (es) instead using variable doesn't work, I can't tell.
Alan_S is offline   Reply With Quote
Old 02-21-2016, 01:31 AM   #5
nachox77
Junior Member
nachox77 began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Feb 2016
Device: Kindle PW3
Thanks for answering. It doesn't work.
nachox77 is offline   Reply With Quote
Advert
Old 02-21-2016, 08:42 AM   #6
Alan_S
Evangelist
Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.Alan_S ought to be getting tired of karma fortunes by now.
 
Alan_S's Avatar
 
Posts: 440
Karma: 1084584
Join Date: Aug 2007
Location: Sisak, Croatia
Device: Kobo Aura H2O, Kobo Aura ONE
It would be good idea if you report it in koreaders github page, i.e.: https://github.com/koreader/koreader/issues In this way authors would know about this issue and can address it.
Alan_S is offline   Reply With Quote
Old 02-22-2016, 07:59 AM   #7
Frenzie
Wizard
Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.
 
Posts: 1,613
Karma: 724945
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
The %s is used a little further down with string.format:

string.format(self.wiki_server, lang or self.default_lang)

The lang variable is set in frontend/ui/translator.lua, although given that we're dealing with single words I don't know about the viability of that approach.

Anyway, did you try the Wikipedia API without bothering with the KOReader code?
Frenzie is offline   Reply With Quote
Old 02-24-2016, 03:20 PM   #8
nachox77
Junior Member
nachox77 began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Feb 2016
Device: Kindle PW3
What i want is searching directly in spanish wikipedia no a traduction
nachox77 is offline   Reply With Quote
Old 02-26-2016, 03:31 AM   #9
Frenzie
Wizard
Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.Frenzie ought to be getting tired of karma fortunes by now.
 
Posts: 1,613
Karma: 724945
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
As far as I've been able to ascertain, what you did (i.e. change the variable %s to es) should already work.
Frenzie is offline   Reply With Quote
Old 03-04-2016, 11:07 AM   #10
djalma
Member
djalma doesn't litterdjalma doesn't litter
 
Posts: 14
Karma: 116
Join Date: Feb 2016
Device: Kobo Glo HD
Quote:
Originally Posted by nachox77
wiki_server="https://es.wikipedia.org" //instead of "https://%s.wikipedia.org"

(I don't know what means "%", it doesn´t look like a joker char)

And it doesn´t work, it keep giving me english text as answers. May be i'm losing some variable

Quote:
Originally Posted by Frenzie View Post
As far as I've been able to ascertain, what you did (i.e. change the variable %s to es) should already work.
Yes, It works. Anyway link "selected koreader language", (or the language in epub's metadata for example, in the same way that koreader nightly version is doing with the "automatic" hyphenation), to the wikipedia's language should be a good idea.
Regards.

Last edited by djalma; 03-04-2016 at 11:18 AM.
djalma is offline   Reply With Quote
Reply

Tags
dictionaries, lenguage, wikipedia

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre language change? mago55 Calibre 8 11-16-2020 01:49 AM
Language change issue Shivam Sony Reader Dev Corner 1 12-26-2012 04:34 PM
Spellingreforms and language change owly General Discussions 52 12-20-2012 03:33 AM
Change Language in DR800SG roatto iRex 31 04-14-2010 08:10 AM
How Do I Change the Language? PBee Bookeen 8 03-13-2009 04:56 AM


All times are GMT -4. The time now is 01:56 PM.


MobileRead.com is a privately owned, operated and funded community.