Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 03-29-2015, 12:08 PM   #1
mendesitba
Connoisseur
mendesitba began at the beginning.
 
Posts: 65
Karma: 10
Join Date: Mar 2015
Device: KPW, Ipad 2, Note 5
Question How to manually set the language for each source of the news recipe?

Greetings!

I would like to know if there is a way to set the language for each source of my recipe. For instance, French for Le Monde, Spanish for El País and so on...

Here is the detailed reason why I need to do this. But in a few words, Kindle's Vocabulary Builder doesn't work properly with multilingual documents. So, I'm trying to figure out a way to fix this problem and maybe if there is a way to set the metadata language for each source it may work.

Here is how my recipe looks like.

Edit: In red below is what I want to do. Set the language (in red) for each source.

Quote:
#!/usr/bin/env python2
# vim:fileencoding=utf-8
from __future__ import unicode_literals, division, absolute_import, print_function
from calibre.web.feeds.news import BasicNewsRecipe

class AdvancedUserRecipe1427664515(BasicNewsRecipe):
title = 'Op-Ed An\xe1lises Di\xe1rios'
oldest_article = 1
max_articles_per_feed = 100
auto_cleanup = True

feeds = [
("Diplomatie : Toute l'actualit\xe9 sur ...", b'http://www.lemonde.fr/diplomatie/rss_full.xml'),French
(b'Politics Opinion Articles - Project Syndicate RSS-Feed', b'http://www.project-syndicate.org/rss/politics'),English
(b'Post Western World', b'http://www.postwesternworld.com/feed/'),English
(b'Boletim Mundorama', b'http://mundorama.net/feed/'),Portuguese
(b'Esglobal', b'http://www.esglobal.org/feed/'),Spanish
("Crise de l'euro : Toute l'actualit\xe9...", b'http://www.lemonde.fr/crise-de-l-euro/rss_full.xml'),French
(b'Economics Opinion Articles - Project Syndicate RSS-Feed', b'http://www.project-syndicate.org/rss/international-economics'),English
(b'Folha.com - Colunas - Matias Spektor', b'http://feeds.folha.uol.com.br/colunas/matiasspektor/rss091.xml'),Portuguese
(b'Global Health & Development', b'http://www.project-syndicate.org/rss/growth-and-development'),English
(b'World Affairs', b'http://www.project-syndicate.org/rss/asia'),English
("Editoriaux : Toute l'actualit\xe9 sur ...", b'http://www.lemonde.fr/editoriaux/rss_full.xml'),French
]

Last edited by mendesitba; 03-29-2015 at 05:37 PM.
mendesitba is offline   Reply With Quote
Old 03-29-2015, 11:58 PM   #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,859
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use postprocess_html and set the lang attribute on each downloaded html file appropriately.
kovidgoyal is offline   Reply With Quote
Advert
Old 04-02-2015, 12:20 AM   #3
mendesitba
Connoisseur
mendesitba began at the beginning.
 
Posts: 65
Karma: 10
Join Date: Mar 2015
Device: KPW, Ipad 2, Note 5
Quote:
Originally Posted by kovidgoyal View Post
Use postprocess_html and set the lang attribute on each downloaded html file appropriately.
Hi! Thanks for the help

I have zero experience on programming, so I didn't really understand what you said. I thought it would be as simple as adding something like << language = en >>, << language = fr >> in front of each source.

I have been searching "postprocess_html" on mobileread forums to discover how to set the lang with that, but so far I don't have any idea of how to do it.
Does it involve adding many lines on my recipe ? Is there some place that I can find the complete code which I can copy and paste on my recipe (just editing the code with the language I want)?
mendesitba is offline   Reply With Quote
Old 04-02-2015, 12:35 AM   #4
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,859
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You will need to learn at least a little bit of programming to do that. There are examples of using postprocess_html etc to do other taks in the user manual, but you wont find a copy/paste solution.
kovidgoyal is offline   Reply With Quote
Old 04-02-2015, 10:19 AM   #5
mendesitba
Connoisseur
mendesitba began at the beginning.
 
Posts: 65
Karma: 10
Join Date: Mar 2015
Device: KPW, Ipad 2, Note 5
Quote:
Originally Posted by kovidgoyal View Post
You will need to learn at least a little bit of programming to do that. There are examples of using postprocess_html etc to do other taks in the user manual, but you wont find a copy/paste solution.
I'll try that. But, what language I should know in order to edit recipes? Is it python or html?
mendesitba is offline   Reply With Quote
Advert
Old 04-02-2015, 01:38 PM   #6
mendesitba
Connoisseur
mendesitba began at the beginning.
 
Posts: 65
Karma: 10
Join Date: Mar 2015
Device: KPW, Ipad 2, Note 5
Hello. I found this article: "Declaring language in HTML" by w3.org.

They describe the following code to set language attributes:
Code:
<html lang="fr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
I'm wondering if this is what I need to do with my recipe. Something like inserting the following code:
Code:
def postprocess_html(self, soup, first_fetch):

<html lang="fr" xml:lang="fr" xmlns="http://www.lemonde.fr/diplomatie/rss_full.xml">

<html lang="en" xml:lang="en" xmlns="http://www.project-syndicate.org/rss/politics">

<html lang="en" xml:lang="en" xmlns="http://www.postwesternworld.com/feed/">

#and so on for each source....

Is that what I need? Is that at least close to what I need to do?

Thanks

Edit:
I noticed that all recipes has "def" before postprocess_html, so I included it.

Moreover, many recipes include (self, soup, first_fetch) after postprocess_html, while others include (self, soup, first_fetch, job_info) or only (self, soup). I added to my code the first option (self, soup, first_fetch) since it is the most used, but I don't know if it's necessary.

Edit 2:
When I use the above code in Calibre recipe advanced settings, I get syntax error for the line with <html lang="fr" xml:lang="fr" xmlns="http://www.lemonde.fr/diplomatie/rss_full.xml">

Last edited by mendesitba; 04-02-2015 at 02:51 PM.
mendesitba is offline   Reply With Quote
Old 04-02-2015, 06:42 PM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
You will need to know at least a little python, and take a look at what postprocess_html does and how to use it.
eschwartz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hanvon C18: how do you set the interface language? Heba More E-Book Readers 1 05-18-2014 05:26 AM
SET READING LOCATION IN SOURCE - How do I do that? mibtp Kindle Formats 18 06-20-2013 06:05 AM
K4NT - How to set time manually? And other questions Beemspam01 Amazon Kindle 0 04-20-2013 03:14 AM
Cant get past the set language menu Dividizzl Kobo Reader 17 10-29-2012 03:56 AM
Custom news recipe default language ppclarke Recipes 2 04-13-2012 07:58 AM


All times are GMT -4. The time now is 10:28 AM.


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