![]() |
#1 |
Enthusiast
![]() 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 ? ![]() |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,199
Karma: 27110894
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. |
![]() |
![]() |
![]() |
#3 | |
Enthusiast
![]() Posts: 32
Karma: 10
Join Date: Jul 2011
Device: none
|
Quote:
from calibre.utils.localization import set_translators set_translators('ar') will it work properly or i need to make more changes ? thanks |
|
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() 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. |
![]() |
![]() |
![]() |
#5 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,199
Karma: 27110894
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.
|
![]() |
![]() |
![]() |
#6 |
fresh Computer scientist
![]() 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 |
![]() |
![]() |
![]() |
#7 |
Enthusiast
![]() 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> Last edited by Naderstouhy; 07-26-2011 at 02:17 AM. |
![]() |
![]() |
![]() |
#8 |
Enthusiast
![]() 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
Last edited by Naderstouhy; 07-27-2011 at 03:02 AM. |
![]() |
![]() |
![]() |
#9 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,199
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There's no way to do that. Those string are translated at program startup.
|
![]() |
![]() |
![]() |
#10 |
Enthusiast
![]() 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)) Last edited by Naderstouhy; 07-27-2011 at 06:39 AM. |
![]() |
![]() |
![]() |
#11 |
Enthusiast
![]() 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
|
![]() |
![]() |
![]() |
#12 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,199
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
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.
|
![]() |
![]() |
![]() |
#13 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,199
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
![]() |
![]() |
![]() |
#14 |
Enthusiast
![]() 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 ? |
![]() |
![]() |
![]() |
#15 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,199
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I have no idea.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |