Permalink
Browse files

Initial commit, working application

  • Loading branch information...
karatemaccie committed Jul 8, 2014
0 parents commit 643c8b28204017a3152a4088c9aa5c740ae86e7d
Showing with 179 additions and 0 deletions.
  1. +12 −0 .classpath
  2. +22 −0 .gitattributes
  3. +52 −0 .gitignore
  4. +17 −0 .project
  5. +76 −0 src/nl/marcsollie/mactranslate/LocaleTranslate.java
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="libs/microsoft-translator-java-api-0.6.2-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="libs/commons-lang3-3.1.jar" sourcepath="libs/commons-lang3-3.1-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MacMassTranslate/libs/commons-lang3-3.1-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
@@ -0,0 +1,52 @@
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
/src/KEYS/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Icon must ends with two \r.
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Windows
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Locale_Translate</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,76 @@
package nl.marcsollie.mactranslate;
import java.io.*;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public class LocaleTranslate {
public static void main(String[] args) {
if(args.length < 4){
System.out.println("Usage: \"Input File\" \"Output File\" \"Begin tag\" \"End tag\"");
System.exit(0);
}
try{
/**Your Azure Datamarket ClientID and ClientSecret**/
//FIXME INPUT CLIENT ID
String clientId = "CLIENT-KEY";
//FIXME INPUT CLIENT SECRET
String clientSecret = "CLIENT-SECRET";
/**Set's the ID and Secret.**/
Translate.setClientId(clientId); Translate.setClientSecret(clientSecret);
/**Reads input file.**/
BufferedReader br = new BufferedReader(new FileReader(args[0]));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
/**Grabs the strings between the tags**/
String[] stringsoriginal = StringUtils.substringsBetween(everything, args[2], args[3]);
/**List where the translated string are put back in**/
List<String> translated = new ArrayList<String>();
//FIXME Change to Language.OUTPUTLANGUAGE
Language outlanguage = null;
int j = 0;
while(j < stringsoriginal.length){
System.out.println("Translating string #"+j);
/**Translate and add to the List**/
translated.add(Translate.execute(stringsoriginal[j], Language.AUTO_DETECT, outlanguage));
j++;
}
int i = 0;
String nieuw = everything;
/**Replace original occurence in file.**/
while(i < translated.size()){
nieuw = StringUtils.replaceOnce(nieuw, stringsoriginal[i], translated.get(i));
i++;
}
PrintWriter out = new PrintWriter(args[1]);
/**Outputs translated file**/
out.println(nieuw);
br.close();
out.close();
} catch(IOException e){
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 643c8b2

Please sign in to comment.