multiterm api count number of language terms

I am trying to access the Termbase statistics with the MultiTerm Api.

I am able to retrieve the Total number of entries:

Termbase.Entries.Count.ToString();

But how do I retrieve the breakdown for each language, like this:

Termbase.Statistics.Language.Breakdown

Thanks in advance

Parents
  • Hi ,

    I did an investigation on the Multiterm public API and you can get the number of entries for each language using one of the the following methods:

    Method 1. Get the language indexes from the current project and retrieve the NumberOfEntriesInIndex using the languageIndex:

       var projectsController = SdlTradosStudio.Application.GetController<ProjectsController>();
          var activeProject = projectsController?.CurrentProject;

          var termbaseConfiguration = activeProject?.GetTermbaseConfiguration();

          var languageIndexes = termbaseConfiguration.LanguageIndexes;

    After you get the list of Language Indexes, you should retreive the corresponding Language Index for the curent language, like in the below print screen:

    Screenshot of Trados Studio code editor showing a method called GetTermbaseIndex with conditional logic to retrieve language index from termbase indexes.

    In the final step, you can use the languageIndex to get the number of entries from the termbase, using the below code:

    var numberOfLanguageEntries  = termbase.Information.NumberOfEntriesInIndex["languageIndex"];

    Note: On the Community Wiki area, we have a documentation which explains how to add a new entry, what is language index and how to get it using Multiterm SDK, the wiki page can be accessed using this link. (I've updated the Wiki page with this new information which shows how to get the number of entries for each language using the public API)

    Method 2. Parsing the Termbase Definition XML and get the needed information (this method is a bit complex, because requiers to create your own implementation to get the nodes information). The Definition can be accessed using the following code:

    var entries = termbase.Entries;
    var definition = termbase.Definition;
    var def = definition._Definition;

    The _Definition property keeps the entire termbase definition, including the languages and entries, so you can use it to extract the needed information.

    You can use the https://codebeautify.org/xmlviewer tool to check how  the xml result looks like.

    With kind regards,

    Florentina Caputa



    Generated Image Alt-Text
    [edited by: Trados AI at 1:23 PM (GMT 0) on 5 Mar 2024]
  • Hi

    Thanks for the reply, however neither of the methods will give me the required data.

    Your first method uses the SdlTradosStudio/Project Api and in my case I am accessing standalone termbases (not attached to projects).

    The second method uses the Termbase Definition XML data which I already have access to. However a termbase definition can have more languages defined than actually in use. For example, I can define "de", "en" and "fr", which would all appear in the definition file; but only the "de" and "en" languages could have entries and terms. This is the data I am looking for.

    How does the desktop application access the term count for each language without looping through each entry?

    Kind regards

    Samuel  

  • Hi ,

    I will look on how you can get the number of entries on a standalone application and I will come back to you with an answer.

    Kind regards,

    Florentina

Reply Children
No Data