Package org.zanata.model.tm

Examples of org.zanata.model.tm.TransMemory


    @Override
    @Restrict("#{s:hasRole('admin')}")
    public Response getTranslationMemory(@Nonnull String slug) {
        log.debug("exporting TMX for translation memory {}", slug);
        TransMemory tm = getTM(transMemoryDAO.getBySlug(slug), slug);
        String filename = makeTMXFilename(slug);
        CloseableIterator<TransMemoryUnit> iter =
                transMemoryStreamingDAO.findTransUnitsByTM(tm);
        return buildTMX("getTranslationMemory-" + filename, tm, iter, filename);
    }
View Full Code Here


        super(TransMemory.class, session);
    }

    public Optional<TransMemory> getBySlug(@Nonnull String slug) {
        if (!StringUtils.isEmpty(slug)) {
            TransMemory tm =
                    (TransMemory) getSession().byNaturalId(TransMemory.class)
                            .using("slug", slug).load();
            return Optional.fromNullable(tm);
        }
        return Optional.absent();
View Full Code Here

    @Test
    @org.junit.Test
    public void mergeComplementaryTM() throws Exception {
        // Initial load
        TransMemory tm = createTMFromFile("/tmx/default-valid-tm.tmx");

        // Make sure everything is stored properly
        tm = getEm().find(TransMemory.class, tm.getId());
        assertThat(tm.getTranslationUnits().size(), is(4));

        // Second load (should add all new tuids)
        populateTMFromFile(tm, "/tmx/valid-tm-with-tuids.tmx");

        tm = getEm().find(TransMemory.class, tm.getId());
        assertThat(tm.getTranslationUnits().size(), is(8));
    }
View Full Code Here

                new TransMemoryTMXExportStrategy(createTM()));
    }

    private TransMemory createTM() throws TMXParseException {
        Date now = new Date();
        TransMemory tm = new TransMemory();
        Element headerElem = newTmxElement("header");
        headerElem.addAttribute(new Attribute("adminlang", "en-US"));
        headerElem.addAttribute(new Attribute("datatype", "unknown"));
        headerElem.addAttribute(new Attribute("o-tmf", "OTMF"));
        headerElem.addAttribute(new Attribute("segtype", "paragraph"));
        headerElem.addAttribute(new Attribute("srclang", "en-US"));
        addCustomProperty(headerElem, "prop1", "propval1");
        addCustomProperty(headerElem, "prop2", "propval2");
        TMXMetadataHelper.setMetadata(tm, headerElem);
        tm.setSourceLanguage(sourceLocale.getId());
        tm.setCreationDate(now);
        tm.setLastChanged(now);
        return tm;
    }
