Search in sources :

Example 1 with ResourceClass

use of org.activityinfo.i18n.tools.model.ResourceClass in project activityinfo by bedatadriven.

the class Check method verifyTermKeysAreGloballyUnique.

private void verifyTermKeysAreGloballyUnique() {
    Map<String, ResourceClass> keys = Maps.newHashMap();
    for (String className : Project.INSTANCE.getResourceClasses()) {
        ResourceClass resourceClass = new ResourceClass(Project.INSTANCE.getSourceDirectory(), className);
        InspectingVisitor visitor = resourceClass.inspect();
        for (String key : visitor.getKeys()) {
            ResourceClass previousDefinition = keys.put(key, resourceClass);
            if (previousDefinition != null) {
                System.err.println(String.format("Duplicate term key '%s' in %s (previously defined in %s)", key, resourceClass.getClassName(), previousDefinition.getClassName()));
                failed = true;
            }
        }
    }
    System.out.println("Found " + keys.size() + " unique term keys");
}
Also used : InspectingVisitor(org.activityinfo.i18n.tools.parser.InspectingVisitor) ResourceClass(org.activityinfo.i18n.tools.model.ResourceClass)

Example 2 with ResourceClass

use of org.activityinfo.i18n.tools.model.ResourceClass in project activityinfo by bedatadriven.

the class Check method checkForXmlEntities.

private void checkForXmlEntities() throws IOException {
    Pattern entityPattern = Pattern.compile("&#?[A-Za-z0-9]+;");
    boolean entityFound = false;
    for (String className : Project.INSTANCE.getResourceClasses()) {
        ResourceClass resourceClass = new ResourceClass(Project.INSTANCE.getSourceDirectory(), className);
        InspectingVisitor visitor = resourceClass.inspect();
        for (ResourceClassTerm term : visitor.getTerms()) {
            Matcher matcher = entityPattern.matcher(term.getDefaultTranslation());
            if (matcher.find()) {
                System.err.println(String.format("Term %s in %s uses the XML entity %s.", term.getKey(), className, matcher.group()));
                entityFound = true;
            }
        }
        for (String language : Project.INSTANCE.getLanguages()) {
            File resourceFile = resourceClass.getResourceFile(language);
            Map<String, String> translations = resourceClass.readResource(language);
            for (String key : translations.keySet()) {
                String translation = translations.get(key);
                Matcher matcher = entityPattern.matcher(translation);
                if (matcher.find()) {
                    System.err.println(String.format("Translation %s in %s uses XML entity %s", key, resourceFile.getName(), matcher.group()));
                    entityFound = true;
                }
            }
        }
    }
    if (entityFound) {
        System.err.println("XML Entities should not be used in terms because they are not parsed in many contexts.");
        System.err.println("Use unicode escapes instead.");
        failed = true;
    }
}
Also used : Pattern(java.util.regex.Pattern) ResourceClassTerm(org.activityinfo.i18n.tools.model.ResourceClassTerm) Matcher(java.util.regex.Matcher) InspectingVisitor(org.activityinfo.i18n.tools.parser.InspectingVisitor) File(java.io.File) ResourceClass(org.activityinfo.i18n.tools.model.ResourceClass)

Example 3 with ResourceClass

use of org.activityinfo.i18n.tools.model.ResourceClass in project activityinfo by bedatadriven.

the class Push method execute.

public void execute() throws IOException {
    List<ResourceClassTerm> terms = Lists.newArrayList();
    for (String className : Project.INSTANCE.getResourceClasses()) {
        ResourceClass resourceClass = new ResourceClass(Project.INSTANCE.getSourceDirectory(), className);
        InspectingVisitor visitor = resourceClass.inspect();
        terms.addAll(visitor.getTerms());
    }
    if (dryRun) {
        Project.INSTANCE.getTranslationSource().dumpNewTerms(terms);
    } else {
        Project.INSTANCE.getTranslationSource().updateTerms(terms, purge);
    }
}
Also used : ResourceClassTerm(org.activityinfo.i18n.tools.model.ResourceClassTerm) InspectingVisitor(org.activityinfo.i18n.tools.parser.InspectingVisitor) ResourceClass(org.activityinfo.i18n.tools.model.ResourceClass)

Aggregations

ResourceClass (org.activityinfo.i18n.tools.model.ResourceClass)3 InspectingVisitor (org.activityinfo.i18n.tools.parser.InspectingVisitor)3 ResourceClassTerm (org.activityinfo.i18n.tools.model.ResourceClassTerm)2 File (java.io.File)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1