### Managing Projects with IProject Interface Source: https://context7.com/omegat-org/omegat/llms.txt Provides examples for interacting with the IProject interface to retrieve project properties, modify translations programmatically, save progress, and compile target documents. ```java import org.omegat.core.Core; import org.omegat.core.data.IProject; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.PrepareTMXEntry; import org.omegat.core.data.TMXEntry; import org.omegat.core.data.ProjectProperties; IProject project = Core.getProject(); // Check if project is loaded if (!project.isProjectLoaded()) { return; } // Get project properties ProjectProperties props = project.getProjectProperties(); String sourceLanguage = props.getSourceLanguage().getLanguage(); String targetLanguage = props.getTargetLanguage().getLanguage(); // Iterate through all entries for (SourceTextEntry ste : project.getAllEntries()) { int entryNum = ste.entryNum(); String sourceText = ste.getSrcText(); // Get translation info TMXEntry trans = project.getTranslationInfo(ste); if (trans.isTranslated()) { System.out.printf("Segment %d: %s -> %s%n", entryNum, sourceText, trans.translation); } } // Set a translation programmatically SourceTextEntry entry = project.getAllEntries().get(0); PrepareTMXEntry newTrans = new PrepareTMXEntry(); newTrans.translation = "New translation text"; newTrans.changer = "script"; newTrans.changeDate = System.currentTimeMillis(); project.setTranslation(entry, newTrans, true, null); // Save project project.saveProject(true); // true = perform team sync if applicable // Compile translated documents (create target files) project.compileProject(".*"); // Pattern matches all files ``` -------------------------------- ### Retrieve system paths with StaticUtils Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/27.UtilityClasses.md Provides access to standard OmegaT directory paths, including configuration, installation, and script directories. ```Java File configDir = StaticUtils.getConfigDir(); File installDir = StaticUtils.installDir(); File scriptDir = StaticUtils.getScriptDir(); ``` -------------------------------- ### Start Remote Debugging with Gradle Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/28.LoggingAndDebugging.md Commands to launch OmegaT in a state that allows a remote debugger to attach to the JVM on port 5005. ```bash ./gradlew run --debug-jvm ``` ```bash ./gradlew runDebugger ``` -------------------------------- ### Generate Language Links with Groovy Source: https://github.com/omegat-org/omegat/blob/master/src_docs/template/index.html Uses Groovy server-side templating to iterate over a collection of languages. It generates conditional links to the Instant Start Guide and the main index based on the language's manual availability. ```groovy <% languages.each { lang -> if (lang.nomanual) { %> <% } else { %> <% } } %> [${lang.name}](${lang.code}/instantStartGuideNoTOC.html) [${lang.name}](${lang.code}/index.html) ``` -------------------------------- ### Gradle Build Configuration for OmegaT Plugin Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/11.HowToCreateFilterPlugin.md Example Gradle build script for an OmegaT plugin project. It includes necessary plugins, version information, and OmegaT-specific configurations like version and plugin class. ```groovy plugin { id('java') id('distribution') id 'org.omegat.gradle' version '1.5.11' } version='1.0.0' group='your.group.id' omegat { version='5.7.1' pluginClass='org.myorganization.MyFilter' } ``` -------------------------------- ### Configure Gradle properties for Windows code signing Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/93.BuildingInstallerPackage.md This configuration snippet defines the PKCS11 module path, certificate identifier, and signing credentials required for the Gradle build process to sign Windows executables. ```properties #pkcs11engine=/usr/lib/x86_64-linux-gnu/engine-3/libpkcs11.so pkcs11module=/usr/lib/libcrypto3PKCS.so pkcs11cert=pkcs11:type=cert winCodesignPassword=passphraseHere winCodesignTimestampUrl=http://time.certum.pl/ ``` -------------------------------- ### Execute OmegaT headless operations via CLI Source: https://context7.com/omegat-org/omegat/llms.txt Provides examples for running OmegaT in console mode for tasks such as batch translation, statistics generation, file alignment, and script execution. These commands are suitable for integration into automated build pipelines. ```bash java -jar OmegaT.jar /path/to/project --mode=console-translate java -jar OmegaT.jar /path/to/project --mode=console-stats --output-file=stats.txt java -jar OmegaT.jar /path/to/project --mode=console-align --alignDir=/path/to/translations java -jar OmegaT.jar /path/to/project --mode=console-translate --script=/path/to/script.groovy java -jar OmegaT.jar --remote-project=https://git.example.com/team/project.git ``` -------------------------------- ### Configure Gradle for OmegaT Plugin Development Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/15.SetupPluginProject.md This Gradle configuration sets up a Java project for OmegaT plugin development. It applies the OmegaT Gradle plugin and specifies OmegaT version and the main plugin class. The `gradle.properties` file defines metadata for the plugin. ```groovy plugin { id('java') id('distribution') id 'org.omegat.gradle' version '1.5.11' } version='1.0.0' group='your.group.id' omegat { version='5.7.1' pluginClass='org.myorganization.MyFilter' } ``` ```properties plugin.name=My Filter Name plugin.category=filter plugin.link=https://github.com/omegat-org/plugin-skeleton plugin.author=My name here. plugin.description=I describe my plugin here. This plugin does amazing things plugin.license=GNU General Public License version 3 ``` -------------------------------- ### Java CLI Command Implementation Pattern Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/adr/2024001.CLIandExtensions.md Demonstrates the standard pattern for implementing commands using PicoCLI. It includes annotations for command registration, parameter definition, and option handling, along with the basic structure for the command's execution logic. ```java import picocli.CommandLine.Command; import picocli.CommandLine.Parameters; import picocli.CommandLine.Option; import java.util.List; import java.util.concurrent.Callable; @Command(name = "commandname", description = "Command description") public class ExampleCommand implements Callable { @Parameters(description = "Command parameters") private List parameters; @Option(names = {"-o", "--option"}, description = "Option description") private String option; @Override public int call() { // Command implementation System.out.println("Executing command..."); if (parameters != null) { System.out.println("Parameters: " + parameters); } if (option != null) { System.out.println("Option: " + option); } return 0; // Indicate successful execution } } ``` -------------------------------- ### Install dictionary-en package Source: https://github.com/omegat-org/omegat/blob/master/spellchecker/lucene/src/test/resources/org/omegat/spellchecker/lucene/readme.md Instructions for installing the dictionary-en package using the npm package manager in a Node.js environment. ```shell npm install dictionary-en ``` -------------------------------- ### Create a Basic Groovy Script for OmegaT Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/51.HowToWriteScript.md Demonstrates how to write a Groovy script for OmegaT that accesses project properties and interacts with the user via the console and GUI dialogs. ```groovy // :name = Hello World // :description = Greets the user and prints project info. import javax.swing.JOptionPane console.println("Hello from Groovy!") console.println("Current project: " + project.projectProperties.projectName) def gui() { JOptionPane.showMessageDialog(null, "Hello, OmegaT user!") } ``` -------------------------------- ### Example Hunspell Dictionary Plugin Implementation (Java) Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/52.HowToSpellCheckDictionary.md A sample implementation of the ISpellCheckDictionary interface for a Hunspell dictionary plugin. This example demonstrates how to override the getHunspellDictionary and getDictionaryType methods, and includes a basic close() method for resource cleanup. ```java public class MyHunspellDictionaryPlugin implements ISpellCheckDictionary { @Override public org.apache.lucene.analysis.hunspell.Dictionary getHunspellDictionary(String language) { // Load and return the Hunspell dictionary for the specified language. return new org.apache.lucene.analysis.hunspell.Dictionary(...); } @Override public SpellCheckDictionaryType getDictionaryType() { return SpellCheckDictionaryType.HUNSPELL; } @Override public void close() { // Cleanup resources if needed. } } ``` -------------------------------- ### Configure Logging via Gradle Command Line Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/28.LoggingAndDebugging.md Demonstrates how to pass a custom logging configuration file to OmegaT using Gradle arguments during execution. ```bash ./gradlew run --args="-Djava.util.logging.config.file=/path/to/logger.properties" ``` -------------------------------- ### Applying Module Conventions in Gradle Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/adr/2025001.BuildSystem.md Demonstrates how individual module subprojects apply shared build configurations using Gradle's 'plugins' block. This centralizes repetitive build logic and ensures consistency across modules. ```groovy plugins { id 'org.omegat.module-conventions' } ``` -------------------------------- ### Accessing Core OmegaT Components Source: https://context7.com/omegat-org/omegat/llms.txt Demonstrates how to use the Core singleton to access the project, editor, spell checker, and glossary services. It shows how to iterate through translation entries and check their status. ```java import org.omegat.core.Core; import org.omegat.core.data.IProject; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.TMXEntry; // Access the current project IProject project = Core.getProject(); if (project.isProjectLoaded()) { // Get all source text entries List entries = project.getAllEntries(); for (SourceTextEntry ste : entries) { String source = ste.getSrcText(); TMXEntry translation = project.getTranslationInfo(ste); if (translation.isTranslated()) { System.out.println("Source: " + source); System.out.println("Target: " + translation.translation); } } // Access project statistics StatisticsInfo stats = project.getStatistics(); System.out.println("Total segments: " + stats.numberOfSegmentsTotal); } // Access the editor IEditor editor = Core.getEditor(); editor.gotoEntry(1); // Navigate to segment 1 // Access spell checker ISpellChecker spellChecker = Core.getSpellChecker(); boolean isCorrect = spellChecker.isCorrect("word"); // Access glossary IGlossaries glossary = Core.getGlossary(); ``` -------------------------------- ### Define Log Levels in logger.properties Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/28.LoggingAndDebugging.md Example configuration for setting specific package log levels within a Java logging properties file. ```properties org.omegat.core.data.level = ALL org.omegat.gui.editor.level = FINE ``` -------------------------------- ### Execute Integration Tests with Docker Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/90.ReleaseProcedure.md Commands to build and run integration tests using docker-compose. This ensures the environment is consistent with the weekly release build CI/CD scripts. ```console docker-compose -f docker-compose.yml build docker-compose -f docker-compose.yml up --abort-on-container-exit docker-compose down ``` -------------------------------- ### Per-Plugin ClassLoader Isolation Example (Java) Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/24.PluginSecurity.md Illustrates the industry best practice of 'per-plugin' ClassLoader isolation. Each plugin is loaded with its own ClassLoader, ensuring complete isolation, dependency safety, and fault containment. ```java public class PluginUtils { Map pluginClassLoaders = new ConcurrentHashMap<>(); public void loadPlugins() { // ... several initializations // During plugin loading: for (PluginManifest manifest : manifests) { ClassLoader pluginClassLoader = new URLClassLoader( manifest.getClasspathUrls(), getClass().getClassLoader() ); pluginClassLoaders.put(manifest.getPluginId(), pluginClassLoader); } } } ``` -------------------------------- ### Sign Windows Executables on Linux Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/90.ReleaseProcedure.md A shell script snippet demonstrating how to use osslsigncode to sign Windows executables on a Linux system using a hardware security module (HSM). ```bash #!/bin/sh infilie=$1 outfile=$2 toolexe=osslsigncode engine=/usr/lib/x86_64-linux-gnu/engines-3/pkcs11.so module=/opt/proCertumCardManager/sc30pkcs11-3.0.6.68-MS.so signer="Open Source Developer, Hiroshi Miura" certs=cert/25044ce4fc92c7b98fcafdd60f46c724.pem ``` -------------------------------- ### Load Plugins Method in OmegaT Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/17.LoadingPlugins.md The `loadPlugins` method is executed on application startup. It's responsible for plugin initialization, including version checking, registering filters, and setting up event listeners. It should handle potential errors gracefully and report them using `Core.pluginLoadingError`. ```java public static void loadPlugins() { try { //analyze OmegaT version: String requiredVersion = "5.4.0"; String requiredUpdate = "0"; try { Class clazz = Class.forName("org.omegat.util.VersionChecker"); Method compareVersions = clazz.getMethod("compareVersions", String.class, String.class, String.class, String.class); if ((int)compareVersions.invoke(clazz, OStrings.VERSION, OStrings.UPDATE, requiredVersion, requiredUpdate) < 0) { Core.pluginLoadingError("Plugin … cannot be loaded because OmegaT Version "+OStrings.VERSION+" is lower than required version "+requiredVersion); return; } } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { Core.pluginLoadingError("Plugin … cannot be loaded because this OmegaT version is not supported"); return; } // … register classes and events … } catch(Throwable ex) { Core.pluginLoadingError("Plugin … cannot be loaded because this version of OmegaT is not supported"); } } ``` -------------------------------- ### OmegaT MT API: isEnabled/setEnabled Methods Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/12.HowToMakeMTConnector.md Methods to get and set the enabled status of the MT connector plugin. This allows users to enable or disable specific MT services. ```java boolean isEnabled(); void setEnabled(boolean b); ``` -------------------------------- ### NetBeans GUI Editor Code Block Source: https://github.com/omegat-org/omegat/blob/master/src_docs/developer/30.CodingStyles.md Example of the auto-generated code block produced by the NetBeans GUI builder. Developers are instructed not to modify this code manually and to use the corresponding .form file. ```Java /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents ```