Skip to content
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

add Block Untranslated Messages option #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
19 changes: 16 additions & 3 deletions PolyglotTranslator.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--[[ --- START OF VERSION ---
MAJOR:1
MINOR:5
PATCH:1
PATCH:2
CHANGELOG
- Fixed broken ChatGPT translation method.
- Fixed broken restoring of translation method upon script startup.
Expand All @@ -11,6 +11,7 @@ CHANGELOG
- Refactoring and code cleanup.
- Added Portuguese localization.
- Credits to all contributors.
- Added `Block Untranslated Messages` option
--- END OF VERSION --- ]]

-- LEGACY
Expand Down Expand Up @@ -586,7 +587,13 @@ TranslationMethodOptions = {
function moduleExports.translateText(text, targetLang, translationMethod, onSuccess)
if translationMethods[translationMethod] then
translationMethods[translationMethod](text, targetLang, function(translation, sourceLang)
onSuccess(translation, sourceLang:lower())
if (Config.blockUntranslatedMessages) then
if translation ~= text then
onSuccess(translation, sourceLang:lower())
end
else
onSuccess(translation, sourceLang:lower())
end
end)
end
end
Expand Down Expand Up @@ -910,6 +917,8 @@ local engTranslations = {
translateYourselfD = "Translate messages sent by yourself",
translatedMessageDisplay = "Translated Message Display",
translatedMessageDisplayD = "Location of translated Message. You need to click to apply change",
blockUntranslatedMessages = "Block Untranslated Messages",
blockUntranslatedMessagesD = "Only show messages where the translated text is different from the original",
scriptSettings = "Other Settings For Polyglot Translator",
scriptSettingsD = "Including color settings and updates",
playerNameColor = "Player Name Color",
Expand Down Expand Up @@ -1568,6 +1577,7 @@ Config = {

translateOn = true,
translateSelf = false,
blockUntranslatedMessages = false,

translatedMsgLocation = 5,

Expand Down Expand Up @@ -1598,6 +1608,9 @@ menu.my_root():list_select(LOC.translatedMessageDisplay, {}, LOC.translatedMessa
TranslatedMsgLocationOptions, #TranslatedMsgLocationOptions,
function(index, option, prevIndex, clickType) Config.translatedMsgLocation = index end)

menu.my_root():toggle(LOC.blockUntranslatedMessages, {}, LOC.blockUntranslatedMessagesD,
function(on) Config.blockUntranslatedMessages = on end)

-- CommandRef|CommandUniqPtr menu.list(CommandRef parent, Label menu_name, table<any, string> command_names = {}, Label help_text = "", ?function on_click = nil, ?function on_back = nil, ?function on_active_list_update = nil)
local settingTranslationMenu = menu.list(menu.my_root(), LOC.scriptSettings, {}, LOC.scriptSettingsD)
local colorTranslation = menu.list(settingTranslationMenu, LOC.playerNameColor)
Expand Down Expand Up @@ -2180,4 +2193,4 @@ json = require "src.lib.external.json"
polyglotUtils = require "src.lib.utils"
LOC = require "src.lib.localization"

require "src.lib.menus"
require "src.lib.menus"