Search in sources :

Example 6 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class MainTest method testConsoleTranslate.

@Test
public void testConsoleTranslate() throws Exception {
    // Create project properties
    ProjectProperties props = new ProjectProperties(tmpDir.toFile());
    // Create project internal directories
    props.autocreateDirectories();
    // Create version-controlled glossary file
    props.getWritableGlossaryFile().getAsFile().createNewFile();
    ProjectFileStorage.writeProjectFile(props);
    String fileName = "foo.txt";
    List<String> fileContent = Arrays.asList("Foo");
    Path srcFile = tmpDir.resolve(OConsts.DEFAULT_SOURCE).resolve(fileName);
    Files.write(srcFile, fileContent);
    Main.main(new String[] { "--mode=console-translate", tmpDir.toString() });
    Path trgFile = tmpDir.resolve(OConsts.DEFAULT_TARGET).resolve(fileName);
    assertTrue(trgFile.toFile().isFile());
    assertEquals(fileContent, Files.readAllLines(trgFile));
}
Also used : Path(java.nio.file.Path) ProjectProperties(org.omegat.core.data.ProjectProperties) Test(org.junit.Test)

Example 7 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class FalseFriendsTest method setUp.

@Before
public final void setUp() {
    final ProjectProperties props = new ProjectProperties() {

        public Language getSourceLanguage() {
            return new Language("en");
        }

        public Language getTargetLanguage() {
            return new Language("pl");
        }
    };
    Core.setProject(new IProject() {

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, TMXEntry.ExternalLinked externalLinked) {
        }

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, ExternalLinked externalLinked, AllTranslations previousTranslations) throws OptimisticLockingFail {
        }

        public void setNote(SourceTextEntry entry, TMXEntry oldTrans, String note) {
        }

        public void saveProjectProperties() throws Exception {
        }

        public void saveProject(boolean doTeamSync) {
        }

        public void iterateByMultipleTranslations(MultipleTranslationsIterator it) {
        }

        public void iterateByDefaultTranslations(DefaultTranslationsIterator it) {
        }

        public boolean isProjectModified() {
            return false;
        }

        public boolean isProjectLoaded() {
            return true;
        }

        public boolean isOrphaned(EntryKey entry) {
            return false;
        }

        public boolean isOrphaned(String source) {
            return false;
        }

        public TMXEntry getTranslationInfo(SourceTextEntry ste) {
            return null;
        }

        public AllTranslations getAllTranslations(SourceTextEntry ste) {
            return null;
        }

        public Map<String, ExternalTMX> getTransMemories() {
            return null;
        }

        public ITokenizer getTargetTokenizer() {
            return null;
        }

        public StatisticsInfo getStatistics() {
            return null;
        }

        public ITokenizer getSourceTokenizer() {
            return null;
        }

        public ProjectProperties getProjectProperties() {
            return props;
        }

        public List<FileInfo> getProjectFiles() {
            return null;
        }

        public Map<Language, ProjectTMX> getOtherTargetLanguageTMs() {
            return null;
        }

        public List<SourceTextEntry> getAllEntries() {
            return null;
        }

        public void compileProject(String sourcePattern) throws Exception {
        }

        public void closeProject() {
        }

        public List<String> getSourceFilesOrder() {
            return null;
        }

        public void setSourceFilesOrder(List<String> filesList) {
        }

        @Override
        public String getTargetPathForSourceFile(String sourceFile) {
            return null;
        }

        @Override
        public boolean isTeamSyncPrepared() {
            return false;
        }

        @Override
        public void teamSync() {
        }

        @Override
        public void teamSyncPrepare() throws Exception {
        }

        @Override
        public boolean isRemoteProject() {
            return false;
        }

        @Override
        public void commitSourceFiles() throws Exception {
        }

        @Override
        public void compileProjectAndCommit(String sourcePattern, boolean doPostProcessing, boolean commitTargetFiles) throws Exception {
        }
    });
    LanguageToolWrapper.setBridgeFromCurrentProject();
}
Also used : ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) EntryKey(org.omegat.core.data.EntryKey) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) ProjectProperties(org.omegat.core.data.ProjectProperties) IProject(org.omegat.core.data.IProject) ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) ITokenizer(org.omegat.tokenizer.ITokenizer) Language(org.omegat.util.Language) SourceTextEntry(org.omegat.core.data.SourceTextEntry) List(java.util.List) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) Map(java.util.Map) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry) Before(org.junit.Before)

Example 8 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectFileStorageTest method testLoadCustomGlossaryFile.

@Test
public void testLoadCustomGlossaryFile() throws Exception {
    ProjectProperties props = ProjectFileStorage.loadPropertiesFile(tempDir, new File(PROJECT_DIR, "customglossaryfile.project"));
    props.autocreateDirectories();
    props.verifyProject();
    assertTrue(props.getWriteableGlossary().endsWith("glossary/bar.txt"));
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) Test(org.junit.Test)

Example 9 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectFileStorageTest method testFarRelativePaths.

@Test
public void testFarRelativePaths() throws Exception {
    File projFile = new File(PROJECT_DIR, "defaultdirs.project");
    Omegat omt = ProjectFileStorage.parseProjectFile(projFile);
    String prefix = repeat(OConsts.MAX_PARENT_DIRECTORIES_ABS2REL, "a/");
    File projRoot = Paths.get(tempDir.getAbsolutePath(), prefix, "root").toFile();
    projRoot.mkdirs();
    // Set project folders to absolute paths
    File srcDir = new File(tempDir, "source").getAbsoluteFile();
    File trgDir = new File(tempDir, "target").getAbsoluteFile();
    File dictDir = new File(tempDir, "dictionary").getAbsoluteFile();
    File glosDir = new File(tempDir, "glossary").getAbsoluteFile();
    File tmDir = new File(tempDir, "tm").getAbsoluteFile();
    String relPrefix = repeat(OConsts.MAX_PARENT_DIRECTORIES_ABS2REL + 1, "../");
    omt.getProject().setSourceDir(relPrefix + srcDir.getName());
    omt.getProject().setTargetDir(relPrefix + trgDir.getName());
    omt.getProject().setDictionaryDir(relPrefix + dictDir.getName());
    omt.getProject().setGlossaryDir(relPrefix + glosDir.getName());
    omt.getProject().setTmDir(relPrefix + tmDir.getName());
    // Make all the actual folders
    Arrays.asList(srcDir, trgDir, dictDir, glosDir, tmDir).forEach(File::mkdirs);
    // Load the ProjectProperties and verify that the project folders
    // are resolved correctly
    ProjectProperties props = ProjectFileStorage.loadPropertiesFile(projRoot, omt);
    props.verifyProject();
    // Indirections should be resolved.
    assertFalse(props.getSourceRoot().contains("../"));
    assertFalse(props.getTargetRoot().contains("../"));
    assertFalse(props.getDictRoot().contains("../"));
    assertFalse(props.getGlossaryRoot().contains("../"));
    assertFalse(props.getTMRoot().contains("../"));
    // Write the project file out and read it again to make sure the
    // paths are correctly round-tripped. Since these are "far" paths
    // they should become absolute and not remain relative.
    ProjectFileStorage.writeProjectFile(props);
    File outProjFile = new File(projRoot, OConsts.FILE_PROJECT);
    assertTrue(outProjFile.isFile());
    Omegat outOmt = ProjectFileStorage.parseProjectFile(outProjFile);
    assertEquals(ProjectFileStorage.normalizeSlashes(srcDir.getPath()), outOmt.getProject().getSourceDir());
    assertEquals(ProjectFileStorage.normalizeSlashes(trgDir.getPath()), outOmt.getProject().getTargetDir());
    assertEquals(ProjectFileStorage.normalizeSlashes(dictDir.getPath()), outOmt.getProject().getDictionaryDir());
    assertEquals(ProjectFileStorage.normalizeSlashes(glosDir.getPath()), outOmt.getProject().getGlossaryDir());
    assertEquals(ProjectFileStorage.normalizeSlashes(tmDir.getPath()), outOmt.getProject().getTmDir());
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) Omegat(gen.core.project.Omegat) Test(org.junit.Test)

