Extract Translatable Strings Method Example

The following method example extracts translatable strings.

extractTStrings();
constants
    SchemaName       : String = "TestTstrings";
    LocaleName       : String = "5129";
    ExtractDirectory : String = "C:\Temp";
vars
    scm      : Schema;
    loc      : Locale;
    tstr     : TranslatableString;
    fylename : String;
    fyle     : File;
    count    : Integer;
    now      : TimeStamp;
    delim    : String;
    tsList   : ConstantNDict;
    const    : Constant;
    src      : String;
    chr      : Character;
begin
    scm := rootSchema.getSchema(SchemaName);
    if scm = null then
        write "**Unknown schema =>" & SchemaName;
        return;
    endif;
    loc := scm.getLocaleLocal(LocaleName);
    if loc = null then
        write "**Unknown locale =>" & scm.name & "::" & LocaleName;
        return;
    endif;
    if loc.isClone() then
        write "**Locale is a clone of =>" & scm.name & "::" & loc.name;
        return;
    endif;
    fylename := ExtractDirectory & "/" & scm.name & "-" & loc.name & ".txt";
    create fyle transient;
    fyle.kind := File.Kind_ANSI;
    fyle.mode := File.Mode_Output;
    fyle.fileName := fylename;
    if not fyle.tryOpen() then
        write "**Could not open file =>" & fylename;
        return;
    endif;
    fyle.writeLine("---Schema=" & scm.name);
    fyle.writeLine("---Locale=" & loc.name & "=" & loc.makeLocaleName());
    fyle.writeLine("---Extracted=" & now.display());
    delim := "-".makeString(60) & CrLf;
    fyle.writeString(delim);
    count := 0;
    foreach const in loc.getTranslatableStrings() do
        count := count + 1;
        tstr := const.TranslatableString;
        src := tstr.getSource().trimBlanks();
        // remove all trailing whitespace
        while src.length() > 0 do
            chr := src[src.length()];
            if chr = " " or chr = Lf or chr = Cr or chr = Tab then
                src := src[1:src.length()-1];
            else
                break;
            endif;
        endwhile;
        fyle.writeString(src & CrLf & delim);
    endforeach;
    write "Extracted " & count.String & " to " & fylename;
epilog
    delete fyle;
end;