Refactor and improve encounter data handling and formatting
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
This commit is contained in:
parent
a32b698ebf
commit
f37808207e
8 changed files with 226 additions and 83 deletions
|
@ -1,5 +1,6 @@
|
|||
local _, addon = ...
|
||||
|
||||
-- Split original text by break-lines
|
||||
local function SplitParagraphs(text)
|
||||
local paragraphs = {}
|
||||
for paragraph in string.gmatch(text, "([^\n]+)") do
|
||||
|
@ -8,6 +9,7 @@ local function SplitParagraphs(text)
|
|||
return paragraphs
|
||||
end
|
||||
|
||||
-- Split text into sentences
|
||||
local function SplitSentences(paragraph)
|
||||
local sentences = {}
|
||||
for sentence in string.gmatch(paragraph, "([^%.%?!]+[%.%?!]?)[%s]*") do
|
||||
|
@ -19,10 +21,17 @@ local function SplitSentences(paragraph)
|
|||
return sentences
|
||||
end
|
||||
|
||||
-- Put break-lines
|
||||
local function ReplaceMultipleBreakLines(text)
|
||||
return text:gsub("\r?\n+", "\n\n")
|
||||
end
|
||||
|
||||
-- Because decimal numbers contain dot, remove space between those numbers
|
||||
local function FixDecimalNumbers(text)
|
||||
return text:gsub("(%d+)%.%s+(%d+)", "%1.%2")
|
||||
end
|
||||
|
||||
-- Fix translated text break-line based on original
|
||||
local function ParseParagraphs(original_text, translation_text)
|
||||
if original_text == "" or original_text == nil then
|
||||
return translation_text
|
||||
|
@ -58,8 +67,9 @@ local function ParseParagraphs(original_text, translation_text)
|
|||
table.insert(translation_paragraphs, table.concat(collected, " "))
|
||||
end
|
||||
|
||||
return ReplaceMultipleBreakLines(
|
||||
table.concat(translation_paragraphs, "\n")
|
||||
)
|
||||
local multilines = ReplaceMultipleBreakLines(table.concat(translation_paragraphs, "\n"))
|
||||
local fixedDecimalNumbers = FixDecimalNumbers(multilines)
|
||||
|
||||
return fixedDecimalNumbers
|
||||
end
|
||||
addon.API.ParseParagraphs = ParseParagraphs
|
Loading…
Add table
Add a link
Reference in a new issue