11import { CustomSidebarTool , sideTool } from "./Utils/ToolManager" ;
22import { getMwApi } from "../Utilities/MediaWikiJsApi" ;
3- import { getCurrentPageInfo , getEnglishRevisionId , PageInfo , PageType } from "../Utilities/PageUtils" ;
3+ import {
4+ getCurrentPageContent ,
5+ getCurrentPageInfo ,
6+ getEnglishRevisionId ,
7+ PageInfo ,
8+ PageType
9+ } from "../Utilities/PageUtils" ;
410import { getCurrentLanguage , setCurrentLanguage } from "../Storage/ScriptDb" ;
511import { getLangInfoFor , LanguagesInfo } from "../Internalization/I18nConstants" ;
12+ import { TranslatedArticlesWorker } from "./Workers/TranslatedArticlesWorker" ;
13+ import { addWorkerResultToUi } from "./TranslatedArticlesUi" ;
14+ import { WikiTextParser } from "../Utilities/WikiTextParser" ;
615
716export const copyCurrentRevisionIdTool = ( ) : CustomSidebarTool => {
817 const showCallback = ( info : PageInfo ) => {
@@ -138,6 +147,34 @@ export const changeActiveLanguageTool = (): CustomSidebarTool => {
138147 } ) ;
139148} ;
140149
150+ export const refreshTranslatedArticles = ( ) : CustomSidebarTool => {
151+ const handler = async ( ) => {
152+ console . debug ( 'Rerunning translated articles worker' ) ;
153+
154+ const pageInfo = getCurrentPageInfo ( ) ;
155+ const contentToParse = await getCurrentPageContent ( ) ;
156+
157+ const parser = new WikiTextParser ( ) ;
158+ parser . parse ( contentToParse ) ;
159+
160+ const translatedArticleWorker = new TranslatedArticlesWorker ( pageInfo ) ;
161+ translatedArticleWorker . run ( parser )
162+ . then ( r => {
163+ console . debug ( r ) ;
164+ console . debug ( 'Translated articles worker done' ) ;
165+
166+ addWorkerResultToUi ( r ) ;
167+ } ) ;
168+ } ;
169+
170+ return sideTool ( {
171+ name : "refresh-translated-articles" ,
172+ displayText : "Refresh translated articles" ,
173+ handler : handler
174+ } ) ;
175+ } ;
176+
141177export const allSidebarTools = [
142- changeActiveLanguageTool ( ) , copyCurrentRevisionIdTool ( ) , copyEnglishRevisionIdTool ( ) , createTranslationTool ( )
178+ changeActiveLanguageTool ( ) , copyCurrentRevisionIdTool ( ) , copyEnglishRevisionIdTool ( ) , createTranslationTool ( ) ,
179+ refreshTranslatedArticles ( )
143180] ;
0 commit comments