From 0c39576de3812b357158259da937ad960eca3c26 Mon Sep 17 00:00:00 2001 From: Richard Souza Date: Mon, 30 Jun 2025 11:34:57 -0300 Subject: [PATCH 1/4] feat: Implements web page translation --- src/components/article.tsx | 32 +++++++++++++++++++++++++++++--- src/scripts/i18n/en-US.json | 2 ++ src/scripts/i18n/pt-BR.json | 2 ++ src/scripts/i18n/pt-PT.json | 2 ++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/components/article.tsx b/src/components/article.tsx index 18a640ab..797b636b 100644 --- a/src/components/article.tsx +++ b/src/components/article.tsx @@ -44,6 +44,7 @@ type ArticleProps = { type ArticleState = { fontFamily: string fontSize: number + translate: boolean loadWebpage: boolean loadFull: boolean fullContent: string @@ -60,6 +61,7 @@ class Article extends React.Component { this.state = { fontFamily: window.settings.getFont(), fontSize: window.settings.getFontSize(), + translate: false, loadWebpage: props.source.openTarget === SourceOpenTarget.Webpage, loadFull: props.source.openTarget === SourceOpenTarget.FullContent, fullContent: "", @@ -288,8 +290,7 @@ class Article extends React.Component { loadWebpage: this.props.source.openTarget === SourceOpenTarget.Webpage, loadFull: - this.props.source.openTarget === - SourceOpenTarget.FullContent, + this.props.source.openTarget === SourceOpenTarget.FullContent, }) if (this.props.source.openTarget === SourceOpenTarget.FullContent) this.loadFull() @@ -304,6 +305,17 @@ class Article extends React.Component { if (refocus) refocus.focus() } + toggleTranslation = () => { + if (this.state.translate) { + this.setState({ translate: false }) + } else if ( + this.props.item.link.startsWith("https://") || + this.props.item.link.startsWith("http://") + ) { + this.setState({ translate: true }) + } + } + toggleWebpage = () => { if (this.state.loadWebpage) { this.setState({ loadWebpage: false }) @@ -439,6 +451,18 @@ class Article extends React.Component { this.props.toggleStarred(this.props.item) } /> + {this.state.loadWebpage && ( + + )} { } src={ this.state.loadWebpage - ? this.props.item.link + ? this.state.translate + ? `https://translate.google.com/translate?sl=auto&tl=${this.props.locale.split("-")[0]}&u=${encodeURIComponent(this.props.item.link)}` + : this.props.item.link : this.articleView() } allowpopups={"true" as unknown as boolean} diff --git a/src/scripts/i18n/en-US.json b/src/scripts/i18n/en-US.json index fad7eacd..626d1af3 100644 --- a/src/scripts/i18n/en-US.json +++ b/src/scripts/i18n/en-US.json @@ -64,6 +64,8 @@ "star": "Star", "unstar": "Remove star", "fontSize": "Font size", + "translate": "Translate article", + "showOriginal": "Show original", "loadWebpage": "Load webpage", "loadFull": "Load full content", "notify": "Notify if fetched in background", diff --git a/src/scripts/i18n/pt-BR.json b/src/scripts/i18n/pt-BR.json index d713081c..079067eb 100644 --- a/src/scripts/i18n/pt-BR.json +++ b/src/scripts/i18n/pt-BR.json @@ -63,6 +63,8 @@ "star": "Marcar como favorito", "unstar": "Remover marcação", "fontSize": "Tamanho da fonte", + "translate": "Traduzir artigo", + "showOriginal": "Mostrar original", "loadWebpage": "Carregar página web", "loadFull": "Carregar todo o conteúdo", "notify": "Notificar se atualizado em segundo plano", diff --git a/src/scripts/i18n/pt-PT.json b/src/scripts/i18n/pt-PT.json index 56354b26..aac0871a 100644 --- a/src/scripts/i18n/pt-PT.json +++ b/src/scripts/i18n/pt-PT.json @@ -64,6 +64,8 @@ "star": "Marcar como favorito", "unstar": "Remover marcação", "fontSize": "Tamanho da fonte", + "translate": "Traduzir artigo", + "showOriginal": "Mostrar original", "loadWebpage": "Carregar página web", "loadFull": "Carregar todo o conteúdo", "notify": "Notificar se atualizado em segundo plano", From 40bff3777622dcdc0608d521232097881c5fc2c8 Mon Sep 17 00:00:00 2001 From: nube Date: Wed, 30 Jul 2025 09:21:31 -0400 Subject: [PATCH 2/4] test changes --- src/components/article.tsx | 20 ++++++++++---------- src/scripts/i18n/en-US.json | 2 +- src/scripts/i18n/pt-BR.json | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/article.tsx b/src/components/article.tsx index 797b636b..c81d295e 100644 --- a/src/components/article.tsx +++ b/src/components/article.tsx @@ -44,7 +44,7 @@ type ArticleProps = { type ArticleState = { fontFamily: string fontSize: number - translate: boolean + translated: boolean loadWebpage: boolean loadFull: boolean fullContent: string @@ -61,7 +61,7 @@ class Article extends React.Component { this.state = { fontFamily: window.settings.getFont(), fontSize: window.settings.getFontSize(), - translate: false, + translated: false, loadWebpage: props.source.openTarget === SourceOpenTarget.Webpage, loadFull: props.source.openTarget === SourceOpenTarget.FullContent, fullContent: "", @@ -306,13 +306,13 @@ class Article extends React.Component { } toggleTranslation = () => { - if (this.state.translate) { - this.setState({ translate: false }) + if (this.state.translated) { + this.setState({ translated: false }) } else if ( this.props.item.link.startsWith("https://") || this.props.item.link.startsWith("http://") ) { - this.setState({ translate: true }) + this.setState({ translated: true }) } } @@ -454,11 +454,11 @@ class Article extends React.Component { {this.state.loadWebpage && ( @@ -501,7 +501,7 @@ class Article extends React.Component { } src={ this.state.loadWebpage - ? this.state.translate + ? this.state.translated ? `https://translate.google.com/translate?sl=auto&tl=${this.props.locale.split("-")[0]}&u=${encodeURIComponent(this.props.item.link)}` : this.props.item.link : this.articleView() diff --git a/src/scripts/i18n/en-US.json b/src/scripts/i18n/en-US.json index 626d1af3..faf09f81 100644 --- a/src/scripts/i18n/en-US.json +++ b/src/scripts/i18n/en-US.json @@ -65,7 +65,7 @@ "unstar": "Remove star", "fontSize": "Font size", "translate": "Translate article", - "showOriginal": "Show original", + "untranslate": "Show original", "loadWebpage": "Load webpage", "loadFull": "Load full content", "notify": "Notify if fetched in background", diff --git a/src/scripts/i18n/pt-BR.json b/src/scripts/i18n/pt-BR.json index 079067eb..6d0fc6d8 100644 --- a/src/scripts/i18n/pt-BR.json +++ b/src/scripts/i18n/pt-BR.json @@ -64,7 +64,7 @@ "unstar": "Remover marcação", "fontSize": "Tamanho da fonte", "translate": "Traduzir artigo", - "showOriginal": "Mostrar original", + "untranslate": "Mostrar original", "loadWebpage": "Carregar página web", "loadFull": "Carregar todo o conteúdo", "notify": "Notificar se atualizado em segundo plano", From 347962b60872070de900cd054284a320e7ea1996 Mon Sep 17 00:00:00 2001 From: nube Date: Wed, 30 Jul 2025 09:27:15 -0400 Subject: [PATCH 3/4] fix build --- electron-builder.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/electron-builder.yml b/electron-builder.yml index 0ae60919..819fcf5f 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -69,5 +69,4 @@ linux: - AppImage icon: build/icons category: Utility - desktop: - StartupWMClass: fluent-reader + desktop: {} \ No newline at end of file From 14700fe8c575bb7250ea2ba1e85a60e65e5f63ba Mon Sep 17 00:00:00 2001 From: nube Date: Wed, 30 Jul 2025 10:32:46 -0400 Subject: [PATCH 4/4] tiny fix on pt-PR.json string --- src/scripts/i18n/pt-PT.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/i18n/pt-PT.json b/src/scripts/i18n/pt-PT.json index aac0871a..5a8f9105 100644 --- a/src/scripts/i18n/pt-PT.json +++ b/src/scripts/i18n/pt-PT.json @@ -65,7 +65,7 @@ "unstar": "Remover marcação", "fontSize": "Tamanho da fonte", "translate": "Traduzir artigo", - "showOriginal": "Mostrar original", + "untranslate": "Mostrar original", "loadWebpage": "Carregar página web", "loadFull": "Carregar todo o conteúdo", "notify": "Notificar se atualizado em segundo plano",