Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Dec 19, 2011
1 parent 53869df commit a72c8b5
Show file tree
Hide file tree
Showing 405 changed files with 31,647 additions and 1,532 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,15 @@
# Zanata change log summary

## zanata-1.5
* Allow bookmarking of selected document, document list filter and current view: https://bugzilla.redhat.com/show_bug.cgi?id=757621
* Add workspace query string parameters for generating a custom doclist with a custom title: https://bugzilla.redhat.com/show_bug.cgi?id=758587
* e.g. &title=Custom%20title&doc=full/path/of/first/doc&doc=full/path/of/second/doc

## zanata-1.4.4
* Ensure final reindex batch is properly flushed: https://bugzilla.redhat.com/show_bug.cgi?id=747836
* Support UTF-8 Properties files, handle empty properties: https://bugzilla.redhat.com/show_bug.cgi?id=760390
* Fix bug: Editor table stops working after 'Source and Target' search returns no results: https://bugzilla.redhat.com/show_bug.cgi?id=759994

## zanata-1.4.3
* Show message context in editor info panel: https://bugzilla.redhat.com/show_bug.cgi?id=750690
* Update gwteventservice to 1.2.0-RC1
Expand Down
3 changes: 1 addition & 2 deletions client/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.zanata</groupId>
<artifactId>zanata-parent</artifactId>
<version>1.4.4-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>
<relativePath>../zanata-parent/pom.xml</relativePath>
</parent>

Expand All @@ -19,7 +19,6 @@
</scm>

<modules>
<module>zanata-adapter-po</module>
<module>zanata-adapter-properties</module>
<module>zanata-adapter-xliff</module>
<module>zanata-client-commands</module>
Expand Down
8 changes: 7 additions & 1 deletion client/zanata-adapter-properties/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.zanata</groupId>
<artifactId>zanata-parent</artifactId>
<version>1.4.4-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>
<relativePath>../../zanata-parent/pom.xml</relativePath>
</parent>
<packaging>jar</packaging>
Expand Down Expand Up @@ -42,5 +42,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.InvalidPropertiesFormatException;
import java.util.List;

import org.fedorahosted.openprops.Properties;
Expand All @@ -23,6 +24,7 @@ public class PropReader
{

public static final String PROP_CONTENT_TYPE = "text/plain";
private static final String NEWLINE_REGEX = "(\r\n|\r|\n)";

// pre: template already extracted
public void extractTarget(TranslationsResource doc, InputStream in, LocaleId localeId, ContentState contentState) throws IOException
Expand All @@ -46,26 +48,103 @@ public void extractTarget(TranslationsResource doc, InputStream in, LocaleId loc
}
}

/**
* Reads properties from a given {@link InputStream} and adds them to the
* given {@link Resource}.
*
* @param doc the resource to add properties textflows to
* @param in the input stream to read the properties from
* @throws IOException
*/
// TODO allowing Readers (via InputSource) might be a bad idea
// TODO add documentation on exceptions thrown
public void extractTemplate(Resource doc, InputStream in) throws IOException
{
List<TextFlow> resources = doc.getTextFlows();
Properties props = loadProps(in);
int nonTranslatableCount = 0;
for (String key : props.stringPropertyNames())
{
String val = props.getProperty(key);
String id = getID(key, val);
TextFlow textFlow = new TextFlow(id);
textFlow.setContent(val);
String comment = props.getComment(key);
if (comment != null && comment.length() != 0)
String comment = null;
String rawComment = props.getRawComment(key);
if (rawComment != null && rawComment.length() != 0)
{
SimpleComment simpleComment = textFlow.getExtensions(true).findOrAddByType(SimpleComment.class);
simpleComment.setValue(comment);
StringBuilder sb = new StringBuilder(rawComment.length());
nonTranslatableCount = processCommentForNonTranslatable(nonTranslatableCount, rawComment, sb);
comment = sb.toString();
}
if (nonTranslatableCount == 0)
{
String val = props.getProperty(key);
String id = getID(key, val);
TextFlow textFlow = new TextFlow(id);
textFlow.setContent(val);
if (comment != null && comment.length() != 0)
{
SimpleComment simpleComment = textFlow.getExtensions(true).findOrAddByType(SimpleComment.class);
simpleComment.setValue(comment);
}
// textFlow.setLang(LocaleId.EN);
resources.add(textFlow);
}
}
}

