Load Translatable Strings Method Example

The following method example reloads extracted translatable strings.

loadTStrings();
constants
    ExtractDirectory : String = "C:\Temp";
vars
    line        : String;
    token       : String;
    scm         : Schema;
    loc         : Locale;
    tstr        : TranslatableString;
    fylename    : String;
    fyle        : File;
    count       : Integer;
    offset      : Integer;
    linenum     : Integer;
    src         : String;
    errorCode   : Integer;
    errorOffset : Integer;
    errorLength : Integer;
    result      : Boolean;
begin
    write "";
    fylename := ExtractDirectory & "/" & "TestTstrings-5129.txt";
    create fyle transient;
    fyle.kind := File.Kind_ANSI;
    fyle.mode := File.Mode_Input;
    fyle.fileName := fylename;
    if not fyle.tryOpen() then
        write "**Could not open file =>" & fylename;
        return;
    endif;
    // First line is gives schema name
    line := fyle.readLine();
    linenum := 1;
    if line.length() < 11 or line[1:10] <> "---Schema=" then
        write "**Invalid file format =>" & fylename;
        return;
    endif;
    token := line[11:end];
    scm := rootSchema.getSchema(token);
    if scm = null then
        write "**Unknown schema =>" & token;
        return;
    endif;
    // Second line gives locale name
    line := fyle.readLine();
    linenum := linenum + 1;
    if line.length() < 11 or line[1:10] <> "---Locale=" then
        write "**Invalid file format =>" & fylename;
        return;
    endif;
    offset := 11;
    token := line.scanUntil("=",offset);
    loc := scm.getLocaleLocal(token);
    if loc = null then
        write "**Unknown locale =>" & scm.name & "::" & token;
        return;
    endif;
    if loc.isClone() then
        write "**Locale is a clone =>" & scm.name & "::" & loc.name;
        return;
    endif;
    //discard remaining header lines
    line := fyle.readLine();
    linenum := linenum + 1;
    while line.length() < 8 or line[1:8] <> "-".makeString(8) do
        if fyle.endOfFile() then
            write "**Unexpected end of file";
            return;
        endif;
        line := fyle.readLine();
        linenum := linenum + 1;
    endwhile;
    beginTransaction;
    while true do
        if fyle.endOfFile() then
            break;
        endif;
        src := "";
        line := fyle.readLine();
        linenum := linenum + 1;
        while line.length() < 8 or line[1:8] <> "-".makeString(8) do
            if src = "" then
                src := line;
            else
                src := src & CrLf & line;
            endif;
            if fyle.endOfFile() then
                write "**Unexpected end of file at line " & linenum.String;
                return;
            endif;
            line := fyle.readLine();
            linenum := linenum + 1;
        endwhile;
        src := src.trimBlanks();
        if src = "" then
            write "**Empty definition before line " & linenum.String;
            return;
        endif;
        // Get TString name
        offset := 1;
        token := src.scanWhile(
           "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_",
           offset);
        if token = "" or token.length > 30 or token[1] < "A" or token[1] > 
           "Z" then
           write "**Invalid TString name before line " & linenum.String &
                 " =>" & src;
            return;
        endif;
        tstr := loc.getTranslatableStringLocal(token);
        if tstr = null then
            write "**Unknown TString name before line " & linenum.String &                 " =>" & src;
            return;
        endif;
        result := tstr.updateCompile( src, errorCode, errorOffset,
               errorLength);
        if result then
            write "**Error in TString before line " & linenum.String &
                " =>" & src;
            write "**Error " & errorCode.String & "=" & 
                process.getErrorText(errorCode) & "; offset=" & 
                errorOffset.String;
            return;
        endif;
        count := count + 1;
    endwhile;
    commitTransaction;
    write "Loaded " & count.String & " from " & fylename;
epilog
    if process.isInTransactionState() then
        write "**aborting transaction";
        abortTransaction;
    endif;
    delete fyle;
end;