Configuring HotFolder

HotFolder settings are stored in a JSON configuration file. The configuration file allows linking Smartcat projects to HotFolder projects created on the local drive and defines the operations that the application must perform.

Configuration file

The JSON root object must contain the following JSON objects:

  • serviceMode — service operation settings. Must contain the following properties:
    • syncInterval — interval between syncs (in seconds).
    • commands — optional JSON object with command execution settings for each service operation cycle. Must contain the following properties:
      • workingDirectory — working directory for executing commands.
      • preWorkCommands — commands to be executed before a service cycle starts.
      • postWorkCommands — commands to be executed after the service cycle ends.
    • projects — array of settings for specific directories. Each directory's settings are stored in a separate JSON object with the following properties:
      • connection — object with connection settings. Must contain the following properties:
        • url — connection string. Corresponds to the Smartcat home page (e.g., https://smartcat.ai, or https://us.smartcat.ai if you are using the U.S. server).
        • timeout — query timeout (in milliseconds). Optional; 100 seconds by default.
        • clientId — login that you received when enabling HotFolder in your account.
        • secretKey — password that you received when enabling HotFolder in your account.
      • projectId — Smartcat project id.
      • path — path to the local folder containing translated documents.
      • localStatePath — path to the folder where you want to store the local statuses of project files. Must be unique for each project.
      • fileProcessingTimeout — timeout for file parsing by Smartcat.
      • exportTimeout — timeout for exporting translations from Smartcat.
      • defaultTranslationSettings — default translation settings. Must contain the following properties:
        • uploadTranslationsForNewFiles — defines whether translations from found translation files (if any) should be uploaded to Smartcat.
        • confirmUploadedTranslations — defines whether the uploaded translations should be confirmed in Smartcat.
        • placeholdersRegex — a regular expression used to retrieve arbitrary placeholders from filenames. Placeholder names are taken from named groups used in the regex. If the regex is set, it must have only one match in the filename. The regex must NOT contain a named group titled TargetLanguage.
      • files — array of sync settings for files matching certain masks. Each object must contain the following properties:
        • searchPattern — file mask to check the file path (relative to the root directory). If a file matches the mask, it is sent for translation. The following wildcards are supported: “?” — any single character, “*” — any number of characters, and “**” — any subdirectories.
        • resultNaming — rules for naming the resulting translation file. You can use placeholders listed below.
        • uploadTranslationsForNewFiles — redefines the default uploadTranslationsForNewFiles setting. Optional.
        • confirmUploadedTranslations — redefines the default confirmUploadedTranslations setting. Optional.
        • placeholdersRegex — redefines the default placeholdersRegex setting. Optional.
      • exclude — array of masks, defined similarly to searchPattern, for files to be excluded from processing. Optional.
      • disassembleAlgorithms — optional array of JSON objects with names of parsing algorithms to be used for files with certain extensions. If no parsing algorithm is set for a certain extension, the default one is used. Each JSON object in the array must contain the following properties:
        • extension — extension that the algorithm applies to (must be unique for each array element).
        • name — name of the parsing algorithm.

Important! If you set a specific parsing algorithm for an existing HotFolder project, all files uploaded earlier and parsed using other algorithms will be processed again.

  • languageTagReplacements — optional array of JSON objects collating Smartcat standard language tags with locally used ones. If no replacement is set, the default Smartcat tag is used. One Smartcat language tag can match only one local tag. Each JSON object in the array must contain the following properties:
    • SmartcatLanguageTag — language tag in Smartcat.
    • replacement — language tag (string) used locally.

The settings can also contain the following optional commands:

  • preSyncCommands — commands to be executed before syncing.
  • postSyncCommands — commands to be executed after syncing.
  • prePushCommand — commands to be executed before adding and updating files in the Smartcat project.
  • postPushCommand — commands to be executed after adding and updating files in the Smartcat project.
  • prePullCommands — commands to be executed before downloading translations.
  • postPullCommands — commands to be executed after downloading translations.

You can use the following placeholders in your commands.

For executable commands:

  • {ProjectId} — project id.
  • {SourceDirectoryName} — source directory name.
  • {SourcePath} — full path to the source directory.
  • {SourceLanguage} — source language.

Additional placeholders for naming translated files:

  • {SourceFilePath} — path to the source file.
  • {SourceFilePathFull} — full path to the source file.
  • {SourceFileNameFull} — source file name (including extension).
  • {SourceFileName} — source file name (excluding extension).
  • {SourceFileNameWithoutLangSuffix} — source file name (excluding extension and language suffix, if any). The suffix is searched for taking into account the languageTagsReplacement property. Example: if the source language tag is 'ru' and the full file name is 'name.ru.resx', this placeholder will return 'name'.
  • {SourceFileExtension} — extension of the source file.
  • {TargetLanguage} — target language (Smartcat tag or local string based on languageTagsReplacement).

 Additional placeholders retrieved using the placeholdersRegex parameter can be used both in commands and in translation naming rules.

Configuration file — Example

{
         serviceMode: {

         syncInterval: 30,

commands: {

workingDirectory: "C:\\test",

preWorkCommands: ["git fetch --all", "checkout origin/develop -f"],

postWorkCommands: ["git add *.resx", "git commit -c translated resources", "git push origin"]

}

         },

         projects: [

         {

connection: {

         url: "https://localhost",

         timeout: 100000,

         clientId: "test",

         secretkey: "secret"

},

        projectId: "00000000-0000-0000-0000-000000000000",

        path: "C:\\folder 1",

         localStatePath: "C:\\folder 1\\.hotfolder",

         fileProcessingTimeout: 120000,

         exportTimeout: 120000,

defaultTranslationSettings: {

uploadTranslationsForNewFiles: true,

         confirmUploadedTranslations: true,

placeholdersRegex: "(?[\\w]+)-[\\w]{2}\\.[\\w]+"

},

        files: [

                  {

                  searchPattern: "Web\\**\\*.resx",

                  resultNaming: "{SourceFilePath}\\{SourceFileName}.{TargetLanguage}.{SourceFileExtension}"

                  },

                  {

                  searchPattern: "Web\\content\\manuals\\*.pdf",

                  resultNaming: "{SourceFilePath}\\{TargetLanguage}\\{SourceFileNameFull}",

                  uploadTranslationsForNewFiles: false,

placeholdersRegex: "(?[\\w]+)_[\\w]+\\.[\\w]+"

                  },

                  {

                  searchPattern: "Web\\content\\manuals\\*.docx",

                  resultNaming: "{SourceFilePath}\\{TargetLanguage}\\{SourceFileNameFull}",

                  confirmUploadedTranslations: false,

placeholdersRegex: "(?[\\w]+)_[\\w]+\\.[\\w]+"

                  }

        ],

exclude: ["Web\\**\\LogMessages.resx", "Web\\**\\temp\\*.resx"],

disassembleAlgorithms: [

{

                  extension: "po",

                  name: "PO Reversed"

},

{

extension: "xlf",

name: "xliff_v3"

         }

],

        languageTagReplacements: [

                  {

                           SmartcatLanguageTag: "en",

                  replacement: "en–GB"

                  },

                  {

                           SmartcatLanguageTag: "zh–Hant",

                           replacement: "zh–CHT"               

                  }

        ],

        prePushCommands: ["git fetch —-all", "checkout origin/develop —f"],

        postPushCommands: ["git add *.resx", "git commit —c translated resources", "git push origin"],

        prePullCommands: ["git fetch —-all", "checkout origin/develop —f"],

        postPullCommands: ["git add *.resx", "git commit —c translated resources", "git push origin"],

        preSyncCommands: ["git fetch —-all", "checkout origin/develop —f"],

        postSyncCommands: ["git add *.resx", "git commit —c translated resources", "git push origin"]

         },

         {

connection: {

         url: "https://localhost",

         timeout: 100000,

         clientId: "test",

         secretkey: "secret"

         },

        projectId: "00000000-0000-0000-0000-000000000001",

        path: "C:\\folder 2",

localStatePath: "C:\\folder 2\\.hotfolder",

         fileProcessingTimeout: 120000,

         exportTimeout: 120000,

defaultTranslationSettings: {

uploadTranslationsForNewFiles: false,

confirmUploadedTranslations: false

},

files: [

                  {

                  searchPattern: "Converter\\**\\*.po",

                  resultNaming: "{SourceFilePath}\\{SourceFileName}.{TargetLanguage}.{SourceFileExtension}"

                  },

        ]
         }
         ]
}

 

Local statuses of HotFolder project files

            Local statuses of HotFolder project files are stored in the .hotfolder subdirectory within the project directory. The status of each file is described in a separate file, the filename being a hash code of the source file path. File statuses are saved to subfolders named according to the first two characters of the filename.

            For each file, its path, the match between the local file and the project document, and the file hash are saved.

Was this article helpful?