Class MessageTranslator

java.lang.Object
io.github.jbastgen.stemma.app.ai.MessageTranslator

public final class MessageTranslator extends Object
Translation of commit messages with the AI (feature 7): the prompt, and reading the answer back into one text per commit.
  • Field Details

    • TEMPLATE_NAME

      public static final String TEMPLATE_NAME
      See Also:
    • LANGUAGES

      public static final Map<String,String> LANGUAGES
      Languages Stemma knows, with the English name used in the prompt; any other name can be typed.
    • UNCHANGED

      public static final String UNCHANGED
      What the AI writes instead of a translation for a message that is in one of the languages that are not translated.
      See Also:
  • Method Details

    • numbered

      public static String numbered(List<MessageTranslator.Message> messages)
      The messages, each under a line ### n, so that the answer can be split again.
    • englishName

      public static String englishName(String code)
      The English name of the language of the interface (a code of i18n/languages.tsv), as the prompt names languages.
    • defaultSkipLanguages

      public static String defaultSkipLanguages(String languageSetting)
      The languages that are not translated until the user chooses: English and the language of the interface (for the setting language, which may be empty or system for the language of the system).
    • skipLanguages

      public static List<String> skipLanguages(String setting)
      The languages of the setting (names separated by commas, semicolons or line breaks), without blanks and duplicates.
    • buildPrompt

      public static String buildPrompt(String template, String language, List<MessageTranslator.Message> messages)
      Fills the template: {language} and {messages}. Only the messages are sent, nothing of the changes.
    • buildPrompt

      public static String buildPrompt(String template, String language, List<String> skip, List<MessageTranslator.Message> messages)
      As above, and {skip} is the list of languages whose messages are left alone. A template of the user without {skip} gets the instruction appended, so the setting works with it as well.
    • parse

      public static List<String> parse(String answer, int count)
      Splits the answer into one text per message. An answer without the ### lines is taken as the translation of a single message; if there are several messages and the marks are missing, nothing can be told apart and the result is empty.