project BLF > class BFcTranslation > method LoadResourceFile

Description

Read a resource file containing translations.


Parameters


icSourceFileinputcharacterName of the resource file (with full path)
icLanguageinputcharacterThe language code
olUpdatesDoneoutputlogicalParameter indicating whether the load of the resource file changed anything in the internal translated strings.
The value will be false if the internal translated strings are the same as the ones that are in the resource file.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BFcTranslation.ApiLoadBusinessTranslations
method BFcTranslation.APISynchronise
method BFcTranslation.LoadResourceFile

QadFinancials
method BFcTranslation.LoadResourceFile


program code (program9/bfctranslation.p)

assign olUpdatesDone = false
       vhTargetProcedure = {&TARGETPROCEDURE}
       icSourceFile = lc(icSourceFile)
       vcSourceFile = search(icSourceFile)
       vcLanguageToLoad = icLanguage.

/* First check the existence of the file to load */
if vcSourceFile = ?
then do :
    <M-6 run SetMessage
       (input  'Could not load the resource file ($1).':U (icMessage), 
        input  icSourceFile (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  1 (iiSeverity), 
        input  '' (icRowid), 
        input  'BLF-104':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
    assign oiReturnStatus = -3.
    return.
end.

vcFreeform = "for each fcTranslation where ":U
           + "fcTranslation.TranslationProjShortCode = '":U + vcProjectCode
           + "' and fcTranslation.TranslationLanguageCode = '":U + icLanguage + "'":U.

<M-8 run DataLoad (input  '' (icRowids), 
                   input  '' (icPkeys), 
                   input  '' (icObjectIds), 
                   input  vcFreeform (icFreeform), 
                   input  no (ilKeepPrevious), 
                   output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
if viFcReturnSuper = -4
then viFcReturnSuper = 0.
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* Copy data into an indexed temp-table to allow performant retrieval */
empty temp-table tfcTranslationCopy.
for each tfcTranslation on error undo, throw:
    create tfcTranslationCopy.
    assign tfcTranslationCopy.tcTranslationLanguageCode  = tfcTranslation.TranslationLanguageCode
           tfcTranslationCopy.tcTranslationProjShortCode = tfcTranslation.TranslationProjShortCode
           tfcTranslationCopy.tiTranslationStringNumber  = tfcTranslation.TranslationStringNumber
           tfcTranslationCopy.tcTranslationStringText    = tfcTranslation.TranslationStringText
           tfcTranslationCopy.tcBusinessClass            = tfcTranslation.BusinessClass
           tfcTranslationCopy.tcClassTempTableRowId      = tfcTranslation.tc_Rowid.
end.

viParseReturnStatus = 0.
vlTruncated = false.
CREATE SAX-READER vhSaxParser in widget-pool "non-persistent".
vhSaxParser:VALIDATION-ENABLED = FALSE.
vhSaxParser:HANDLER = THIS-PROCEDURE.
vhSaxParser:SET-INPUT-SOURCE( "FILE":U, vcSourceFile ).
vhSaxParser:SAX-PARSE no-error.
if error-status:error
then do :
    assign vcMessage = "Error in SAX parser.":U + chr(10) +
                       error-status:get-message(1) + chr(10) +
                       error-status:get-message(2) + chr(10) +
                       error-status:get-message(3)
           oiReturnStatus = -3.
    <M-5 run SetMessage (input  vcMessage (icMessage), 
                     input  '' (icArguments), 
                     input  '' (icFieldName), 
                     input  '' (icFieldValue), 
                     input  'S':U (icType), 
                     input  2 (iiSeverity), 
                     input  '' (icRowid), 
                     input  'BLF-103':U (icFcMsgNumber), 
                     input  '' (icFcExplanation), 
                     input  '' (icFcIdentification), 
                     input  '' (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
    DELETE OBJECT vhSaxParser.
    return.
end.
DELETE OBJECT vhSaxParser.
ASSIGN vhSaxParser = ?.
if viParseReturnStatus <> 0
then oiReturnStatus = viParseReturnStatus.
if viParseReturnStatus < 0
then return.

/* Second: check whether there are custom translations.  If so, try to load them */

assign vcSourceFile = icSourceFile
       entry(1,vcSourceFile,".":U) = entry(1,vcSourceFile,".":U) + "cust":U
       vcSourceFile = search(vcSourceFile).   
           
if vcSourceFile <> ?
then do :
    CREATE SAX-READER vhSaxParser in widget-pool "non-persistent".
    vhSaxParser:VALIDATION-ENABLED = FALSE.
    vhSaxParser:HANDLER = THIS-PROCEDURE.
    vhSaxParser:SET-INPUT-SOURCE( "FILE":U, vcSourceFile ).
    vhSaxParser:SAX-PARSE no-error.
    if error-status:error
    then do :
        assign vcMessage = "Error in SAX parser.":U + chr(10) +
                           error-status:get-message(1) + chr(10) +
                           error-status:get-message(2) + chr(10) +
                           error-status:get-message(3)
               oiReturnStatus = -3.
        <M-7 run SetMessage (input  vcMessage (icMessage), 
                         input  '' (icArguments), 
                         input  '' (icFieldName), 
                         input  '' (icFieldValue), 
                         input  'S':U (icType), 
                         input  2 (iiSeverity), 
                         input  '' (icRowid), 
                         input  'BLF-105':U (icFcMsgNumber), 
                         input  '' (icFcExplanation), 
                         input  '' (icFcIdentification), 
                         input  '' (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
        DELETE OBJECT vhSaxParser.
        return.
    end.
    DELETE OBJECT vhSaxParser.
    ASSIGN vhSaxParser = ?.
end.

if vlTruncated
then do:
    oiReturnStatus = 1.
    <M-9 run SetMessage
       (input  #T-24'Translations cannot be longer than 255 characters. Some translations were truncated.':255(846477648)T-24# (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'W' (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'blf-152998':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  'language code = ' + icLanguage + chr(10) + 'resource file = ' + icSourceFile (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
end.

/* Check the number of records in tFcTranslation. If there is one, the vlUpdatesDone flag needs to be set */
/* Make sure the update is done in batches of 1000, otherwise the server
   will stop with an error on the -L parameter */

do while can-find(first tfcTranslationCopy where
                        tfcTranslationCopy.tcStatus > ""):

    assign vlFcDataValidated = yes
           viCnt = 0.
    
    for each tfcTranslationCopy where
             tfcTranslationCopy.tcStatus > "":U on error undo, throw:

        find tfcTranslation where
             tfcTranslation.tc_Rowid = tfcTranslationCopy.tcClassTempTableRowId.
             
        assign tfcTranslation.TranslationStringText = tfcTranslationCopy.tcTranslationStringText
               tfcTranslation.BusinessClass         = tfcTranslationCopy.tcBusinessClass
               tfcTranslation.tc_Status             = tfcTranslationCopy.tcStatus.
               
        delete tfcTranslationCopy.

        assign viCnt = viCnt + 1.
        if viCnt > 1000 then leave.
    end.
        
    <M-3 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    assign olUpdatesDone = TRUE.
end.

assign vcProjectsLoaded = (if vcProjectsLoaded = "" then vcProjectCode                                                    
                                                    else vcProjectsLoaded + ",":U + vcProjectCode).

do viCnt = 1 to num-entries(vcProjectsToLoad):
    if lookup(ENTRY(viCnt,vcProjectsToLoad),vcProjectsLoaded) = 0
    then do:
        assign vcProjectCode = entry(viCnt,vcProjectsToLoad).
        <M-4 run LoadResourceFile (input  'xml/':U + entry(viCnt,vcProjectsToLoad) + '.':U + vclanguageToLoad + '.resx':U (icSourceFile), 
                           input  vcLanguageToLoad (icLanguage), 
                           output vlUpdatesDone (olUpdatesDone), 
                           output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
        if vlUpdatesDone
        then assign olUpdatesDone = true.
    END.
end.