Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions apiconcepts/terminology/creating_a_file_based_termbase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Creating a File-based Termbase

This article shows how to create a file-based termbase (`.ttb`) programmatically.

## Create the Class

Create a class named `FileBasedTermbaseCreator`.

Add a public asynchronous method named `CreateFileBasedTermbaseAsync()`.

This method accepts the following string parameters:

* `folderPath` - folder where the termbase file will be created
* `fileName` - name of the termbase file

Call the method as follows:

```csharp
var creator = new FileBasedTermbaseCreator();
await creator.CreateFileBasedTermbaseAsync(@"C:\MyTermbases", "MyTermbase.ttb");
```

## Create the File-based Termbase

Create a [CreateTermbaseRequest](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.CreateTermbaseRequest.yml) object and pass it to the `CreateTermbaseAsync()` method of the [TerminologyProviderManager](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.TerminologyProviderManager.yml) class.

`CreateTermbaseRequest` includes the following properties:

* **Name** - termbase name
* **Description** - termbase description
* **Path** - folder where the termbase file will be created
* **Languages** - list of languages to include in the termbase

Each language uses a [DefinitionLanguage](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.DefinitionLanguage.yml) object with these properties:

* **Locale** - locale code of the language, for example `en` or `de`
* **Name** - display name of the language
* **IsBidirectional** - indicates whether the language is bidirectional
* **TargetOnly** - indicates whether the language is target-only

`CreateTermbaseAsync()` returns an [OperationResult](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.OperationResult.yml) object. Check `IsSuccess` to confirm that the operation succeeded. If the operation fails, inspect `Error` for details.

The following example creates a file-based termbase with English and German:

```csharp
public async Task CreateFileBasedTermbaseAsync(string folderPath, string fileName)
{
var request = new CreateTermbaseRequest
{
Name = fileName,
Description = "My termbase description",
Path = folderPath,
Languages = new List<DefinitionLanguage>
{
new DefinitionLanguage
{
Locale = "en",
Name = "English",
IsBidirectional = true,
TargetOnly = false
},
new DefinitionLanguage
{
Locale = "de",
Name = "German",
IsBidirectional = true,
TargetOnly = false
}
}
};

OperationResult result = await TerminologyProviderManager.Instance.CreateTermbaseAsync(request);

if (!result.IsSuccess)
{
// Handle result.Error.
}
}
```

## See Also

* [Managing Terms in a File-based Termbase](managing_terms_in_a_file_based_termbase.md)
14 changes: 14 additions & 0 deletions apiconcepts/terminology/file_based_termbase_introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Introduction to File-based Termbases

This article explains how to work with file-based termbases in Var:ProductName. It points you to the main tasks: create a termbase, manage terms and display entry content.

## File-based Termbases

A file-based termbase uses the `.ttb` file extension. It supports single-user access and can store terms in multiple languages.

Use the [IStudioTermbase](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Termbase.IStudioTermbase.yml) interface to manage entries in a file-based termbase.

## See Also

