1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "gL10nMem.hxx"
//#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
/*****************************************************************************
************************ G L 1 0 N M E M . C X X ************************
*****************************************************************************
* This is the interface to translation memory that links between the converts
* and to the language files. The memory contains the actual text info
***********************d******************************************************/
/******************* G L O B A L D E F I N I T I O N *******************/
l10nMem_impl * l10nMem_impl::mcImpl = nullptr;
bool l10nMem_impl::mbVerbose = false;
bool l10nMem_impl::mbDebug = false;
/********************** I M P L E M E N T A T I O N **********************/
l10nMem::l10nMem()
{
l10nMem_impl::mcImpl = new l10nMem_impl();
}
/********************** I M P L E M E N T A T I O N **********************/
l10nMem::~l10nMem()
{
delete l10nMem_impl::mcImpl;
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem::setShowVerbose()
{
l10nMem_impl::mbVerbose = true;
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem::setShowDebug()
{
l10nMem_impl::mbDebug = true;
}
/********************** I M P L E M E N T A T I O N **********************/
int l10nMem::showError(const std::string& sText, int iLineNo)
{ return l10nMem_impl::mcImpl->showError(sText, iLineNo); }
int l10nMem::showWarning(const std::string& sText, int iLineNo)
{ return l10nMem_impl::mcImpl->showWarning(sText, iLineNo); }
void l10nMem::showDebug(const std::string& sText, int iLineNo)
{ l10nMem_impl::mcImpl->showDebug(sText, iLineNo); }
void l10nMem::showVerbose(const std::string& sText, int iLineNo)
{ l10nMem_impl::mcImpl->showVerbose(sText, iLineNo); }
bool l10nMem::isError()
{ return l10nMem_impl::mcImpl->mbInError; }
void l10nMem::setModuleName(const std::string& sM)
{ l10nMem_impl::mcImpl->setModuleName(sM); }
const std::string& l10nMem::getModuleName ()
{ return l10nMem_impl::mcImpl->getModuleName(); }
void l10nMem::setLanguage(const std::string& sL, bool bC)
{ l10nMem_impl::mcImpl->mcDb.setLanguage(sL, bC); }
void l10nMem::setConvert(bool bC, bool bS)
{ l10nMem_impl::mcImpl->mcDb.setConvert(bC, bS); }
void l10nMem::loadEntryKey(int iL, const std::string& sS, const std::string& sK, const std::string& sO, const std::string& sT, bool bI)
{ l10nMem_impl::mcImpl->loadEntryKey(iL, sS, sK, sO, sT, bI); }
void l10nMem::setSourceKey(int iL, const std::string& sF, const std::string& sK, const std::string& sT, bool bM)
{ l10nMem_impl::mcImpl->setSourceKey(iL, sF, sK, sT, bM); }
void l10nMem::saveTemplates(const std::string& sT, bool bK, bool bF)
{ l10nMem_impl::mcImpl->saveTemplates(*this, sT, bK, bF); }
void l10nMem::saveLanguages(const std::string& sT, bool bF)
{ l10nMem_impl::mcImpl->saveLanguages(*this, sT, bF); }
void l10nMem::showNOconvert ()
{ l10nMem_impl::mcImpl->showNOconvert(); }
void l10nMem::convertToInetString(std::string& sT)
{ l10nMem_impl::mcImpl->convertToInetString(sT); }
void l10nMem::convertFromInetString(std::string& sT)
{ l10nMem_impl::mcImpl->convertFromInetString(sT); }
int l10nMem::prepareMerge()
{ return l10nMem_impl::mcImpl->mcDb.prepareMerge(); }
void l10nMem::dumpMem(const std::string& sT)
{ l10nMem_impl::mcImpl->dumpMem(sT); }
bool l10nMem::getMergeLang(std::string& sL, std::string& sT)
{ return l10nMem_impl::mcImpl->mcDb.getMergeLang(sL, sT); }
/********************** I M P L E M E N T A T I O N **********************/
l10nMem_impl::l10nMem_impl()
:
mbInError(false)
{
}
/********************** I M P L E M E N T A T I O N **********************/
l10nMem_impl::~l10nMem_impl()
{
}
/********************** I M P L E M E N T A T I O N **********************/
int l10nMem_impl::showError(const std::string& sText, int iLineNo)
{
mbInError = true;
formatAndShowText("ERROR", iLineNo, sText);
return 1;
}
/********************** I M P L E M E N T A T I O N **********************/
int l10nMem_impl::showWarning(const std::string& sText, int iLineNo)
{
formatAndShowText("WARNING", iLineNo, sText);
return 2;
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::showDebug(const std::string& sText, int iLineNo)
{
if (mbDebug)
formatAndShowText("DEBUG", iLineNo, sText);
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::showVerbose(const std::string& sText, int iLineNo)
{
if (mbVerbose)
formatAndShowText("INFO", iLineNo, sText);
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::setModuleName(const std::string& sModuleName)
{
msModuleName = sModuleName;
}
/********************** I M P L E M E N T A T I O N **********************/
const std::string& l10nMem_impl::getModuleName()
{
return msModuleName;
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::loadEntryKey(int iLineNo,
const std::string& sSourceFile,
const std::string& sKey,
const std::string& sMsgId,
const std::string& sMsgStr,
bool bIsFuzzy)
{
if (mcDb.mbConvertMode)
convEntryKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
else if (!mcDb.miCurLangInx)
mcDb.loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId);
else
mcDb.loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::setSourceKey(int iLineNo,
const std::string& sSourceFile,
const std::string& sKey,
const std::string& sMsgId,
bool bMustExist)
{
std::string newText(sMsgId);
int i;
// time to escape " and \ if contained in text or key
for (i = 0; (i = newText.find("\\", i)) != (int)std::string::npos;)
{
++i;
if (i < (int)newText.size() &&
(newText[i] == '\\' || newText[i] == '<' || newText[i] == '>' ||
newText[i] == 'n' || newText[i] == 't' || newText[i] == 'r' ||
newText[i] == '\''))
++i;
else
{
newText.insert(i-1, "\\");
++i;
}
}
for (i = 0; (i = newText.find("\"", i)) != (int)std::string::npos;)
{
newText.insert(i, "\\");
i += 2;
}
// if key exist update state
if (mcDb.locateKey(iLineNo, sSourceFile, sKey, newText, false))
{
mcDb.mcENUSlist[mcDb.miCurENUSinx].meState = l10nMem::ENTRY_NORMAL;
}
else
{
if (bMustExist)
throw l10nMem::showError("key " + sKey + " does not exist");
else
// add key, if changed text, this is wrong but handled in reorganize
mcDb.addKey(iLineNo, sSourceFile, sKey, newText, l10nMem::ENTRY_ADDED);
}
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::saveTemplates(l10nMem& cMem, const std::string& sTargetDir, bool bKid, bool bForce)
{
int iE, iEsize = mcDb.mcENUSlist.size();
std::string sFileName = msModuleName + ".pot";
// Dummy to satisfy compiler
if (bKid)
return;
// and reorganize db if needed
mcDb.miCurFileInx = 0;
mcDb.reorganize(false);
// no save if there has been errors
if(!needWrite(sFileName, bForce))
return;
//JIX save HANDLE KID
// Save en-US
convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName);
savePo.startSave("templates/", sFileName);
for (iE = 1; iE < iEsize; ++iE)
{
l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE];
// remove deleted entries
if (cE.meState == l10nMem::ENTRY_DELETED)
continue;
savePo.save(mcDb.mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", false);
}
savePo.endSave();
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool bForce)
{
int iE, iEsize = mcDb.mcENUSlist.size();
int iL, iLsize = mcDb.mcLangList.size();
std::string sFileName = msModuleName + ".po";
// and reorganize db if needed
mcDb.miCurFileInx = 0;
mcDb.reorganize(true);
// no save if there has been errors
if(!needWrite(sFileName, bForce))
return;
// save all languages
for (iL = 1; iL < iLsize; ++iL)
{
// only save language file if modified
if (!mcDb.mcLangList[iL].mbChanged)
continue;
mcDb.mcLangList[iL].mbChanged = false;
convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName);
savePo.startSave(mcDb.mcLangList[iL].msName + "/", sFileName);
for (iE = 1; iE < iEsize; ++iE)
{
l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE];
l10nMem_lang_entry& cL = cE.mcLangText[iL];
bool bF = cL.mbFuzzy;
// remove deleted entries
if (cE.meState == l10nMem::ENTRY_DELETED)
continue;
savePo.save(mcDb.mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, cL.msMsgStr, bF);
}
savePo.endSave();
}
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::showNOconvert ()
{
int iE, iEsize = mcDb.mcENUSlist.size();
for (iE = 1; iE < iEsize; ++iE)
{
l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE];
if (cE.meState == l10nMem::ENTRY_DELETED)
{
showError("template key(" + cE.msKey + ") msgId(" + cE.msMsgId + ") not in pot file", 0);
}
}
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::dumpMem(const std::string& sFileName)
{
// and reorganize db if needed
mcDb.reorganize(false);
// no save if there has been errors
if(!needWrite(sFileName, true))
return;
// JIX (dumpMem)
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText)
{
std::cout << sType;
if (mcDb.miCurFileInx > 0)
std::cout << " in " << mcDb.mcFileList[mcDb.miCurFileInx].msFileName;
if (iLineNo)
std::cout << "(" << iLineNo << ")";
std::cout << ": " << sText << std::endl;
}
/********************** I M P L E M E N T A T I O N **********************/
bool l10nMem_impl::needWrite(const std::string sFileName, bool bForce)
{
int iE, iEsize = mcDb.mcENUSlist.size();
int iCntDeleted = 0, iCntChanged = 0, iCntAdded = 0;
// no save if there has been errors
if (mbInError)
throw l10nMem::showError("Cannot save due to previous errors");
// Check number of changes
for (iE = 1; iE < iEsize; ++iE)
{
l10nMem_enus_entry& cur = mcDb.mcENUSlist[iE];
if (cur.meState == l10nMem::ENTRY_ADDED)
++iCntAdded;
if (cur.meState == l10nMem::ENTRY_CHANGED)
{
++iCntChanged;
if (mcDb.mbStrictMode)
cur.meState = l10nMem::ENTRY_NORMAL;
}
if (cur.meState == l10nMem::ENTRY_DELETED)
++iCntDeleted;
}
if (!mcDb.mbConvertMode)
iCntDeleted -= iCntChanged;
if (!iCntAdded && !iCntChanged && !iCntDeleted)
{
std::cout << "genLang: No changes in " << sFileName;
if (bForce)
std::cout << ", -o switch used, so files are saved" << std::endl;
else
std::cout << " skipping \"save\"" << std::endl;
return bForce;
}
std::cout << "genLang statistics: " << iCntDeleted << " deleted, "
<< iCntChanged << " changed, "
<< iCntAdded << " added entries in "
<< sFileName << std::endl;
return true;
}
/********************** I M P L E M E N T A T I O N **********************/
bool l10nMem_impl::convFilterWarning(const std::string& sSourceFile,
const std::string& sKey,
const std::string& sMsgId)
{
// silent ignore deleted messages
if (sMsgId == "-" || sMsgId == "")
return true;
if (msModuleName == "help_sbasic")
{
if (sSourceFile == "sbasic.tree")
return true;
}
if (msModuleName == "help_scalc")
{
if (sSourceFile == "scalc.tree")
return true;
}
if (msModuleName == "help_schart")
{
if (sSourceFile == "schart.tree")
return true;
}
if (msModuleName == "help_shared")
{
if (sSourceFile == "shared.tree")
return true;
}
if (msModuleName == "help_simpress")
{
if (sSourceFile == "simpress.tree")
return true;
}
if (msModuleName == "help_smath")
{
if (sSourceFile == "smath.tree")
return true;
}
if (msModuleName == "help_swriter")
{
if (sSourceFile == "swriter.tree")
return true;
}
if (msModuleName == "officecfg")
{
if (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" && sKey == "Writer.Insert.Caption.CaptionOrderNumberingFirst")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" && sKey == "Writer.Layout.Other.TabStop")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" && sKey == "WriterCommands.UserInterface.Commands..uno:FlipVertical.Label")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" && sKey == "WriterCommands.UserInterface.Commands..uno:FlipHorizontal.Label")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" && sKey == "Common.View.Localisation.AutoMnemonic")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" && sKey == "Common.View.Localisation.DialogScale")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/SlideTransitions.UIName")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/CustomAnimations.UIName")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/MasterPages.UIName")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/Layouts.UIName")
return true;
if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/TableDesign.UIName")
return true;
}
if (msModuleName == "readlicense_oo")
{
if (sSourceFile == "docs/readme/readme.xrm")
{
if (sKey == "BDB11")
return true;
if (sKey == "BDB2a")
return true;
if (sKey == "BDB3a")
return true;
if (sKey == "BDB4a")
return true;
}
}
if (msModuleName == "scp2")
{
if (sSourceFile == "source/binfilter/module_binfilter.ulf")
return true;
if (sSourceFile == "source/binfilter/registryitem_binfilter.ulf")
return true;
}
if (msModuleName == "sdext")
{
if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/Addons.xcu")
return true;
if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/extension/SunPresentationMinimizer.xcu")
return true;
if (sSourceFile == "source/presenter/help/en-US/com.sun.PresenterScreen/presenter.xhp")
return true;
if (sSourceFile == "source/presenter/registry/data/org/openoffice/Office/extension/PresenterScreen.xcu")
return true;
}
if (msModuleName == "sd")
{
if (sSourceFile == "source/ui/dlg/celltempl.src")
return true;
}
if (msModuleName == "svx")
{
if (sSourceFile == "source/dialog/fontwork.src")
{
if (sKey == "RID_SVXSTR_FONTWORK_FORM1.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM2.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM3.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM4.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM5.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM6.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM7.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM8.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM9.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM10.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM11.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_FORM12.String.Text")
return true;
if (sKey == "RID_SVXSTR_FONTWORK_UNDOCREATE.String.Text")
return true;
}
if (sSourceFile == "source/dialog/sdstring.src")
{
if (sKey == "RID_SVXSTR_LIGHTGREY.String.Text")
return true;
if (sKey == "RID_SVXSTR_LIGHTBLUE.String.Text")
return true;
if (sKey == "RID_SVXSTR_LIGHTGREEN.String.Text")
return true;
if (sKey == "RID_SVXSTR_LIGHTCYAN.String.Text")
return true;
if (sKey == "RID_SVXSTR_LIGHTRED.String.Text")
return true;
if (sKey == "RID_SVXSTR_LIGHTMAGENTA.String.Text")
return true;
if (sKey == "RID_SVXSTR_COLOR_SUN.String.Text")
return true;
}
if (sSourceFile == "source/svdraw/svdstr.src" && sKey == "SIP_XA_FORMTXTSTDFORM.String.Text")
return true;
}
return false;
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::convEntryKey(int iLineNo,
const std::string& sSourceFile,
const std::string& sKey,
const std::string& sMsgId,
const std::string& sMsgStr,
bool bIsFuzzy)
{
std::vector<int> ivEntryList;
std::string curFileName;
std::string curKeyUpper;
int curFileIndex, curENUSindex, i, iSize;
// filter out dummy messages, silently
if (convFilterWarning(sSourceFile, sKey, sMsgId))
return;
// check for directory names in file name
i = sSourceFile.rfind("/");
if (i > 0)
curFileName = sSourceFile.substr(i+1);
else
curFileName = sSourceFile;
// Find all matching file names (old system does not have directory.
// build list of potential entries
iSize = mcDb.mcFileList.size();
for (curFileIndex = 1; curFileIndex < iSize; ++curFileIndex)
if (curFileName == mcDb.mcFileList[curFileIndex].msPureName)
{
int j = mcDb.mcFileList[curFileIndex].miStart;
int iEnd = mcDb.mcFileList[curFileIndex].miEnd;
for (; j <= iEnd; ++j)
ivEntryList.push_back(j);
}
// Did we find one or more files ?
iSize = ivEntryList.size();
if (!iSize)
{
showWarning("source file(" + curFileName + ") not in template file", iLineNo);
return;
}
// Loop through all potential en-US entries
for (curENUSindex = -1, i = 0; i < iSize; ++i)
{
l10nMem_enus_entry& curE = mcDb.mcENUSlist[ivEntryList[i]];
// The entry must be unconverted if strict mode (comparing .pot files)
if (mcDb.mbStrictMode && curE.meState != l10nMem::ENTRY_DELETED)
continue;
// msgId must match
if (sMsgId == curE.msMsgId)
{
curENUSindex = ivEntryList[i];
if (curE.meState == l10nMem::ENTRY_DELETED)
curE.meState = l10nMem::ENTRY_NORMAL;
break;
}
}
// do we need to do advanced find
if (curENUSindex == -1 || mcDb.mbStrictMode)
{
// make copy of key in upper case
curKeyUpper = sKey;
l10nMem_db::keyToUpper(curKeyUpper);
// Loop through all potential en-US entries
for (i = 0; i < iSize; ++i)
{
l10nMem_enus_entry& curE = mcDb.mcENUSlist[ivEntryList[i]];
// compare keys, but be aware of different length
if (curKeyUpper.find(curE.msKey) != std::string::npos)
{
curENUSindex = ivEntryList[i];
bIsFuzzy = true;
break;
}
}
}
if (curENUSindex == -1)
{
showWarning("file(" + curFileName + ") key(" + sKey + ") msgId(" + sMsgId + ") not found in templates", iLineNo);
return;
}
// update language text
l10nMem_enus_entry& curE = mcDb.mcENUSlist[curENUSindex];
l10nMem_lang_entry& curL = curE.mcLangText[mcDb.miCurLangInx];
if (sMsgStr != curL.msMsgStr)
{
curL.msMsgStr = sMsgStr;
curL.mbFuzzy = bIsFuzzy;
curE.meState = l10nMem::ENTRY_CHANGED;
mcDb.mcLangList[mcDb.miCurLangInx].mbChanged = true;
}
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::convertToInetString(std::string& sText)
{
static const char *replacingStr[] = {"&", "\'", ">", "<", "\"", nullptr };
static const int replacingLen[] = {1, 1, 1, 1, 1, 0 };
static const char *newStr[] = {"&", "'", ">", "<", """, nullptr };
static const int newLen[] = {5, 6, 4, 4, 6, 0 };
int i, pos;
for (i = 0; replacingStr[i]; i++)
{
pos = 0;
while((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) {
sText.replace(pos, replacingLen[i], newStr[i]);
pos += newLen[i];
}
}
}
/********************** I M P L E M E N T A T I O N **********************/
void l10nMem_impl::convertFromInetString(std::string& sText)
{
static const char *replacingStr[] = {"&", "'", ">", "<", """, nullptr };
static const int replacingLen[] = {5, 6, 4, 4, 6, 0 };
static const char *newStr[] = {"&", "\'", ">", "<", "\"", nullptr };
static const int newLen[] = {1, 1, 1, 1, 1, 0 };
int i, pos;
for (i = 0; replacingStr[i]; i++)
{
pos = 0;
while((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) {
sText.replace(pos, replacingLen[i], newStr[i]);
pos += newLen[i];
}
}
}
|