/**
* Processes a full comment for non-translatable sections, writing
* translatable sections to a given string buffer.
*
* @param comment comment to process, may have multiple lines
* @param sb string buffer to output comments in translatable blocks
* @return adjusted non-translateable count, a value > 0 indicates that the
* current section is non-translatable
* @throws Exception
*/
private int processCommentForNonTranslatable(int nonTranslatableCount, String comment, StringBuilder sb) throws InvalidPropertiesFormatException
{
int nonTranslatable = nonTranslatableCount;
String[] lines = comment.split(NEWLINE_REGEX);

int lineNonTranslatable;
for (String line : lines)
{
lineNonTranslatable = checkNonTranslatable(line);
nonTranslatable += lineNonTranslatable;
if (nonTranslatable < 0)
{
// TODO probably want a different exception here
throw new InvalidPropertiesFormatException("Found '# END NON-TRANSLATABLE' " + "without matching '# START NON-TRANSLATABLE'");
}
// textFlow.setLang(LocaleId.EN);
resources.add(textFlow);
if (nonTranslatable == 0 && lineNonTranslatable == 0)
{
sb.append(Properties.cookCommentLine(line));
// TODO if not last line
sb.append('\n');
}
}

return nonTranslatable;
}

/**
* Checks a comment for START and END of NON-TRANSLATABLE sections within a
* single line of a comment.
*
* @param line a single line of a comment
* @return 0 if no NON-TRANSLATABLE comment is found, +1 for start, -1 for
* end
*/
private int checkNonTranslatable(String line)
{
if (line.startsWith("# START NON-TRANSLATABLE"))
{
return 1;
}
if (line.startsWith("# END NON-TRANSLATABLE"))
{
return -1;
}
return 0;
}

private String getID(String key, String val)
Expand Down
Expand Up @@ -3,7 +3,8 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.fedorahosted.openprops.Properties;
import org.zanata.rest.dto.extensions.comment.SimpleComment;
Expand All @@ -27,7 +28,15 @@ private static void makeParentDirs(File f)
parentFile.mkdirs();
}

public static void write(final Resource doc, final File baseDir) throws IOException
/**
* Writes a properties file representation of the given {@link Resource} to
* the given directory.
*
* @param doc
* @param baseDir
* @throws IOException
*/
public static void write(final Resource doc, final File baseDir, String charset) throws IOException
{
File baseFile = new File(baseDir, doc.getName() + ".properties");
makeParentDirs(baseFile);
Expand All @@ -42,13 +51,19 @@ public static void write(final Resource doc, final File baseDir) throws IOExcept
props.setComment(textFlow.getId(), simpleComment.getValue());
}
// props.store(System.out, null);
PrintStream out = new PrintStream(new FileOutputStream(baseFile));
props.store(out, null);
Writer out = new OutputStreamWriter(new FileOutputStream(baseFile), charset);
try
{
props.store(out, null);
}
finally
{
out.close();
}
}

public static void write(final TranslationsResource doc, final File baseDir, String bundleName, String locale) throws IOException
public static void write(final TranslationsResource doc, final File baseDir, String bundleName, String locale, String charset) throws IOException
{

Properties targetProp = new Properties();
for (TextFlowTarget target : doc.getTextFlowTargets())
{
Expand All @@ -62,8 +77,15 @@ public static void write(final TranslationsResource doc, final File baseDir, Str
makeParentDirs(langFile);
logVerbose("Creating target file " + langFile);
// targetProp.store(System.out, null);
PrintStream out2 = new PrintStream(new FileOutputStream(langFile));
targetProp.store(out2, null);
Writer out2 = new OutputStreamWriter(new FileOutputStream(langFile), charset);
try
{
targetProp.store(out2, null);
}
finally
{
out2.close();
}
}

}

0 comments on commit a72c8b5

Please sign in to comment.