* [Creating a File-based Termbase](creating_a_file_based_termbase.md)
* [Managing Terms in a File-based Termbase](managing_terms_in_a_file_based_termbase.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
186 changes: 186 additions & 0 deletions apiconcepts/terminology/managing_terms_in_a_file_based_termbase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Managing Terms in a File-based Termbase

This article shows how to manage content in a file-based termbase.

## Retrieve a file-based termbase instance

The [IStudioTermbase](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Termbase.IStudioTermbase.yml) interface exposes the methods that manage entries in a file-based termbase.

To get an `IStudioTermbase` instance, first retrieve an [ITerminologyProvider](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.ITerminologyProvider.yml) by calling the [TerminologyProviderManager](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.TerminologyProviderManager.yml) `GetTerminologyProvider()` method and passing the termbase URI. The URI must use the `ttb.file` scheme, for example `ttb.file:///C:/MyTermbases/MyTermbase.ttb`.

After you retrieve the provider, initialize it and cast it to `IStudioTermbase`.

```csharp
ITerminologyProvider terminologyProvider = TerminologyProviderManager.Instance.
GetTerminologyProvider(new Uri("ttb.file:///C:/MyTermbases/MyTermbase.ttb"));
if (!terminologyProvider.Initialize())
{
// handle case
return;
}

var termbase = terminologyProvider as IStudioTermbase;
```

## Understand entries

A termbase entry contains one or more terms in one or more languages together with metadata such as fields and transactions. Each term belongs to a specific language.

An [Entry](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Entry.yml) object contains these properties:

- **Id**: The unique identifier of the entry. This property is optional when you add a new entry because the termbase generates the ID. You must set it when you update an existing entry.
- **Fields**: A list of [EntryField](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.EntryField.yml) objects that define the entry fields.
- **Languages**: A list of [EntryLanguage](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.EntryLanguage.yml) objects that define the entry languages.
- **Transactions**: A list of [EntryTransaction](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.EntryTransaction.yml) objects that record the entry transactions.

<img style="display:block;" src="images/Cd-Entry Dependencies.png" alt="Entry dependencies"/>

## Add an entry

After you get the termbase instance, call the `AddEntry()` method to add a new term entry. The method takes an [Entry](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Entry.yml) object and returns the ID of the new entry.

The language locales must match the termbase definition. In this example, the termbase uses English (`en`) and German (`de`), so the entry uses those locales.

This example creates an [Entry](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Entry.yml) with one field, the English term "Photo printer", the German equivalent "Fotodrucker", and an origination transaction. It then adds the entry to the file-based termbase.

```csharp
var entry = new Entry
{
Fields = new List<EntryField>
{
new EntryField { Name = "domain", Value = "general" }
},
Languages = new List<EntryLanguage>
{
new EntryLanguage
{
Locale = "en",
Name = "English",
Terms = new List<EntryTerm> { new EntryTerm { Value = "Photo printer" } }
},
new EntryLanguage
{
Locale = "de",
Name = "German",
Terms = new List<EntryTerm> { new EntryTerm { Value = "Fotodrucker" } }
}
},
Transactions = new List<EntryTransaction>
{
new EntryTransaction
{
Date = DateTime.Now,
Type = TransactionType.Origination,
Name = "Creating Entry"
}
}
};

int entryId = termbase.AddEntry(entry);
```

## Update an entry

To update an existing term entry, call the `UpdateEntry()` method and pass an [Entry](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Entry.yml) object.

Set the `Id` property to the ID of the entry that you want to update.

This example updates the entry created earlier. It uses the existing `Id`, replaces the language content, and adds a modification transaction. The updated entry contains the same German term as the previous example and two English terms, "Photo printer" and "Photo-printer", with different "Status" field values.

```csharp
var entryToUpdate = new Entry
{
Id = entryId,
Languages = new List<EntryLanguage>
{
new EntryLanguage
{
Locale = "en",
Name = "English",
Terms = new List<EntryTerm>
{
new EntryTerm
{
Value = "Photo printer",
Fields = new List<EntryField>
{
new EntryField { Name = "Status", Value = "Preferred" }
}
},
new EntryTerm
{
Value = "Photo-printer",
Fields = new List<EntryField>
{
new EntryField { Name = "Status", Value = "Forbidden" }
}
}
}
},
new EntryLanguage
{
Locale = "de",
Name = "German",
Terms = new List<EntryTerm> { new EntryTerm { Value = "Fotodrucker" } }
}
},
Transactions = new List<EntryTransaction>
{
new EntryTransaction
{
Date = DateTime.Now,
Type = TransactionType.Modification,
Name = "Modifying Entry"
}
}
};

termbase.UpdateEntry(entryToUpdate);
```

## Retrieve all entry IDs

Call the `GetEntriesIDs()` method to retrieve the IDs of all entries in a file-based termbase. The method returns a list of integers, where each integer identifies an entry.

This example retrieves all entry IDs and checks whether the termbase returned any values before it processes them.

```csharp
int[] entryIds = termbase.GetEntriesIDs();

if (entryIds == null || entryIds.Length == 0)
{
// no entries
}
else
{
// process entry IDs
}
```

## Retrieve a fixed number of entries

Call the `GetEntries()` method to retrieve a fixed number of entries from a file-based termbase. The method returns a list of [Entry](../../api/terminology/Sdl.Terminology.TerminologyProvider.Core.Entry.yml) objects.

This example retrieves entries in batches of 25. It starts at the first entry, continues until it reaches a limit of 100 entries, and stops early when no more entries are available.

```csharp
int start = 0;
int end = 100;
int batchSize = 25;

for (int offset = start; offset < end; offset += batchSize)
{
var entries = termbase.GetEntries(offset, batchSize);

if (entries == null || entries.Count == 0)
{
break;
}

// process entries
}
```

## See also

* [Creating a File-based Termbase](creating_a_file_based_termbase.md)
9 changes: 9 additions & 0 deletions apiconcepts/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,15 @@
href: terminology/displaying_entry_content.md
- name: Adding Terms
href: terminology/adding_terms.md
- name: Working with File-based Termbases
href: terminology/file_based_termbase_introduction.md
items:
- name: Introduction
href: terminology/file_based_termbase_introduction.md
- name: Creating a File-based Termbase
href: terminology/creating_a_file_based_termbase.md
- name: Managing Terms in a File-based Termbase
href: terminology/managing_terms_in_a_file_based_termbase.md
- name: API Reference
href: ../api/terminology/toc.yml
- name: Release Notes
Expand Down
Loading