View Full Code Here

        return tm;
    }

    private @Nonnull
    Iterator<TransMemoryUnit> createTestData() throws TMXParseException {
        TransMemory tm = null;
        String fr = LocaleId.FR.getId();
        String de = LocaleId.DE.getId();
        String sourceLoc = sourceLocale.getId();
        ArrayList<TransMemoryUnit> tuList =
                Lists.<TransMemoryUnit> newArrayList(
View Full Code Here

        deleteTMData();
    }

    private void createTMData() {
        TransMemory tm = tm("testTM");
        session.save(tm);
        String fr = LocaleId.FR.getId();
        String de = LocaleId.DE.getId();
        String sourceLoc = "en-US";
        ArrayList<TransMemoryUnit> tus =
View Full Code Here

                .use("session", getSession());
    }

    private TransMemory createTMFromFile(String file) throws Exception {
        TransMemoryDAO transMemoryDAO = seam.autowire(TransMemoryDAO.class);
        TransMemory tm = new TransMemory();
        tm.setSlug("new-tm");
        tm.setDescription("New test tm");
        transMemoryDAO.makePersistent(tm);

        populateTMFromFile(tm, file);
        return tm;
    }
View Full Code Here

    @Test
    @org.junit.Test
    public void parseTMX() throws Exception {
        // Create a TM
        TransMemory tm = createTMFromFile("/tmx/default-valid-tm.tmx");

        // Make sure everything is stored properly
        tm = getEm().find(TransMemory.class, tm.getId());
        assertThat(tm.getTranslationUnits().size(), is(4));

        // Dates were modified to match the TM header in the file
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(tm.getCreationDate());
        assertThat(cal.get(Calendar.YEAR), is(2013));
        assertThat(cal.get(Calendar.MONTH), is(4));
        assertThat(cal.get(Calendar.DATE), is(9));

        assertThat(tm.getSourceLanguage(), equalTo("en"));

        // TM metadata
        assertThat(tm.getMetadata().size(), greaterThan(0));
        assertThat(tm.getMetadata().get(TMMetadataType.TMX14), notNullValue());

        // Translation Units
        for (TransMemoryUnit tu : tm.getTranslationUnits()) {
            assertThat(tu.getTransUnitVariants().size(), greaterThan(0));
        }
    }
View Full Code Here

    @Test
    @org.junit.Test
    public void parseDubiousTMXDespiteUnderscoresInLocales() throws Exception {
        // Create a TM
        TransMemory tm =
                createTMFromFile("/tmx/dubious-tm-with-underscores.tmx");

        // Make sure everything is stored properly
        tm = getEm().find(TransMemory.class, tm.getId());
        assertThat(tm.getTranslationUnits().size(), is(1));

        assertThat(tm.getSourceLanguage(), equalTo("en-US"));

        Set<String> expectedLocales =
                Sets.newHashSet("en-US", "es", "es-ES", "fr", "fr-FR", "he",
                        "it", "it-IT");
        TransMemoryUnit tu = tm.getTranslationUnits().iterator().next();
        HashSet<String> actualLocales =
                Sets.newHashSet(tu.getTransUnitVariants().keySet());
        assertThat(actualLocales, equalTo(expectedLocales));
    }
View Full Code Here

    @Test
    @org.junit.Test
    public void parseTMXWithMetadata() throws Exception {
        // Create a TM
        TransMemory tm = createTMFromFile("/tmx/valid-tmx-with-metadata.tmx");

        // Make sure everything is stored properly
        tm = getEm().find(TransMemory.class, tm.getId());

        // Metadata at the header level
        Map<String, String> tmAtts = TMXMetadataHelper.getAttributes(tm);
        assertThat(tmAtts.size(), is(9));
        assertThat(tmAtts, hasEntry("segtype", "paragraph"));
        assertThat(tmAtts, hasEntry("creationtoolversion", "unknown"));
        assertThat(tmAtts,
                hasEntry("creationtool", "Zanata TransMemoryExportTMXStrategy"));
        assertThat(tmAtts, hasEntry("datatype", "unknown"));
        assertThat(tmAtts, hasEntry("adminlang", "en"));
        assertThat(tmAtts, hasEntry("o-tmf", "unknown"));
        assertThat(tmAtts, hasEntry("srclang", "*all*"));
        assertThat(tmAtts, hasKey("creationdate"));
        assertThat(tmAtts, hasKey("changedate"));

        List<Element> tmChildren = TMXMetadataHelper.getChildren(tm);
        assertThat(tmChildren.size(), is(2));
        assertThat(tmChildren.get(0).getLocalName(), is("prop"));
        assertThat(tmChildren.get(0).getValue(), is("Header Prop value"));
        assertThat(tmChildren.get(1).getLocalName(), is("note"));
        assertThat(tmChildren.get(1).getValue(), is("Header Note value"));

        // Metadata at the TU level
        TransMemoryUnit tu0 =
                findInCollection(tm.getTranslationUnits(), "doc0:resId0");
        Map<String, String> tu0Atts = TMXMetadataHelper.getAttributes(tu0);
        assertThat(tu0Atts.size(), is(4));
        assertThat(tu0Atts, hasEntry("tuid", "doc0:resId0"));
        assertThat(tu0Atts, hasEntry("srclang", "en"));
        assertThat(tu0Atts, hasKey("creationdate"));
        assertThat(tu0Atts, hasKey("changedate"));

        List<Element> tu0Children = TMXMetadataHelper.getChildren(tu0);
        assertThat(tu0Children.size(), is(2));
        assertThat(tu0Children.get(0).getLocalName(), is("prop"));
        assertThat(tu0Children.get(0).getValue(), is("Custom prop0 value"));
        assertThat(tu0Children.get(1).getLocalName(), is("note"));
        assertThat(tu0Children.get(1).getValue(), is("Custom note"));

        TransMemoryUnit tu1 =
                findInCollection(tm.getTranslationUnits(), "doc0:resId1");
        Map<String, String> tu1Atts = TMXMetadataHelper.getAttributes(tu1);
        assertThat(tu1Atts.size(), is(4));
        assertThat(tu1Atts, hasEntry("tuid", "doc0:resId1"));
        assertThat(tu1Atts, hasEntry("srclang", "en"));
        assertThat(tu1Atts, hasKey("creationdate"));
View Full Code Here

TOP

Related Classes of org.zanata.model.tm.TransMemory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.