IResourceImporter.Import

Syntax

Import;

Description

The Import method imports resources.

Comments

On importing resources the user should take into account that during the export two symbols "New line" are used as a separator of resource string elements, one symbol "New line" is used to separate strings of the multistring resource element (for example, the strings of the ListBox component).

Example

Executing the example requires that the repository contains resources with the RESOURCES identifier. There also should be a file, into which the C:\Res.txt resources were exported.

Sub ImportResource;
Var
    MB: IMetabase;
    ResObj: IResourceObject;
    Provider: DtTextProvider;
    ImpObj: IResourceImporter;
    Countries: Array[0..1Of String;
    Log: IResourceImporterLog;
    i: Integer;
    s: String;
Begin
    MB := MetabaseClass.Active;
    ResObj := MB.ItemById("RESOURCES").Edit As IResourceObject;
    Provider := New DtTextProvider.Create;
    Provider.File := "C:\Res.txt";
    Provider.RangeHasHeader := True;
    ImpObj := New ResourceImporter.Create;
    ImpObj.Provider := Provider;
    Countries[0] := "ru";
    Countries[1] := "en";
    ImpObj.Locales := Countries;
    ImpObj.Resource := ResObj;
    ImpObj.Method := ResourceImportType.UpdateAndAdd;
    ImpObj.Import;
    Log := ImpObj.Log;
    Debug.WriteLine("Total " + Log.Count.ToString + " records");
    For i := 0 To Log.Count - 1 Do
        Select Case log.State(i).ToString
            Case "0": s := " - record is added";
            Case "1": s := " - record is updated";
            Case "2": s := " - record is skipped";
        End Select;
        Debug.WriteLine(Log.Item(i) + s);
    End For;
End Sub ImportResource;

After executing the example resources are imported from the C:\Res.txt file. The elements missing in the current resources are imported, and existing elements values are updated. Information about import process is displayed in the console window.

See also:

IResourceImporter