I've now added language as a field for my sources. This was the plan when I realized that not every country will have an English alternative feed. This gave me the chance to look at the translate library on npm and it looks straightforward to use.
I set up an api key with deepl and going to use that to translate the titles for displaying. The links are going to be set up to go through google translate.
I realized that I actually don't need deepl and could have used google directly. Bah! I gave my information for no reason. If you don't specify an engine, it defaults to google.
I currently fetch the rss files and save them. Then I use them to generate the home page. I'm going to update this so that the data is saved to a database instead and that way it should speed things up. This will also cut down on the translation calls that I need to do now.
npm install translate
import translate from "translate";
async function main() {
let text = "La reprise du trafic ferroviaire pourrait être effective d’ici fin janvier, selon le Premier Ministre, Alain Claude Bilie By Nze";
const t = await translate(text, {
from: "fr",
to: "en",
});
console.log(t);
}
main();
This is the core of adding translations to my world news site.