-
Notifications
You must be signed in to change notification settings - Fork 52
FEATURE: Experimental feature for viewing translated topics #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
assets/javascripts/discourse/components/show-original-content.gjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import Component from "@glimmer/component"; | ||
| import { tracked } from "@glimmer/tracking"; | ||
| import { action } from "@ember/object"; | ||
| import { service } from "@ember/service"; | ||
| import DButton from "discourse/components/d-button"; | ||
| import concatClass from "discourse/helpers/concat-class"; | ||
|
|
||
| export default class ShowOriginalContent extends Component { | ||
| @service router; | ||
| @tracked isTranslated = true; | ||
|
|
||
| constructor() { | ||
| super(...arguments); | ||
| this.isTranslated = !new URLSearchParams(window.location.search).has( | ||
| "show" | ||
| ); | ||
| } | ||
|
|
||
| @action | ||
| async showOriginal() { | ||
| const params = new URLSearchParams(window.location.search); | ||
| if (this.isTranslated) { | ||
| params.append("show", "original"); | ||
| } else { | ||
| params.delete("show"); | ||
| } | ||
| window.location.search = params.toString(); | ||
| } | ||
|
|
||
| get title() { | ||
| return this.isTranslated | ||
| ? "translator.content_translated" | ||
| : "translator.content_not_translated"; | ||
| } | ||
|
|
||
| <template> | ||
| <div class="discourse-translator_toggle-original"> | ||
| <DButton | ||
| @icon="language" | ||
| @title={{this.title}} | ||
| class={{concatClass "btn btn-default" (if this.isTranslated "active")}} | ||
| @action={{this.showOriginal}} | ||
| /> | ||
| </div> | ||
| </template> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe "Full page translation", type: :system do | ||
| fab!(:japanese_user) { Fabricate(:user, locale: "ja") } | ||
| fab!(:site_local_user) { Fabricate(:user, locale: "en") } | ||
| fab!(:author) { Fabricate(:user) } | ||
|
|
||
| fab!(:topic) { Fabricate(:topic, title: "Life strategies from The Art of War", user: author) } | ||
| fab!(:post_1) do | ||
| Fabricate(:post, topic: topic, raw: "The masterpiece isn’t just about military strategy") | ||
| end | ||
| fab!(:post_2) do | ||
| Fabricate(:post, topic: topic, raw: "The greatest victory is that which requires no battle") | ||
| end | ||
|
|
||
| let(:topic_page) { PageObjects::Pages::Topic.new } | ||
|
|
||
| before do | ||
| # topic translation setup | ||
| topic.set_detected_locale("en") | ||
| post_1.set_detected_locale("en") | ||
| post_2.set_detected_locale("en") | ||
|
|
||
| topic.set_translation("ja", "孫子兵法からの人生戦略") | ||
| topic.set_translation("es", "Estrategias de vida de El arte de la guerra") | ||
| post_1.set_translation("ja", "傑作は単なる軍事戦略についてではありません") | ||
| post_2.set_translation("ja", "最大の勝利は戦いを必要としないものです") | ||
| end | ||
|
|
||
| context "when the feature is enabled" do | ||
| before do | ||
| SiteSetting.translator_enabled = true | ||
| SiteSetting.allow_user_locale = true | ||
| SiteSetting.set_locale_from_cookie = true | ||
| SiteSetting.set_locale_from_param = true | ||
| SiteSetting.experimental_anon_language_switcher = true | ||
| SiteSetting.experimental_topic_translation = true | ||
| end | ||
|
|
||
| it "shows the correct language based on the selected language and login status" do | ||
| visit("/t/#{topic.slug}/#{topic.id}?lang=ja") | ||
| expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true) | ||
| expect(find(topic_page.post_by_number_selector(1))).to have_content("傑作は単なる軍事戦略についてではありません") | ||
|
|
||
| visit("/t/#{topic.id}") | ||
| expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true) | ||
| expect(find(topic_page.post_by_number_selector(1))).to have_content( | ||
| "The masterpiece isn’t just about military strategy", | ||
| ) | ||
|
|
||
| sign_in(japanese_user) | ||
| visit("/") | ||
| visit("/t/#{topic.id}") | ||
| expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more familiar with ruby so I genuinely am not sure, but in this case do we even want the
elsefor now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's just a note to indicate it's a missing feature. Should not cost much.