Translate visual novels in real time, while reading
Customize it however you wish
It works with Textractor letting you configure it for each separate game: transform the extracted text using JavaScript, translate it using a pre-defined translator or write your own, stylize the text window to blend in with the game.
It can replace a huge part of the built-in xdll
extensions for Textractor.
It allows you to perform and configure the following things for each game:
- Parsing and transforming the text extracted by Textractor, making it readable;
- Translating the transformed text;
- Transforming the translated text;
- Stylizing the text using HTML & CSS;
- The appearance of the text window.
Note
I don't have anything to do with the original software (Textractor) developers.
Currently, only Windows it supported.
You can use either ia32
or x64
versions depending on your OS.
Both versions (at least the x64 one) can work with both Textractor x86
and Textractor x64
.
- Download the binaries for your operating system in the Releases section (x86 x64).
- Unzip the archive to the directory where the app will be stored.
- Run the
TextractorTranslator.exe
file to run the application. - You will see the main window of the app:
- Hover the top right corner of the window, then click the settings button.
- You will see the settings window:
- Ensure you have Textractor installed. If you don't, install it before you continue. Remember the directory where you'll have installed it.
- Having Textractor installed, click a folder button to select the
Textractor.exe
executable of Textractor. - When you select either
Textractor x86
orTextractor x64
location, the other one will be selected automatically. If not, please, select it manually if you need it. - It's recommended to check the
Autorun
checkbox for the Textractor you're planning to run with. It depends on the bitness of the game process. Usually it'sx86
for visual novels. - After you have configured the path(s) to Textractor, you'll have to install the TextractorPipe extension. It can be done automatically by clicking the install button(s):
- After installing the extension, you can run Textractor by clicking one of the buttons:
- Now, text seen in Textractor should be displayed in Textractor Translator too:
History of this app
It also requires TextractorPipe.xdll
extension for Textractor: https://github.com/MRGRD56/textractor-integration-extensions The app will not work without this extension installed. It can be automatically installed right in the app settings. You might need to restart Textractor for the extension to start working.
You need some JavaScript knowledge to configure and use this application.
The purpose of this software is to be able to fine-tune Textractor in terms of parsing, modifying and translating texts for each separate game.
Requires TextractorPipe.xdll
extension for Textractor: https://github.com/MRGRD56/textractor-integration-extensions
The app will not work without this extension installed.
The extension can be installed right in the app:
config.languages = {
source: 'en',
target: 'ru'
};
const googleTranslate = Translators.GoogleTranslate();
// const libreTranslate = Translators.LibreTranslate({
// host: 'https://libretranslate.example.com'
// });
// implements caching translations of not really long sentences
// also optimizes translation if there are no English letters in text when translating from English - this kind of text returns as is
Translators.Custom = {};
/**
* @returns {Translator}
*/
Translators.Custom.MainTranslator = () => ({
translate: async (text, sourceLanguage, targetLanguage) => {
const doTranslate = () => googleTranslate.translate(text, sourceLanguage, targetLanguage);
if (sourceLanguage === 'en' && !/[a-z]+/i.test(text)) {
return text;
}
if (text.length <= 200) {
const translatedCache = memory.translatedCache ??= {};
const cachedTranslation = translatedCache[text];
if (cachedTranslation === undefined) {
const translation = await doTranslate();
translatedCache[text] = translation;
return translation;
} else {
return cachedTranslation;
}
}
return doTranslate();
}
});
config.translator = Translators.Custom.MainTranslator();
config.transformOriginal = ({text, meta}) => {
if (text.startsWith('Textractor:') || text.startsWith('vnreng:')) {
return undefined;
}
return text;
};
config.transformTranslated = (text) => {
return {
plain: text,
displayed: common.htmlifyText(text),
isHtml: true
};
};
const nameColor = '#ef9a9a';
/** @param {string} text */
common.htmlifyText = (text) => {
return text
.replace(/^([^:]+?): ["«](.+)["»][.!?]?$/, '<span style="color: ' + nameColor + ';">$1:</span> «$2»')
};
/** @param {string} text */
common.htmlifyTextJa = (text) => {
return text
.replace(/^([^:]+?): 「(.+)」[.!?]?$/, '<span style="color: ' + nameColor + ';">$1:</span> 「$2」')
};
common.style = (text, css) => {
return `<span style="${css}">${text}</span>`;
};
config.transformOriginal = ({text, meta}) => {
text = commonConfig.transformOriginal({text, meta});
if (!text) {
return text;
}
const result = text
.replaceAll(/([a-z]\d){2,}/g, '')
.replaceAll(/_stage_action/g, '');
if (!result?.trim()) {
return;
}
return result;
};
config.transformTranslated = (text) => text
.replaceAll('…', '...');
const {style, htmlifyText} = common;
config.transformOriginal = ({text, meta}) => {
text = commonConfig.transformOriginal({text, meta});
if (!text) {
return;
}
const englishText = /([【 ].+?)␂/.exec(text)?.[1]?.trim();
if (!englishText) {
return;
}
const plainText = englishText
.replace(/^【(.+?)】:(.+)$/, '$1: "$2"');
if (!plainText) {
return;
}
return {
plain: plainText,
displayed: htmlifyText(plainText),
isHtml: true
};
};
const {style, htmlifyText, htmlifyTextJa} = common;
config.languages.source = 'ja';
config.languages.target = 'en';
config.transformOriginal = ({text, meta}) => {
text = commonConfig.transformOriginal({text, meta});
if (!text) {
return;
}
const japaneseText = /␂([【 ]?.+?)␂/.exec(text)?.[1]?.trim();
if (!japaneseText) {
return;
}
const plainText = japaneseText
.replace(/^【(.+?)】:(.+)$/, '$1: $2');
if (!plainText) {
return;
}
return {
plain: plainText,
displayed: htmlifyTextJa(plainText),
isHtml: true
};
};
// /** @param {string} text */
// const htmlifyText = (text) => {
// return text
// .replace(/^([^:]+?): ["«](.+)["»][.!?]?$/, '<span style="color: #ffcdd2;">$1:</span> «$2»')
// };
config.transformOriginal = ({text, meta}) => {
text = commonConfig.transformOriginal({text, meta});
if (!text) {
return;
}
if (/^mv\d+$/.test(text) || text === 'sepia.AMP') {
return;
}
const normalText = text
.replaceAll('~', ',')
.replaceAll('\\n', ' ')
.replaceAll('�c', '...')
.replaceAll('�`', '~')
.replaceAll('�[', ' - ')
.replaceAll('\\k', '❄️');
const plainText = normalText
.replace(/^([^:"]+?)"(.+)"$/, '$1: "$2"');
// const displayedText = normalText
// .replace(/^(.+?)"(.*)"$/, '<b style="color: #ffcdd2;">$1:</b> "$2"');
return {
plain: plainText,
displayed: common.htmlifyText(plainText),
isHtml: true
};
};
config.transformOriginal = ({text, meta}) => {
text = commonConfig.transformOriginal({text, meta});
if (!text) {
return;
}
text = text
.replaceAll(/\d{4}\/\d{2}\/\d{2}\s\d{2}:\d{2}/g, '')
.replaceAll(/\S+\.(png|ogg|ani)/g, '')
.replaceAll(/\\n/g, ' ')
.replaceAll(/\\\w/g, '')
.replaceAll('�', '\'')
.replaceAll('#4', '~')
.replaceAll('#5', '♪')
.replace(/^'(.+)'$/, '"$1"')
.trim();
if (!text) {
return;
}
return text;
};
config.transformTranslated = (text) => {
text = text
.replace(/^— (.+)$/, '«$1»')
.replace(/^["'](.+)["']$/, '«$1»');
return text;
};
net
(the node.js module), httpRequest
("electron-request" library), queryString
("query-string" library), URL
, URLSearchParams
variables can help you create your custom translators.
/**
* @param config {{host?: string, format?: string, apiKey?: string}}
* @returns {Translator}
*/
Translators.LibreTranslateCustom = (config = {}) => ({
translate: async (text, sourceLanguage, targetLanguage) => {
const host = config.host || 'https://libretranslate.com';
const url = new URL('/translate', host).toString();
const responseData = await httpRequest(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
q: text,
source: sourceLanguage,
target: targetLanguage,
format: config.format,
api_key: config.apiKey
})
}).then((response) => response.json());
if (!responseData || responseData.translatedText == null) {
console.error('LibreTranslator unable to translate: ', responseData);
throw responseData;
}
console.log('custom translator response:', responseData);
return responseData.translatedText;
}
});
⚠️ Add a "retry" button if an error occurred while translating, also add auto retries (since v0.3.0 auto retries can be implemented by creating an own translator by extending the existing, in theory)⚠️ Fix dragging when history mode is enabledMaybe returnNot relevant anymore since HTTP has been replaced with named pipes200 OK
immediately after a reqeust (/sentence
) to the appIf Textractor Translator is not running, TTBridge shows errors when sendingProbably not relevant anymore/sentence
requests to the app, so Textractor crashesSometimes Google Translator works incorrectly, returning incomplete sentences as a translation, fix it if possible(not possible)- Limit history size
- ⏬ Maybe add "export history" feature
- ⏬ Maybe save history to the storage and also add "clear history" button
- ⏬ Add a switch to disable automatic translation of each phrase, phrases would be translated by clicking on the button
- ⏬ Add more appearance settings: text shadows (✅), outline (✅), text only background (✅), vertical and horizontal text alignment
- Add a dictionary of words, you can add words there while reading and learn them later
- Add DeepL translator, improve custom translator creating feature
- Maybe move languages and translator settings somewhere from profiles code
- Profiles: add translator and languages options to
config.transformOriginal
Profiles: addThetranslators
object with predefined translators (objects, not names) in itDefinedTranslators
object has been added- ⏬ Add Google Translate extension if it's possible
Add aTheglobal
object so that it's possible to store some global (mutable) variablesmemory
variable has been added for this purposeNot relevant⚠️ Fix this: https://user-images.githubusercontent.com/35491968/215345061-34eb33c0-68f2-4651-b826-422856eff69c.pngДобавить возможность настраивать конфиг TTBridge (и вернуть туда JSON конфиг), включая возможность настройки порта для коммуникации TTBridge и Textractor Translator- Добавить возможность настраивать TextractorPipe, включая возможность фильтрации отправляемых данных (например только
isCurrentSelect
или все без исключения) - Добавить перевод с контекстом для более точного перевода
See also: https://github.com/MRGRD56/RealTimeTranslator
readme
coming soon...