Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be translated given it represents the current state, not the verb to translate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think translated could be better, the commit is not mine so, honestly I had not tried to modify that kind of stuff before 👀 thanks for pointing out

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to change all the lines that say translate to translated, right? not only this one? just asking n.n

Copy link
Collaborator

@CrystalSplitter CrystalSplitter Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all the instances of the translate property from ArticleState. You can change just this line and then typescript will complain to you during the build :)

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://")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is odd to put here. I assume this is needed for maybe ftp or gopher links? Do you know why this is here? what other protocols has fluent reader supported in the past?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much idea, this was not an open PR with a detailed description. Is it unnecessary? if so, is it safe to remove it or do you have to refactor it?

About protocols, tbh, idk, sorry

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! I'll look around in the codebase to try to understand what this is doing first.

) {
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)}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can be sectioned off into its other util function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can be sectioned off into its other util function.

To have a code that is easier to read, or is it something more technical?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More for expanding to different translation backends. Thinking about what this feature needs and how to make it ergonomic...

: 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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe untranslate rather than showOriginal? Other modifications for example could ultimately change the state of the article (e.g. configurations in Mercury parser), and this wouldn't be reverting them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untranslate sounds better!

"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