Consultor Eletrônico



Kbase P13082: When I translate a word from English to French sometimes it
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   3/11/2003
Status: Unverified

FACT(s) (Environment):

Translation Manager 2.0

SYMPTOM(s):

TranMan does not translate some words from English to French sometimes.

FIX:

The tmstrinst.p procedure code reports duplicate strings in a project. Along with duplicate strings, the compiled and translated code might display original (non-translated) strings for some instances. This procedure repairs this problem and deletes the redundant strings.

To run the code, back up your project database and connect the project database <tmproject> with logical name 'xlatedb' and run the tmstrinst.p procedure from the procedure editor.

/* tmstrinst.p: */
/* ============ */
/* buffers to search for string, instances and translations */
DEFINE BUFFER bXlString FOR xl_string_info.
DEFINE BUFFER bXlInst FOR xl_instance.

DEFINE VARIABLE lDsp AS LOGICAL NO-UNDO.

DEFINE VARIABLE NextString AS INTEGER NO-UNDO.
DEFINE VARIABLE NextInstance AS INTEGER NO-UNDO.
DEFINE VARIABLE NextStr AS INTEGER NO-UNDO.
DEFINE VARIABLE NextInst AS INTEGER NO-UNDO.

DEFINE VARIABLE AssignString AS INTEGER NO-UNDO.
DEFINE VARIABLE iLngth AS INTEGER NO-UNDO.
DEFINE VARIABLE iinstnum AS INTEGER NO-UNDO.

/* get the correct next instance and next sequence numbers */
FIND FIRST XL_Project NO-LOCK NO-ERROR.
IF NUM-ENTRIES(XL_Project.DisplayType,CHR(4)) > 1 THEN
DO:
ASSIGN
NextString = INTEGER(ENTRY(2, XL_Project.DisplayType, CHR(4)))
NextInstance = INTEGER(ENTRY(3, XL_Project.DisplayType, CHR(4)))
NextString = IF NextString = ? THEN 1 ELSE NextString
NextInstance = IF NextINstance = ? THEN 1 ELSE NextInstance.
END.
DO:
FIND LAST XL_String_Info USE-INDEX Sequence_Num NO-LOCK NO-ERROR.
FIND LAST XL_Instance USE-INDEX Instance_Num NO-LOCK NO-ERROR.
ASSIGN
NextInst = IF AVAILABLE XL_Instance
THEN XL_Instance.Instance_Num + 1
ELSE 1
NextStr = IF AVAILABLE XL_String_Info
THEN XL_String_Info.Sequence_Num + 1
ELSE 1.
END.
ASSIGN NextString = MAX(NextString, NextStr)
NextInstance = MAX(NextInstance, NextInst).

/* produce a report */
OUTPUT TO report.txt.

/* go through all the xl_string_info entries */
FOR EACH xl_string_info NO-LOCK USE-INDEX sequence_num:
ASSIGN lDsp = YES
AssignString = xl_string_info.sequence_num.

/* Search for duplicate xl_string_info records;
they are duplicate if original and key strings of two
xl_string_info
records are equal */
loop:
FOR EACH bXlString
WHERE bXlString.keyOfString BEGINS xl_string_info.keyOfString
AND bXlString.Original_string = xl_string_info.Original_string
AND bXlString.sequence_num > xl_string_info.sequence_num:

/* we have a duplicate - but we must compare extended characters
as "a" = "ä"; in V9+ we can use COMPARE(),
but this works for all versions */
DO iLngth = 1 TO LENGTH (RIGHT-TRIM(xl_string_info.keyofstring)):
IF ASC(SUBSTRING(xl_string_info.keyofstring, iLngth, 1)) <>
ASC(SUBSTRING(bxlstring.keyofstring, iLngth, 1))
THEN LEAVE.
END.
IF iLngth > LENGTH (RIGHT-TRIM(xl_string_info.keyofstring))
THEN DO:

/* display the original string, it's instances & translations */
IF lDsp THEN DO:
ASSIGN lDsp = NO.
PUT
"STRING: Seq#:" SPACE
xl_string_info.sequence_num FORMAT '>>>>>9' SPACE
"Length:" SPACE
LENGTH (xl_String_info.keyOfString) FORMAT '>>>9' SPACE
xl_string_info.KeyOfString AT 9 SKIP
"INSTANCES:" TO 13 SKIP.

