Skip to content

Commit 1839816

Browse files
committed
Add configurable custom file limits
Implemented configurable limits (both lines and characters) for searching regex match in a custom/MCM file, using customTxtDefinition.txt. This is needed for finding translatable strings in files where a match can't be found within the previous limits, causing the files not being recognized. This can occur in files where only a few strings are translatable. Changes: - Added `CustomTypeLineLimit` and `CustomTypeSizeLimit` to customTxtDefinition.txt. - Added `iLineLimit` & `iSizeLimit` properties to `rcustomTxtDefinition` and `getLineLimit` & `getSizeLimit` methods to `pcustomTxtDefinition`. - Edited `tCustomTxt.mcmDecider()` function to use the configurable limits instead of the fixed ones. Previous values are set as default.
1 parent 9aa38d6 commit 1839816

2 files changed

Lines changed: 47 additions & 9 deletions

File tree

Misc/customTxtDefinition.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#CustomTypeIsFallback_1=false define if the pattern is the fallback if no pattern in the list can match.
77
#CustomTypeSaveLangSuffixe_1=true if true, rebuild the output name with the target language suffixe (ex: mcmcfile_en.txt)
88
#CustomTypeSearchByLine_1=true if true, analyse the text with a single match per line, if false, process a match-again routine over the whole text in a raw. The later process might be very slow on big files.
9+
#CustomTypeLineLimit_1=50 define the maximum number of lines to look for a regex match, starting from the beginning.
10+
#CustomTypeSizeLimit_1=2048 define the maximum number of characters to look for a regex match, starting from the first one.
911
#---------
1012
SupportedTxtExt=*.txt;*.ini;*.csv;*.pas;*.xml;*.json;*.pot;
1113
#---------
@@ -19,6 +21,8 @@ CustomTypeRestrictExt_1=.txt
1921
CustomTypeSaveLangSuffixe_1=true
2022
CustomTypeIsFallback_1=false
2123
CustomTypeSearchByLine_1=true
24+
CustomTypeLineLimit_1=50
25+
CustomTypeSizeLimit_1=2048
2226
#---------
2327
CustomTypeRegex_2=^(?![;#])([^=]+)====(?!.*={2,})(.*)$
2428
CustomTypeLabel_2=res
@@ -28,6 +32,8 @@ CustomTypeRestrictExt_2=.ini
2832
CustomTypeSaveLangSuffixe_2=false
2933
CustomTypeIsFallback_2=false
3034
CustomTypeSearchByLine_2=true
35+
CustomTypeLineLimit_2=50
36+
CustomTypeSizeLimit_2=2048
3137
#---------
3238
CustomTypeRegex_3=^(?!#)(.+~[0-9a-fA-F]+)\|.*?name\("(.+?)"\)(?:\|.*?name\("(.+?)"\))?
3339
CustomTypeLabel_3=rftp
@@ -37,6 +43,8 @@ CustomTypeRestrictExt_3=.txt
3743
CustomTypeSaveLangSuffixe_3=false
3844
CustomTypeIsFallback_3=false
3945
CustomTypeSearchByLine_3=true
46+
CustomTypeLineLimit_3=50
47+
CustomTypeSizeLimit_3=2048
4048
#---------
4149
CustomTypeRegex_4=^(0x.+~[^\|]+)\|([^\|]+)
4250
CustomTypeLabel_4=descfw
@@ -46,6 +54,8 @@ CustomTypeRestrictExt_4=.txt
4654
CustomTypeSaveLangSuffixe_4=false
4755
CustomTypeIsFallback_4=false
4856
CustomTypeSearchByLine_4=true
57+
CustomTypeLineLimit_4=50
58+
CustomTypeSizeLimit_4=2048
4959
#-----fallback: catch each line directly--------
5060
CustomTypeRegex_5=^(.*)$
5161
CustomTypeLabel_5=Generic
@@ -55,6 +65,8 @@ CustomTypeRestrictExt_5=*
5565
CustomTypeSaveLangSuffixe_5=false
5666
CustomTypeIsFallback_5=true
5767
CustomTypeSearchByLine_5=true
68+
CustomTypeLineLimit_5=50
69+
CustomTypeSizeLimit_5=2048
5870
#---------
5971
CustomTypeRegex_6=<(description|moduleName)>(.*?)<\/\1>
6072
CustomTypeLabel_6=fomod
@@ -64,6 +76,8 @@ CustomTypeRestrictExt_6=.txt
6476
CustomTypeSaveLangSuffixe_6=false
6577
CustomTypeIsFallback_6=false
6678
CustomTypeSearchByLine_6=false
79+
CustomTypeLineLimit_6=50
80+
CustomTypeSizeLimit_6=2048
6781
#---------testPOT
6882
#CustomTypeRegex_7=^(?!#)msgctxt "(.*?)"$^(?!#)msgid "(.*?)"$
6983
#CustomTypeRegex_7=msgctxt "(.*?)".*?msgid "(.*?)"
@@ -74,6 +88,8 @@ CustomTypeSearchByLine_6=false
7488
#CustomTypeSaveLangSuffixe_7=false
7589
#CustomTypeIsFallback_7=false
7690
#CustomTypeSearchByLine_7=false
91+
#CustomTypeLineLimit_7=50
92+
#CustomTypeSizeLimit_7=2048
7793
#---------test
7894
#CustomTypeRegex_9=^(?!#)msgctxt "(.*?)"$^(?!#)msgid "(.*?)"$
7995
#CustomTypeRegex_9=msgid "(.*?)"$
@@ -84,6 +100,8 @@ CustomTypeSearchByLine_6=false
84100
#CustomTypeSaveLangSuffixe_9=false
85101
#CustomTypeIsFallback_9=false
86102
#CustomTypeSearchByLine_9=true
103+
#CustomTypeLineLimit_9=50
104+
#CustomTypeSizeLimit_9=2048
87105
#---------test
88106
#CustomTypeRegex_8="form_id": "(.*?)",.*?"original": "(.*?)",
89107
#CustomTypeRegex_8="original": "(.*?)",
@@ -94,4 +112,5 @@ CustomTypeSearchByLine_6=false
94112
#CustomTypeSaveLangSuffixe_8=false
95113
#CustomTypeIsFallback_8=false
96114
#CustomTypeSearchByLine_8=true
97-
115+
#CustomTypeLineLimit_8=50
116+
#CustomTypeSizeLimit_8=2048

TESVT_Const.pas

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ rcustomTxtDefinition = record
105105
iIdBackref: integer;
106106
bUseSaveLangSuffixe: boolean;
107107
stats: integer;
108+
iLineLimit: integer;
109+
iSizeLimit: integer;
108110
end;
109111

110112
pcustomTxtDefinition = ^rcustomTxtDefinition;
@@ -123,6 +125,8 @@ tCustomTxt = class
123125
function getrefId(i: integer): integer;
124126
function getLabel(i: integer): string;
125127
function getEncoding(i: integer): tencoding;
128+
function getLineLimit(i: integer): integer;
129+
function getSizeLimit(i: integer): integer;
126130
function mcmDecider(f: tstringList): integer;
127131
function isValidTxtExt(ext: string): boolean;
128132
function isSearchByLine(i: integer): boolean;
@@ -1091,6 +1095,8 @@ constructor tCustomTxt.Create(l: tstringList);
10911095
p.bIsFallback := strtobooldef(l.Values[format('CustomTypeIsFallback_%d', [i])], false);
10921096
p.bUseSaveLangSuffixe := strtobooldef(l.Values[format('CustomTypeSaveLangSuffixe_%d', [i])], false);
10931097
p.bSearchByLine := strtobooldef(l.Values[format('CustomTypeSearchByLine_%d', [i])], true);
1098+
p.iLineLimit := strtointdef(l.Values[format('CustomTypeLineLimit_%d', [i])], 50);
1099+
p.iSizeLimit := strtointdef(l.Values[format('CustomTypeSizeLimit_%d', [i])], 2048);
10941100

10951101
end;
10961102
// define fallback
@@ -1195,13 +1201,26 @@ procedure tCustomTxt.resetstat;
11951201
pcustomTxtDefinition(lCustomTxtParamList[i]).stats := 0;
11961202
end;
11971203

1204+
function tCustomTxt.getLineLimit(i: integer): integer;
1205+
var
1206+
p: pcustomTxtDefinition;
1207+
begin
1208+
p := lCustomTxtParamList[i];
1209+
Result := p.iLineLimit;
1210+
end;
1211+
1212+
function tCustomTxt.getSizeLimit(i: integer): integer;
1213+
var
1214+
p: pcustomTxtDefinition;
1215+
begin
1216+
p := lCustomTxtParamList[i];
1217+
Result := p.iSizeLimit;
1218+
end;
1219+
11981220
function tCustomTxt.mcmDecider(f: tstringList): integer;
11991221
var
12001222
i, j, m: integer;
12011223
RegEx: tperlRegex;
1202-
const
1203-
iLineLimit = 50;
1204-
iSizeLimit = 2048;
12051224
begin
12061225
Result := -1;
12071226
if lCustomTxtParamList.Count = 0 then
@@ -1226,13 +1245,13 @@ function tCustomTxt.mcmDecider(f: tstringList): integer;
12261245
RegEx.subject := f[i];
12271246
if RegEx.Match then
12281247
incStat(j);
1229-
if i > iLineLimit then
1248+
if i > getLineLimit(j) then
12301249
break;
12311250
end;
12321251
end
12331252
else
12341253
begin
1235-
RegEx.subject := copy(f.text, 1, iSizeLimit);
1254+
RegEx.subject := copy(f.text, 1, getSizeLimit(j));
12361255
if RegEx.Match then
12371256
repeat
12381257
incStat(j);
@@ -1569,7 +1588,7 @@ procedure enableToolBar(tb: TToolBar; b: boolean);
15691588
function isChar_WordDelimiter(c: char): boolean;
15701589
begin
15711590
case c of
1572-
#0 .. #32, '.', ',', '?', '!', ':', ';', '(', ')', '[', ']', '{', '}', '°', '"', '/', '\', '|', '+', '*', '=', '%', '&', '>', '<', '¡', '¿', '$', '@', '§', '#', '~', '^', '_',
1591+
#0 .. #32, '.', ',', '?', '!', ':', ';', '(', ')', '[', ']', '{', '}', '°', '"', '/', '\', '|', '+', '*', '=', '%', '&', '>', '<', '¡', '¿', '$', '@', '§', '#', '~', '^', '_',
15731592
#160, #8239,
15741593
// Non-breaking spaces ,
15751594
#8230, // Suspension points
@@ -1587,15 +1606,15 @@ function isChar_WordDelimiterExtended(c: char): boolean;
15871606
Result := isChar_WordDelimiter(c);
15881607
if not Result then
15891608
case c of
1590-
'-', '''', #8209, '’', #8720:
1609+
'-', '''', #8209, '’', #8720:
15911610
Result := true;
15921611
end;
15931612
end;
15941613

15951614
function isChar_WordDelimitersEndLine(c: char): boolean;
15961615
begin
15971616
case c of
1598-
'.', '?', '!', '¡', '¿', #8230:
1617+
'.', '?', '!', '¡', '¿', #8230:
15991618
Result := true;
16001619
else
16011620
Result := false;

0 commit comments

Comments
 (0)