Example 10 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectFileStorageTest method testNearRelativePaths.

@Test
public void testNearRelativePaths() throws Exception {
    File projFile = new File(PROJECT_DIR, "defaultdirs.project");
    Omegat omt = ProjectFileStorage.parseProjectFile(projFile);
    for (int i = 0; i < OConsts.MAX_PARENT_DIRECTORIES_ABS2REL; i++) {
        File projRoot = Paths.get(tempDir.getAbsolutePath(), repeat(i, "a/"), "root").toFile();
        projRoot.mkdirs();
        // Set project folders to relative paths
        File srcDir = new File(tempDir, "source").getAbsoluteFile();
        File trgDir = new File(tempDir, "target").getAbsoluteFile();
        File dictDir = new File(tempDir, "dictionary").getAbsoluteFile();
        File glosDir = new File(tempDir, "glossary").getAbsoluteFile();
        File tmDir = new File(tempDir, "tm").getAbsoluteFile();
        String prefix = repeat(i + 1, "../");
        omt.getProject().setSourceDir(prefix + srcDir.getName());
        omt.getProject().setTargetDir(prefix + trgDir.getName());
        omt.getProject().setDictionaryDir(prefix + dictDir.getName());
        omt.getProject().setGlossaryDir(prefix + glosDir.getName());
        omt.getProject().setTmDir(prefix + tmDir.getName());
        // Make all the actual folders
        Arrays.asList(srcDir, trgDir, dictDir, glosDir, tmDir).forEach(File::mkdirs);
        // Load the ProjectProperties and verify that the project folders
        // are resolved correctly
        ProjectProperties props = ProjectFileStorage.loadPropertiesFile(projRoot, omt);
        props.verifyProject();
        // Indirections should be resolved.
        assertFalse(props.getSourceRoot().contains("../"));
        assertFalse(props.getTargetRoot().contains("../"));
        assertFalse(props.getDictRoot().contains("../"));
        assertFalse(props.getGlossaryRoot().contains("../"));
        assertFalse(props.getTMRoot().contains("../"));
        // Write the project file out and read it again to make sure the
        // paths are correctly round-tripped. Since these are "near" paths
        // they should remain relative and not absolute.
        ProjectFileStorage.writeProjectFile(props);
        File outProjFile = new File(projRoot, OConsts.FILE_PROJECT);
        assertTrue(outProjFile.isFile());
        Omegat outOmt = ProjectFileStorage.parseProjectFile(outProjFile);
        assertEquals(prefix + srcDir.getName(), outOmt.getProject().getSourceDir());
        assertEquals(prefix + trgDir.getName(), outOmt.getProject().getTargetDir());
        assertEquals(prefix + dictDir.getName(), outOmt.getProject().getDictionaryDir());
        assertEquals(prefix + glosDir.getName(), outOmt.getProject().getGlossaryDir());
        assertEquals(prefix + tmDir.getName(), outOmt.getProject().getTmDir());
    }
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) Omegat(gen.core.project.Omegat) Test(org.junit.Test)

Aggregations

ProjectProperties (org.omegat.core.data.ProjectProperties)29 File (java.io.File)20 Test (org.junit.Test)11 IOException (java.io.IOException)10 ExecutionException (java.util.concurrent.ExecutionException)6 KnownException (org.omegat.core.KnownException)6 Omegat (gen.core.project.Omegat)4 Cursor (java.awt.Cursor)4 List (java.util.List)4 Language (org.omegat.util.Language)4 ArrayList (java.util.ArrayList)3 NotLoadedProject (org.omegat.core.data.NotLoadedProject)3 ProjectPropertiesDialog (org.omegat.gui.dialogs.ProjectPropertiesDialog)3 RepositoryDefinition (gen.core.project.RepositoryDefinition)2 RepositoryMapping (gen.core.project.RepositoryMapping)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 Before (org.junit.Before)2