Skip to content

Commit

Permalink
Revert "Release Preparation"
Browse files Browse the repository at this point in the history
This reverts commit adfeab0.
  • Loading branch information
jason-fox committed Feb 5, 2024
1 parent 7891a76 commit a22971f
Show file tree
Hide file tree
Showing 136 changed files with 5,373 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/** linguist-vendored

build_dita2translate_template.xml linguist-language=Ant-Build-System
src/main/resources/fox/jason/translate/antlib.xml linguist-language=Ant-Build-System
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI
'on':
push:
branches:
- master
pull_request:
branches:
- master
jobs:
sonarcloud:
name: SonarCloud Scan
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
- name: Use Java 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- name: SonarCloud Scan
uses: jason-fox/sonarcloud-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_CLOUD_LOGIN: ${{ secrets.SONAR_CLOUD_LOGIN }}

unit-test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
- name: Run DITA-OT Unit Test
uses: jason-fox/dita-unit-test-action@master
with:
dita-ot-version: '4.1.2'
plugin: 'fox.jason.translate.xliff'
#env:
# COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: |
*.html
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
**/out/**
**/temp/**
**/tmp/**
build_dita2translate.xml

**/test/add-translations1/translate.xlf
**/test/approved-translations1/test.properties
**/test/add-translations2/translate.xlf
**/test/approved-translations2/test.properties

.scannerwork/

target/
classes/
lib/ant-*.jar
lib/ant-launcher-*.jar

*~
.fuse_hidden*
.directory
.Trash-*
.nfs*
*.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

80 changes: 80 additions & 0 deletions src/fox/jason/translate/tasks/BingParseTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* This file is part of the DITA-OT Translate Plug-in project.
* See the accompanying LICENSE file for applicable licenses.
*/

package fox.jason.translate.tasks;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

// Microsoft Translation. Copies text translated by Azure cloud services to a file
//

public class BingParseTask extends Task {

private String text;
private String outproperty;
private JSONParser parser;

/**
* Creates a new <code>BingParseTask</code> instance.
*/
public BingParseTask() {
super();
this.text = null;
this.outproperty = null;
this.parser = new JSONParser();
}

/**
* Method setText.
*
* @param text String
*/
public void setText(String text) {
this.text = text;
}

/**
* Method setOutproperty.
*
* @param outproperty String
*/
public void setOutproperty(String outproperty) {
this.outproperty = outproperty;
}

/**
* Method execute.
*
* @throws BuildException if something goes wrong
*/
@Override
public void execute() {
// @param text - The response from Microsoft Translate
// @param outproperty - The property to output to
if (this.text == null) {
throw new BuildException("You must supply a response from Microsoft Translate");
}
if (this.outproperty == null) {
throw new BuildException("You must supply a property to output to");
}

try {
JSONArray json = (JSONArray) this.parser
.parse(this.text);
JSONArray translations = (JSONArray) ((JSONObject) json.get(0)).get("translations");
String trans = (String) ((JSONObject) translations.get(0)).get("text");
trans = trans.replaceAll("\\\\\"", "\"");
trans = trans.replaceAll("class=\"notranslate\"", "translate=\"no\"");
getProject().setProperty(this.outproperty, trans);
} catch (ParseException e) {
throw new BuildException("Unable to translate JSON", e);
}
}
}
80 changes: 80 additions & 0 deletions src/fox/jason/translate/tasks/DeeplParseTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* This file is part of the DITA-OT Translate Plug-in project.
* See the accompanying LICENSE file for applicable licenses.
*/

package fox.jason.translate.tasks;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

// Watson Translation. Parses the response and extracts the translated text
//

public class DeeplParseTask extends Task {

private String text;
private String outproperty;
private JSONParser parser;

/**
* Creates a new <code>DeeplParseTask</code> instance.
*/
public DeeplParseTask() {
super();
this.text = null;
this.outproperty = null;
this.parser = new JSONParser();
}

/**
* Method setText.
*
* @param text String
*/
public void setText(String text) {
this.text = text;
}

/**
* Method setOutproperty.
*
* @param outproperty String
*/
public void setOutproperty(String outproperty) {
this.outproperty = outproperty;
}

/**
* Method execute.
*
* @throws BuildException if something goes wrong
*/
@Override
public void execute() {
// @param text - The response from Deepl
// @param outproperty - The property to output to
if (this.text == null) {
throw new BuildException("You must supply a response from Deepl");
}
if (this.outproperty == null) {
throw new BuildException("You must supply a property to output to");
}

try {
JSONObject json = (JSONObject) this.parser
.parse(this.text);
JSONArray translations = (JSONArray) json.get("translations");
String trans = (String) ((JSONObject) translations.get(0)).get("text");
trans = trans.replaceAll("\\\\\"", "\"");
getProject().setProperty(this.outproperty, trans);
} catch (ParseException e) {
throw new BuildException("Unable to translate JSON", e);
}

}
}
124 changes: 124 additions & 0 deletions src/fox/jason/translate/tasks/IterateFilesetTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* This file is part of the DITA-OT Pretty DITA Plug-in project.
* See the accompanying LICENSE file for applicable licenses.
*/

package fox.jason.translate.tasks;

import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.MacroInstance;
import org.apache.tools.ant.types.FileSet;

//
// Iterator function to run a given macro against a set of files
//

public class IterateFilesetTask extends Task {
/**
* Field filesets.
*/
private List<FileSet> filesets;
/**
* Field todir.
*/
private String macro;
/**
* Field todir.
*/
private String todir;

/**
* Field dir.
*/
private String dir;

/**
* Creates a new <code>IterateFilesetTask</code> instance.
*/
public IterateFilesetTask() {
super();
this.dir = null;
this.todir = null;
this.macro = null;
this.filesets = new ArrayList<>();
}

/**
* Method setDir.
*
* @param dir String
*/
public void setDir(String dir) {
this.dir = dir;
}

/**
* Method setTodir.
*
* @param todir String
*/
public void setTodir(String todir) {
this.todir = todir;
}

/**
* Method setMacro.
*
* @param macro String
*/
public void setMacro(String macro) {
this.macro = macro;
}

/**
* @param set FileSet
*/
public void addFileset(FileSet set) {
this.filesets.add(set);
}

/**
* Method execute.
*
* @throws BuildException if something goes wrong
*/
@Override
public void execute() {
// @param toDir - The output location of the files
// @param dir - The location of the files to process
// @param macro - A macro to run.
// @param fileset - A set of files
if (this.dir == null) {
throw new BuildException("You must supply a source directory");
}
if (this.macro == null) {
throw new BuildException("You must supply a macro");
}
if (filesets.isEmpty()) {
throw new BuildException("You must supply a set of files");
}

for (FileSet fileset : this.filesets) {
DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
scanner.scan();

for (String file : scanner.getIncludedFiles()) {
MacroInstance task = (MacroInstance) getProject()
.createTask(this.macro);
try {
task.setDynamicAttribute("file", this.dir + "/" + file);
if (this.todir != null){
task.setDynamicAttribute("toDir", this.todir);
}
task.execute();
} catch (Exception err) {
throw new BuildException(err);
}
}
}
}
}
Loading

0 comments on commit a22971f

Please sign in to comment.