Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/components/article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ArticleProps = {
type ArticleState = {
fontFamily: string
fontSize: number
translate: boolean
loadWebpage: boolean
loadFull: boolean
fullContent: string
Expand All @@ -60,6 +61,7 @@ class Article extends React.Component<ArticleProps, ArticleState> {
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: "",
Expand Down Expand Up @@ -288,8 +290,7 @@ class Article extends React.Component<ArticleProps, ArticleState> {
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()
Expand All @@ -304,6 +305,17 @@ class Article extends React.Component<ArticleProps, ArticleState> {
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 })
Expand Down Expand Up @@ -439,6 +451,18 @@ class Article extends React.Component<ArticleProps, ArticleState> {
this.props.toggleStarred(this.props.item)
}
/>
{this.state.loadWebpage && (
<CommandBarButton
title={
this.state.translate
? intl.get("article.showOriginal")
: intl.get("article.translate")
}
className={this.state.translate ? "active" : ""}
iconProps={{ iconName: "Translate" }}
onClick={this.toggleTranslation}
/>
)}
<CommandBarButton
title={intl.get("article.loadFull")}
className={this.state.loadFull ? "active" : ""}
Expand Down Expand Up @@ -477,7 +501,9 @@ class Article extends React.Component<ArticleProps, ArticleState> {
}
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}
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/i18n/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down