|
1 | 1 | import { ajax } from "discourse/lib/ajax"; |
2 | 2 | import { popupAjaxError } from "discourse/lib/ajax-error"; |
| 3 | +import { withSilencedDeprecations } from "discourse/lib/deprecated"; |
3 | 4 | import { withPluginApi } from "discourse/lib/plugin-api"; |
4 | | -import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; |
5 | 5 | import { i18n } from "discourse-i18n"; |
| 6 | +import LanguageSwitcher from "../components/language-switcher"; |
6 | 7 | import ToggleTranslationButton from "../components/post-menu/toggle-translation-button"; |
7 | 8 | import TranslatedPost from "../components/translated-post"; |
8 | 9 |
|
9 | 10 | function initializeTranslation(api) { |
10 | 11 | const siteSettings = api.container.lookup("service:site-settings"); |
| 12 | + if (!siteSettings.translator_enabled) { |
| 13 | + return; |
| 14 | + } |
| 15 | + |
11 | 16 | const currentUser = api.getCurrentUser(); |
12 | 17 |
|
13 | | - if (!currentUser || !siteSettings.translator_enabled) { |
14 | | - return; |
| 18 | + if (!currentUser && siteSettings.experimental_anon_language_switcher) { |
| 19 | + api.headerIcons.add( |
| 20 | + "discourse-translator_language-switcher", |
| 21 | + LanguageSwitcher, |
| 22 | + { before: ["search"] } |
| 23 | + ); |
15 | 24 | } |
16 | 25 |
|
17 | | - customizePostMenu(api); |
| 26 | + if (currentUser) { |
| 27 | + customizePostMenu(api); |
| 28 | + } |
18 | 29 | } |
19 | 30 |
|
20 | 31 | function customizePostMenu(api, container) { |
@@ -123,24 +134,6 @@ function customizeWidgetPostMenu(api) { |
123 | 134 | post.set("translated_text", ""); |
124 | 135 | } |
125 | 136 | }); |
126 | | - |
127 | | - api.addPostMenuButton("translate", (attrs, state) => { |
128 | | - if (!attrs.can_translate) { |
129 | | - return; |
130 | | - } |
131 | | - |
132 | | - const [action, title] = !state.isTranslated |
133 | | - ? ["translate", "translator.view_translation"] |
134 | | - : ["hideTranslation", "translator.hide_translation"]; |
135 | | - |
136 | | - return { |
137 | | - action, |
138 | | - title, |
139 | | - icon: "globe", |
140 | | - position: "first", |
141 | | - className: state.isTranslated ? "translated" : null, |
142 | | - }; |
143 | | - }); |
144 | 137 | } |
145 | 138 |
|
146 | 139 | export default { |
|
0 commit comments