Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 07-21-2011, 04:47 AM   #1
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
language changing

i have changed the funcation set_language() to be able to accept a parameter the language i wish to set, i need to know if there's any way we can modify the .html code in order to be able to access this function and also to change the <html dir="rtl"> tag dynamicly , as i did some research i know that we don't have any python scripts in html, so i need to have a solution for language changing if you have any.

i have thought about some solution:
- making 2 instances of calibre on the server, and switch from one instance to another but i think it wont work because calibre need to be restarted in order to change the language.

any suggestions ?
Naderstouhy is offline   Reply With Quote
Old 07-21-2011, 11:06 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Briefly:
1) You will have to write code to load translators dynamically.
2) You will have to replace the use of the _() function in the server code with a local function that can be changed dynamically
3) You will need to add a dir variable to all the HTML templates of the server.
kovidgoyal is offline   Reply With Quote
Advert
Old 07-25-2011, 06:05 AM   #3
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
Quote:
Originally Posted by kovidgoyal View Post
Briefly:
1) You will have to write code to load translators dynamically.
2) You will have to replace the use of the _() function in the server code with a local function that can be changed dynamically
3) You will need to add a dir variable to all the HTML templates of the server.
whenever you start browser.html, what .py code is being executed first ? and if i add to this .py code :

from calibre.utils.localization import set_translators

set_translators('ar')

will it work properly or i need to make more changes ? thanks
Naderstouhy is offline   Reply With Quote
Old 07-25-2011, 07:23 AM   #4
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
or in fact i need to ask how to add an action for a button ( in the web ) to be able to put the set_dyntranslators('ar') into this action?

my browse.py code is :

connect('browse_language', base_href, self.browse_language)

def browse_language(self, lang):
set_dyntranslators('lang')


i'm getting a 404 (path not found) when compiling

Last edited by Naderstouhy; 07-25-2011 at 09:17 AM.
Naderstouhy is offline   Reply With Quote
Old 07-25-2011, 11:14 AM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You need to replace every instance of the use of _() in the server code with dynamic_translate() then you need to create an endpoint in browse.py that changes dynamic_translate. Then you need to create some HTML in browse.html that calls that endpoint.
kovidgoyal is offline   Reply With Quote
Advert
Old 07-25-2011, 03:20 PM   #6
csi-farah
fresh Computer scientist
csi-farah began at the beginning.
 
csi-farah's Avatar
 
Posts: 5
Karma: 10
Join Date: Jul 2011
Location: canada
Device: none
i think i will need to do the same thing hihihi but the only problem is that i don't understand the solution !!!!!!!! i am sure i should've studied fashion

Dear Mr. kovid genius can you please tell me in details ? like where i should find every instance of the use of _() ? can you give me 1 example please


Quote:
Originally Posted by kovidgoyal View Post
You need to replace every instance of the use of _() in the server code with dynamic_translate() then you need to create an endpoint in browse.py that changes dynamic_translate. Then you need to create some HTML in browse.html that calls that endpoint.
csi-farah is offline   Reply With Quote
Old 07-26-2011, 02:03 AM   #7
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
Thanks a lot Mr. kovid, my Code in case anyone wishes to use it is :


in the browse.py code is :

def add_routes(self, connect):
...
connect('browse_language', base_href+'/language', self.browse_language)

def browse_language(self, lang):
set_dyntranslators('lang')

in the localization.py :


def set_dyntranslators(newlang):

lang = newlang
if lang:
buf = iso639 = None
...

in html :

<a href="{prefix}/browse/language" id="nav-ar" title="The Arabic version of this webiste" OnClick='getElementById("htmltag").dir="rtl";getEl ementById("datebet").innerHTML= "التاريخ بين:";</a>



Quote:
Originally Posted by kovidgoyal View Post
You need to replace every instance of the use of _() in the server code with dynamic_translate() then you need to create an endpoint in browse.py that changes dynamic_translate. Then you need to create some HTML in browse.html that calls that endpoint.

Last edited by Naderstouhy; 07-26-2011 at 02:17 AM.
Naderstouhy is offline   Reply With Quote
Old 07-27-2011, 02:56 AM   #8
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
Mr. Kovid i have 1 more Question please, for the category fields, whenever i change the language dynamically the category : newest and allBooks are changes successfully, but all othere categories like rating, publishers, tags etc, are not change, also the sort by options are not changed, for these fields you called the db.field_metadata in browse.py, i couldn't find a solution on where i should add the function set_dyntranslator(..) in order for this items to change... thanks in advance





Quote:
Originally Posted by kovidgoyal View Post
You need to replace every instance of the use of _() in the server code with dynamic_translate() then you need to create an endpoint in browse.py that changes dynamic_translate. Then you need to create some HTML in browse.html that calls that endpoint.

Last edited by Naderstouhy; 07-27-2011 at 03:02 AM.
Naderstouhy is offline   Reply With Quote
Old 07-27-2011, 03:06 AM   #9
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There's no way to do that. Those string are translated at program startup.
kovidgoyal is offline   Reply With Quote
Old 07-27-2011, 06:33 AM   #10
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
for the sorting list i modified : sort_opts.append((x, n)) to sort_opts.append((x, _(n))) then the list worked fine !!!!!

for the category i modified : cats.append((meta['name'], category, icon)) to cats.append((_(meta['name']), category, icon))

Quote:
Originally Posted by kovidgoyal View Post
There's no way to do that. Those string are translated at program startup.

Last edited by Naderstouhy; 07-27-2011 at 06:39 AM.
Naderstouhy is offline   Reply With Quote
Old 07-27-2011, 06:36 AM   #11
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
btw Mr. kovid if you would like to have my modifications uploaded for your later use please let me know
Naderstouhy is offline   Reply With Quote
Old 07-27-2011, 11:32 AM   #12
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by Naderstouhy View Post
for the sorting list i modified : sort_opts.append((x, n)) to sort_opts.append((x, _(n))) then the list worked fine !!!!!

for the category i modified : cats.append((meta['name'], category, icon)) to cats.append((_(meta['name']), category, icon))
That will only work if the language of the main calibre interface is in English or the words are not translated in the language of the calibre interface. Try setting your calibre interface to Spanish and you will see that it wont work.
kovidgoyal is offline   Reply With Quote
Old 07-27-2011, 11:34 AM   #13
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by Naderstouhy View Post
btw Mr. kovid if you would like to have my modifications uploaded for your later use please let me know
Sure, open a bug report with your patch attached.
kovidgoyal is offline   Reply With Quote
Old 07-29-2011, 08:26 AM   #14
Naderstouhy
Enthusiast
Naderstouhy began at the beginning.
 
Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
great i will after i have a fully done modification (Y)

Mr kovid do you have any idea why in Internet Explorer everything worked fine with my code modifications, but while working on Firefox i've got some errors regarding the translations issue, i need to refresh the page whenever navigate in the website in order to have my dynamic translation back ! what is the difference that we are facing here ? and what should i modify in order to have it work on firefox as well ?

Quote:
Originally Posted by kovidgoyal View Post
Sure, open a bug report with your patch attached.
Naderstouhy is offline   Reply With Quote
Old 07-29-2011, 12:06 PM   #15
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I have no idea.
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which language do you use ? Druid_Elf Writers' Corner 6 08-15-2010 02:05 PM
Why not in another language? panzer Kobo Reader 0 08-05-2010 08:07 PM
Changing language Baldrake Bookeen 8 09-26-2009 08:15 AM
Changing from french language to english escalla Sony Reader 3 05-14-2009 12:57 PM


All times are GMT -4. The time now is 07:14 PM.


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