Traducir un properties de manera semiautomatica

package net.prietopalacios.josemanuel.i18n.translate;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.junit.Test;

/**
* Permite coger la parte a traducir de un properties, posteriormente inserta el texto traducido en el properties
*/
public class InternacionalizaProperties {

	@Test
	public void cogePropertiesEnGallegoYcapturasSoloElTextoATraducir_MeLoPasasEnEsteFicheroDeSalida() throws IOException{
		File salida = new File("src/test/resources/salida.txt");
		FileInputStream fis = new FileInputStream("src/test/resources/lenguaje_gl_utf-8.txt");

		BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
		FileWriter fw = new FileWriter(salida.getAbsoluteFile());
		BufferedWriter bw = new BufferedWriter(fw);

		while (true) {
			String line = br.readLine();
			if(line == null) break;
			if(line.contains("=")){
				String[] equals = line.split("=");
				bw.write(equals[1] + "n");
			}
		}

		bw.close();
	}

	@Test
	public void leeElFicheroSalidaAnteriorYMeLoSeparasEnBloquesDe2500Caracteres() throws IOException{
		File salida = new File("src/test/resources/salida2.txt");
		FileInputStream fis = new FileInputStream("src/test/resources/salida.txt");

		BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
		FileWriter fw = new FileWriter(salida.getAbsoluteFile());
		BufferedWriter bw = new BufferedWriter(fw);

		String bloque = "";
		int cont = 0;
		int contBloques = 0;
		while (true) {
			String line = br.readLine();
			if(line == null) break;
			cont += line.length();
			if(cont > 2000){
				bw.write(bloque);
				bw.write("n");
				bw.write("n");
				bw.write("n");
				contBloques++;
				cont = 0;
				bloque = line + "n";
				cont += line.length();
			}else{
				bloque += line + "n";
			}
		}
		bw.write("n");
		bw.write("Han sido " + contBloques + " bloques.");
		bw.close();
	}
	
	@Test
	/**
	 * CUIDADO: el traductor de la Xunta hay cosas que no las entiende, como | `... o el codigo html
	 *  
	 * @throws IOException
	 */
	public void elTextoTraducidoInsertaloEnUnProperties() throws IOException{
		File salida = new File("src/test/resources/Language_gl.properties");
		FileWriter fw = new FileWriter(salida.getAbsoluteFile());
		BufferedWriter bw = new BufferedWriter(fw);
		
		FileInputStream fis = new FileInputStream("src/test/resources/lenguaje_gl_utf-8.txt");
		BufferedReader original = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
		FileInputStream fis2 = new FileInputStream("src/test/resources/textEnGalego.txt");
		BufferedReader traduccion = new BufferedReader(new InputStreamReader(fis2, "UTF-8"));
		
		while (true) {
			String lineaOriginal = original.readLine();
			if(lineaOriginal == null) break;
			if(lineaOriginal.contains("=")){
				String lineaTraducida = traduccion.readLine();
				String[] lineasOriginales = lineaOriginal.split("=");
				bw.write(lineasOriginales[0] + insertaTabComoEnOriginal(lineaOriginal) + "= ");
				if(lineasOriginales[1].contains(" <a id")){
					bw.write(lineasOriginales[1] + "n");
				}else{
					bw.write(lineaTraducida + "n");
				}
			}else{
				bw.write(lineaOriginal + "n");
			}
		}

		bw.close();
	}
	
	private String insertaTabComoEnOriginal(String lineaOriginal) {
		String xtab = "";
		for (int i = 0; i < cuentaTabuladores(lineaOriginal); i++) {
			xtab += "t";
		}
		return xtab;
	}

	public int cuentaTabuladores(String linea){
		int cont = 0;
		char[] array = linea.toCharArray();
		for (int i = 0; i < array.length; i++) {
			if(array[i] == '\' && array[i + 1] == 't'){
				cont++;
			}
		}	
		return cont;
	}
}
Traducir un properties de manera semiautomatica

Maven Properties

You can use Maven properties in a pom.xml file or in any resource that is being processed by the Maven Resource plugin’s filtering features.
A property is always surrounded by ${ and }. For example, to reference the ${project.version} property

project.* Maven Project Object Model (POM). You can use the project.* prefix to reference values in a Maven POM.
settings.* Maven Settings. You use the settings.* prefix to reference values from your Maven Settings in ~/.m2/settings.xml.
env.* Environment variables like PATH and M2_HOME can be referenced using the env.* prefix.
System Properties: Any property which can be retrieved from the System.getProperty() method can be referenced as a Maven property.

The ${project.*} actually resolved to a MavenProject object. From there, you can just use bean properties to get the value you need
${project.basedir}
${project.groupId}
${project.version}

project.name and project.description
The name and project description can often be useful properties to reference from documentation. Instead of having to worry that all of your site documents maintain the same short descriptions, you can just reference these properties.
project.build.*
If you are ever trying to reference output directories in Maven, you should never use a literal value like target/classes. Instead you should use property references to refer to these directories.
project.build.sourceDirectory
project.build.scriptSourceDirectory
project.build.testSourceDirectory
project.build.outputDirectory
project.build.testOutputDirectory
project.build.directory

project.baseUri
If you need a valid URI for your project’s base directory, you can use the ${project.baseUri} property. If your project is stored in the directory /tmp/simple, ${project.baseUri} will resolve to file:/private/tmp/simple/.

Built-in properties

${basedir} represents the directory containing pom.xml
${version} equivalent to ${project.version} (deprecated: ${pom.version})

Pom/Project properties

${project.build.directory} results in the path to your “target” directory, this is the same as ${pom.project.build.directory}
${project.build.outputDirectory} results in the path to your “target/classes” directory
${project.name}refers to the name of the project (deprecated: ${pom.name} ).
${project.version} refers to the version of the project (deprecated: or ${pom.version}).
${project.build.finalName} refers to the final name of the file created when the built project is packaged

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	...
	<build>
		<finalName>finalNameOfFile</finalName>
		...
	</build>		
</project>

Local user settings

${settings.localRepository} refers to the path of the user’s local repository

Environment variables

${env.M2_HOME} returns the Maven2 installation path.
${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
${java.home}../bin/java.exe

Java system properties

All Java System Properties defined by the JVM.

Custom properties in the POM

It’s not a good idea to use properties for artifact IDs. The ${project.file.parentFile.name} property cannot be resolved when using it as part of artifactId, however some properties do work (project.groupId for the artifactId seems to work).
However, this is not recommended. In fact, if you use any property for the artifact ID instead of a constant, you’ll get a warning when you build your project:

        <properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

${project.build.sourceEncoding}

Referencias:
books sonatype mvnref-book
MavenPropertiesGuide

Maven Properties