FOR EACH xl_instance OF xl_string_info:
PUT
"Seq#:" TO 13 SPACE
xl_instance.sequence_num FORMAT '>>>>>9' SPACE
"Length:" SPAC.E
XL_Instance.MaxLength FORMAT '>>>9' SPACE
"Inst#:" SPACE
xl_instance.instance_num FORMAT '>>>>>9' SPACE
"Just:" SPACE
xl_instance.Justification FORMAT '9' SPACE
"#Occ:" SPACE
xl_instance.Num_Occurs FORMAT '>>9' SPACE
xl_instance.proc_name SKIP.


FOR EACH xl_translation WHERE
xl_translation.sequence_num = xl_instance.sequence_num AND
xl_translation.instance_num = xl_instance.instance_num:
PUT xl_translation.trans_string AT 9 SKIP.
END. /* FOR EACH xl_translation */
END. /* FOR EACH xl_instance */
END. /* IF lDsp THEN ... */

/* display the duplicate string, it's instances, translations */
PUT
"DUPL. STR:" TO 13 SPACE
bXlstring.sequence_num FORMAT '>>>>>9' SPACE
"Length:" SPACE
LENGTH (bXlstring.keyOfString) FORMAT ">>>9" SPACE
bXlstring.keyOfString AT 9.

FOR EACH xl_instance OF bXlstring:
PUT
"Seq#:" TO 13 SPACE
xl_instance.sequence_num FORMAT '>>>>>9' SPACE
"Length:" SPACE
XL_Instance.MaxLength FORMAT '>>>9' SPACE
"Inst#:" SPACE
xl_instance.instance_num FORMAT '>>>>>9' SPACE
"Just:" SPACE
xl_instance.Justification FORMAT '9' SPACE
"#Occ:" SPACE
xl_instance.Num_Occurs FORMAT '>>9' SPACE
xl_instance.proc_name SKIP.

/* can we find an existing instance of the new parent? */
FIND FIRST bxlInst WHERE
bxlinst.sequence_num = xl_string_info.sequence_num AND
bxlinst.Justification = xl_instance.Justification AND
bxlinst.MaxLength = xl_instance.MaxLength AND
bxlinst.proc_name = xl_instance.proc_name
EXCLUSIVE-LOCK NO-ERROR.
IF AVAILABLE bXlinst THEN iinstnum = bXlInst.instance_num.
ELSE iinstnum = ?. /* No, we cannot */

FOR EACH xl_translation WHERE
xl_translation.sequence_num = xl_instance.sequence_num AND
xl_translation.instance_num = xl_instance.instance_num:
PUT xl_translation.trans_string AT 9 SKIP.

/* we have to change the translation */
IF iinstnum = ? THEN
ASSIGN xl_translation.sequence_num =
xl_string_info.sequence_num
xl_translation.instance_num = NextInstance
/* should find a translation of the original instance and
assign this one if it did not exist; the translation may
be lost here */.
ELSE DELETE xl_translation.

END. /* FOR EACH xl_translation */
/* we have to change seq_num and inst_num of the instance */
IF iinstnum = ? THEN
ASSIGN xl_instance.sequence_num =
xl_string_info.sequence_num
xl_instance.instance_num = NextInstance
nextInstance = NextInstance + 1.
ELSE DO:
ASSIGN bXlinst.Num_Occurs = bXlinst.num_occurs + 1.
DELETE xl_instance.
END.
END. /* FOR EACH xl_i.nstqance OF bXlString */
/* get rid of the duplicate - we need NO-ERROR here as the
record could be deleted by db trigger */
DELETE bXlString NO-ERROR.
PUT SKIP (1).
END. /* IF LENGTH ... */
END. /* FOR EACH bXlString */
END. /* FOR EACH xl_String_info */

/* update the counters of sequence and instance */
DO TRANSACTION:
FIND FIRST xl_project EXCLUSIVE-LOCK NO-ERROR.
IF AVAILABLE xl_project THEN
ASSIGN
XL_Project.DisplayType =
IF NUM-ENTRIES(XL_Project.DisplayType,CHR(4)) > 1 THEN
ENTRY(1,XL_Project.DisplayType,CHR(4))
+ CHR(4) + TRIM(STRING(NextString))
+ CHR(4) + TRIM(STRING(NextInstance))
ELSE
XL_Project.DisplayType
+ CHR(4) + TRIM(STRING(NextString))
+ CHR(4) + TRIM(STRING(NextInstance)).

END.
OUTPUT CLOSE.
/* tmstrinst.p - end */.