project QadFinancials > 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)

/*************************************************************************** */
/* Structure : Read the resx file (Standard and custom) into tResourceFile   */
/*             Merge the tResourceFile to the database                       */
/*************************************************************************** */
/* Note the ANCESTOR code is skipped                                         */
/*************************************************************************** */

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-59 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  'qadfin-836391':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
    assign oiReturnStatus = -3.
    return.
end.


/* Read the Data into tfcTranslationCopy */
empty temp-table tResourceFile.

/* ============================================================================= */
/* First: Load the Standard Translations of the project                          */
/* ============================================================================= */
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-57 run SetMessage
       (input  vcMessage (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'S':U (icType), 
        input  2 (iiSeverity), 
        input  '' (icRowid), 
        input  'qadfin-474038':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: Load the Customized Translations of the project (if any)              */
/* ============================================================================= */
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-53 run SetMessage
           (input  vcMessage (icMessage), 
            input  '' (icArguments), 
            input  '' (icFieldName), 
            input  '' (icFieldValue), 
            input  'S':U (icType), 
            input  2 (iiSeverity), 
            input  '' (icRowid), 
            input  'qadfin-622072':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-73 run SetMessage
       (input  #T-58'Translations cannot be longer than 255 characters. Some translations were truncated.':255(992346791)T-58# (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'W' (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'qadfin-40402':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  'language code = ' + icLanguage + chr(10) + 'resource file = ' + icSourceFile (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>
end.

/* Merge the tResourceFile to the db now */
<M-17 run DataSaveTranslationsDIRECT
   (output viDummy (oiTranslationsRead#), 
    output viDummy (oiTranslationsCreated#), 
    output viDummy (oiTranslationsUpdated#), 
    output viDummy (oiTranslationsDeleted#), 
    output olUpdatesDone (olUpdatesDone), 
    output viFcReturnSuper (oiReturnStatus)) in BFcTranslation>

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-7 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.