This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release' into integration/master
Conflicts: zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java
- Loading branch information
Showing
5 changed files
with
180 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 45 additions & 27 deletions
72
...ta-client-commands/src/main/java/org/zanata/client/commands/push/GettextPushStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,72 @@ | ||
package org.zanata.client.commands.push; | ||
|
||
import static com.google.common.collect.Sets.newTreeSet; | ||
import static org.apache.commons.io.FileUtils.listFiles; | ||
import static org.apache.commons.io.FilenameUtils.removeExtension; | ||
|
||
import java.io.File; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.zanata.client.commands.TransFileResolver; | ||
import org.zanata.client.commands.UnqualifiedSrcDocName; | ||
import org.zanata.client.config.LocaleList; | ||
import org.zanata.client.config.LocaleMapping; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.Lists; | ||
|
||
public class GettextPushStrategy extends AbstractGettextPushStrategy { | ||
private static final Logger log = LoggerFactory | ||
.getLogger(GettextPushStrategy.class); | ||
|
||
@Override | ||
List<LocaleMapping> findLocales() { | ||
List<LocaleMapping> findLocales(String srcDocName) { | ||
// find all .po basenames in this dir and subdirs | ||
final LocaleList localeList = getOpts().getLocaleMapList(); | ||
Collection<File> files = | ||
Collection<File> transFilesOnDisk = | ||
listFiles(getOpts().getTransDir(), new String[] { "po" }, true); | ||
Set<String> localeNames = newTreeSet(); | ||
for (File f : files) { | ||
String localeName = removeExtension(f.getName()); | ||
localeNames.add(localeName); | ||
|
||
final LocaleList localeListInConfig = getOpts().getLocaleMapList(); | ||
|
||
if (localeListInConfig == null || localeListInConfig.isEmpty()) { | ||
log.warn("No locale list in configuration (check zanata.xml)"); | ||
return Collections.emptyList(); | ||
} | ||
List<LocaleMapping> locales = Lists.newArrayList(); | ||
for (String localeName : localeNames) { | ||
LocaleMapping localLocale; | ||
if (localeList != null) { | ||
localLocale = localeList.findByLocalLocaleOrJavaLocale( | ||
localeName); | ||
if (localLocale == null) { | ||
log.warn( | ||
"Skipping locale {}; no locale entry found in zanata.xml", | ||
localeName); | ||
continue; | ||
} | ||
} else { | ||
localLocale = new LocaleMapping(localeName); | ||
} | ||
locales.add(localLocale); | ||
|
||
final UnqualifiedSrcDocName unqualifiedSrcDocName = | ||
UnqualifiedSrcDocName.from(srcDocName); | ||
List<File> transFilesDestinations = | ||
Lists.transform(localeListInConfig, | ||
new LocaleMappingToTransFile(unqualifiedSrcDocName, | ||
getOpts())); | ||
// we remove all the ones that WILL be mapped and treated as | ||
// translation files | ||
transFilesOnDisk.removeAll(transFilesDestinations); | ||
// for all remaining po files we give a warning | ||
for (File transFile : transFilesOnDisk) { | ||
log.warn( | ||
"Skipping file {}; no locale entry found in zanata.xml", | ||
transFile); | ||
} | ||
return locales; | ||
return localeListInConfig; | ||
} | ||
|
||
private static class LocaleMappingToTransFile implements | ||
Function<LocaleMapping, File> { | ||
private final UnqualifiedSrcDocName unqualifiedSrcDocName; | ||
private TransFileResolver transFileResolver; | ||
|
||
public LocaleMappingToTransFile( | ||
UnqualifiedSrcDocName unqualifiedSrcDocName, PushOptions opts) { | ||
this.unqualifiedSrcDocName = unqualifiedSrcDocName; | ||
transFileResolver = new TransFileResolver(opts); | ||
} | ||
|
||
@Override | ||
public File apply(LocaleMapping localeMapping) { | ||
return transFileResolver.getTransFile(unqualifiedSrcDocName, | ||
localeMapping); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters