Batch Search and Replace and Selective Pretranslation in OmegaT

Update: Most of the post ramains true, but make sure you download these scripts from the SF.net repository.

In this post I want to share three scripts that can do an extended search and replace in OmegaT project. Search and replace templates for each script are specified in external plain text files located in project’s root folder, so these scripts without any modifications can be used for different projects with different sets of search and replace patterns — the user needs to modify only those plain text files as needed. On top of text modification there is a possibility to do a simple math on what is being found by the script thus enabling the user to have a per project unit converter.
Each script should be accompanied by its own external file located in a subfolder named .ini in the project’s root (details under each script further on). The format of these files is the same for all three:


  • Only one empty line in the file — the very last one
  • Each line consists of tree blocks:
    1. Search pattern (regex aware)
    2. Tab
    3. Replace pattern

So, if you need to replace “Владимир Владимирович” (taking into consideration different cases of Russian nouns) with “the President of Russian Federation“, here’s what you need to specify in the substitution file:
Владимир\p{L}?+\sВладимирович\p{L}?+ the President of Russian Federation Continue reading

Substitute Template For Each Project

Update: Please, download scripts from the dedicated SF.net project page where they are maintained. Scripts at the links below might be obsolete (though most likely still working).

Here I have a script that reads a tab-separated file (any number of tabs between items), each line of which contains the patterns to be found in the first position, and what it should be replaced with in the second. This file MUST be named subst_template.txt (well, it can be changed in the script, so maybe such a loud “must” isn’t really needed). The first pair should start on the first line, no empty lines between the pairs, and after the final pair there should be exactly one empty line. Below you’ll find an example of such file.
The file ought to be placed in OmegaT project’s root. That is made intentionally so that one can have a unique set of substitute patterns for each project. For example, I had an English to Ukrainian Christian project where names of the Bible books needed to be translated using one particular Ukrainian Bible version (Khomenko Bible), while for another project they needed to be taken from another version (Ohiyenko Bible). While English abbreviations remained the same, Ukrainian needed to be quite different (for instance, “Jn.” was “Йо.” in one, and “Ів.” in the other). So having a separate substitute pattern file in each projects I could use just one script to get Bible references with proper abbreviations in each of them. Continue reading

Пошук перекладу слова або фрази

Ситуація:

Під час роботи у програмі OmegaT над великим проектом натрапляєш на слово або фразу, і стає зрозуміло, що слово це чи фраза мають перекладатись у цьому проекті скрізь однаково. Аби цього досягти, вносиш потрібне слово чи фразу разом із перекладом у користувацький глосарій, і далі маєш щастя. Однак, якщо точно знаєш, що вже таке слово траплялось і вже ти його перекладав, от тільки згадати не можеш, як саме, що тоді? Правильно — пошук.

Проблема:

Пошук потрібних слова або фрази серед сегментів оригіналу [In source] видає сегменти і з перекладом, і без нього, не підсвічуючи результати різними кольорами, як у панелі редагування. Якщо проект великий, то пошук серед великої кількості результатів може бути доволі марудним. Звісно, можна пошукати серед перекладених сегментів [In translation] за ключовими словами, однак що робити, якщо не можеш згадати, якими саме словами перекладав це слово, або якщо хочеш подивитись, як його переклав інший перекладач з команди? Отож, наша проблема — знайти лише ті сегменти мовою оригіналу з потрібним нам словом, які мають переклад, і не показувати сегменти без перекладу.

Continue reading