Revision 38679
tags/v2_0_0_Build_2050/libraries/libInternationalization/.cvsignore | ||
---|---|---|
1 |
bin |
|
2 |
bin-test |
|
3 |
bin-utils |
|
4 |
doc |
|
0 | 5 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/TestProperties.java | ||
---|---|---|
1 |
package org.gvsig.i18n.utils; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.FileNotFoundException; |
|
6 |
import java.io.FileOutputStream; |
|
7 |
import java.io.IOException; |
|
8 |
import java.io.InputStream; |
|
9 |
import java.io.OutputStream; |
|
10 |
|
|
11 |
import junit.framework.TestCase; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author cesar |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class TestProperties extends TestCase { |
|
18 |
static final String fileName = "TestProperties-file"; |
|
19 |
InputStream is; |
|
20 |
OutputStream os; |
|
21 |
|
|
22 |
public void initOutputStream() { |
|
23 |
try { |
|
24 |
os = new FileOutputStream(fileName); |
|
25 |
} catch (FileNotFoundException e) { |
|
26 |
TestCase.fail(e.getLocalizedMessage()); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
public void discardOutputStream() { |
|
31 |
try { |
|
32 |
os.close(); |
|
33 |
File file = new File(fileName); |
|
34 |
file.delete(); |
|
35 |
} catch (IOException e) { |
|
36 |
TestCase.fail(e.getLocalizedMessage()); |
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
public void initInputStream() { |
|
41 |
try { |
|
42 |
is = new FileInputStream(fileName); |
|
43 |
} catch (FileNotFoundException e) { |
|
44 |
TestCase.fail(e.getLocalizedMessage()); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public void discardInputStream() { |
|
49 |
try { |
|
50 |
is.close(); |
|
51 |
} catch (IOException e) { |
|
52 |
TestCase.fail(e.getLocalizedMessage()); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public void testOrderedPropertiesBasic() { |
|
57 |
// write file |
|
58 |
OrderedProperties props1 = new OrderedProperties(); |
|
59 |
props1.setProperty("prueba", "hola"); |
|
60 |
props1.setProperty("prueba2", "holas"); |
|
61 |
props1.setProperty("abrir", "cerrar"); |
|
62 |
props1.setProperty("puerta", "hembrilla"); |
|
63 |
props1.setProperty("12libros", "quijote"); |
|
64 |
props1.setProperty("ca?uto", "\u20acuropeo"); |
|
65 |
props1.setProperty("confli=cto", "amigo"); |
|
66 |
props1.setProperty(" confli = :cto mayor ", " peque?o conflicto"); |
|
67 |
initOutputStream(); |
|
68 |
try { |
|
69 |
props1.store(os, "header"); |
|
70 |
} catch (IOException e) { |
|
71 |
TestCase.fail(e.getLocalizedMessage()); |
|
72 |
} |
|
73 |
|
|
74 |
// read file |
|
75 |
OrderedProperties props2 = new OrderedProperties(); |
|
76 |
initInputStream(); |
|
77 |
try { |
|
78 |
props2.load(is); |
|
79 |
} catch (IOException e) { |
|
80 |
TestCase.fail(e.getLocalizedMessage()); |
|
81 |
} |
|
82 |
TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto")); |
|
83 |
TestCase.assertEquals("amigo", props2.getProperty("confli=cto")); |
|
84 |
TestCase.assertEquals(" peque?o conflicto", props2.getProperty(" confli = :cto mayor ")); |
|
85 |
TestCase.assertEquals("hola", props2.getProperty("prueba")); |
|
86 |
TestCase.assertEquals("holas", props2.getProperty("prueba2")); |
|
87 |
TestCase.assertEquals("cerrar", props2.getProperty("abrir")); |
|
88 |
TestCase.assertEquals("hembrilla", props2.getProperty("puerta")); |
|
89 |
TestCase.assertEquals("quijote", props2.getProperty("12libros")); |
|
90 |
discardInputStream(); |
|
91 |
discardOutputStream(); |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
public void testOrderedProperties() { |
|
96 |
// write file |
|
97 |
OrderedProperties props1 = new OrderedProperties(); |
|
98 |
props1.setProperty("prueba", "hola"); |
|
99 |
props1.setProperty("prueba2", "holas"); |
|
100 |
props1.setProperty("ca?uto", "\u20acuropeo"); |
|
101 |
props1.setProperty("confli=cto", "amigo"); |
|
102 |
props1.setProperty(" conflis = :cto mayor ", " peque?o conflicto"); |
|
103 |
props1.setProperty("abrir", "cerrar"); |
|
104 |
props1.setProperty("puerta", "hembrilla"); |
|
105 |
props1.setProperty("12libros", "quijote"); |
|
106 |
initOutputStream(); |
|
107 |
try { |
|
108 |
props1.store(os, "header", "8859_15"); |
|
109 |
} catch (IOException e) { |
|
110 |
TestCase.fail(e.getLocalizedMessage()); |
|
111 |
} |
|
112 |
|
|
113 |
// read file |
|
114 |
OrderedProperties props2 = new OrderedProperties(); |
|
115 |
initInputStream(); |
|
116 |
try { |
|
117 |
props2.load(is, "8859_15"); |
|
118 |
} catch (IOException e) { |
|
119 |
TestCase.fail(e.getLocalizedMessage()); |
|
120 |
} |
|
121 |
// estos deber?an salir igual |
|
122 |
TestCase.assertEquals("hola", props2.getProperty("prueba")); |
|
123 |
TestCase.assertEquals("holas", props2.getProperty("prueba2")); |
|
124 |
TestCase.assertEquals("cerrar", props2.getProperty("abrir")); |
|
125 |
TestCase.assertEquals("hembrilla", props2.getProperty("puerta")); |
|
126 |
TestCase.assertEquals("quijote", props2.getProperty("12libros")); |
|
127 |
// con estos en cambio no obtenemos los mismos valores que escribimos anteriormente. Es normal, porque incluimos |
|
128 |
// caracteres especiales como ":" y "=". Para manejarlos correctamente necesitamos usas los m?todos load/store |
|
129 |
// sin encoding, los cuales s? escapan los caracteres especiales |
|
130 |
TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto")); |
|
131 |
TestCase.assertEquals("cto=amigo", props2.getProperty("confli")); |
|
132 |
TestCase.assertEquals(":cto mayor = peque?o conflicto", props2.getProperty("conflis")); |
|
133 |
|
|
134 |
discardInputStream(); |
|
135 |
discardOutputStream(); |
|
136 |
|
|
137 |
// write file |
|
138 |
props1 = new OrderedProperties(); |
|
139 |
props1.setProperty("Prueba", "hola"); |
|
140 |
props1.setProperty("prueba2", "holas"); |
|
141 |
props1.setProperty("ca?uto", "\u20acuropeo"); |
|
142 |
props1.setProperty("confli=cto", "amigo"); |
|
143 |
props1.setProperty(" conflis = :cto mayor ", " peque?o conflicto"); |
|
144 |
props1.setProperty("abrir", "cerrar"); |
|
145 |
props1.setProperty("puerta", "hembrilla"); |
|
146 |
props1.setProperty("12libros", "quijote"); |
|
147 |
initOutputStream(); |
|
148 |
try { |
|
149 |
props1.store(os, "header", "UTF8"); |
|
150 |
} catch (IOException e) { |
|
151 |
TestCase.fail(e.getLocalizedMessage()); |
|
152 |
} |
|
153 |
|
|
154 |
// read file |
|
155 |
props2 = new OrderedProperties(); |
|
156 |
initInputStream(); |
|
157 |
try { |
|
158 |
props2.load(is, "UTF8"); |
|
159 |
} catch (IOException e) { |
|
160 |
TestCase.fail(e.getLocalizedMessage()); |
|
161 |
} |
|
162 |
// estos deber?an salir igual |
|
163 |
TestCase.assertEquals("hola", props2.getProperty("Prueba")); |
|
164 |
TestCase.assertEquals("holas", props2.getProperty("prueba2")); |
|
165 |
TestCase.assertEquals("cerrar", props2.getProperty("abrir")); |
|
166 |
TestCase.assertEquals("hembrilla", props2.getProperty("puerta")); |
|
167 |
TestCase.assertEquals("quijote", props2.getProperty("12libros")); |
|
168 |
// con estos en cambio no obtenemos los mismos valores que escribimos anteriormente. Es normal, porque incluimos |
|
169 |
// caracteres especiales como ":" y "=". Para manejarlos correctamente necesitamos usas los m?todos load/store |
|
170 |
// sin encoding, los cuales s? escapan los caracteres especiales |
|
171 |
TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto")); |
|
172 |
TestCase.assertEquals("cto=amigo", props2.getProperty("confli")); |
|
173 |
TestCase.assertEquals(":cto mayor = peque?o conflicto", props2.getProperty("conflis")); |
|
174 |
|
|
175 |
discardInputStream(); |
|
176 |
discardOutputStream(); |
|
177 |
} |
|
178 |
|
|
179 |
} |
|
0 | 180 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/TestUtils.java | ||
---|---|---|
1 |
package org.gvsig.i18n.utils; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
import junit.framework.TestCase; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author cesar |
|
10 |
* |
|
11 |
*/ |
|
12 |
public class TestUtils extends TestCase { |
|
13 |
|
|
14 |
public ConfigOptions loadConfig() { |
|
15 |
ConfigOptions config = new ConfigOptions(); |
|
16 |
config.setConfigFile("src-test"+File.separator+"org"+File.separator+"gvsig"+File.separator+"i18n"+File.separator+"utils"+File.separator+"config.xml"); |
|
17 |
config.load(); |
|
18 |
return config; |
|
19 |
} |
|
20 |
|
|
21 |
public void testConfigOptions() { |
|
22 |
ConfigOptions config = loadConfig(); |
|
23 |
|
|
24 |
String databaseDir=null, basedir=null; |
|
25 |
try { |
|
26 |
databaseDir = new File("test-data/database").getCanonicalPath(); |
|
27 |
basedir = new File("test-data").getCanonicalPath(); |
|
28 |
} catch (IOException e) { |
|
29 |
// TODO Auto-generated catch block |
|
30 |
e.printStackTrace(); |
|
31 |
} |
|
32 |
|
|
33 |
// the values of the projects. They are pairs (dir, basename). |
|
34 |
String projectValues[]={"src/appgvSIG", "otro", "sources", "src/_fwAndami", "text", "sources"}; |
|
35 |
for (int i=0; i<projectValues.length; i=i+3) { |
|
36 |
try { |
|
37 |
// set the canonical path |
|
38 |
projectValues[i]= new File(basedir+File.separator+projectValues[i]).getCanonicalPath(); |
|
39 |
} catch (IOException e) { |
|
40 |
// TODO Auto-generated catch block |
|
41 |
e.printStackTrace(); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
TestCase.assertEquals(databaseDir, config.databaseDir); |
|
46 |
TestCase.assertEquals(basedir, config.defaultBaseDir); |
|
47 |
TestCase.assertEquals("text", config.defaultBaseName); |
|
48 |
|
|
49 |
String languages = config.languages[0]; |
|
50 |
for (int i=1; i<config.languages.length; i++) { |
|
51 |
languages=languages+";"+config.languages[i]; |
|
52 |
} |
|
53 |
TestCase.assertEquals("ca;cs;de;en;es;eu;fr;gl;it;pt", languages); |
|
54 |
|
|
55 |
for (int i=0; i<config.projects.size(); i=i+3) { |
|
56 |
Project project = (Project) config.projects.get(i); |
|
57 |
TestCase.assertEquals(projectValues[i], project.dir); |
|
58 |
TestCase.assertEquals(projectValues[i+1], project.basename); |
|
59 |
TestCase.assertEquals(projectValues[i+2], project.sourceKeys); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
public void testTranslationDatabase() { |
|
64 |
ConfigOptions config = loadConfig(); |
|
65 |
TranslationDatabase database = new TranslationDatabase(config); |
|
66 |
database.load(); |
|
67 |
TestCase.assertEquals("A?adir Capa" , database.getTranslation("es", "Anadir_Capa")); |
|
68 |
TestCase.assertEquals("Add Layer" , database.getTranslation("en", "Anadir_Capa")); |
|
69 |
TestCase.assertEquals("Afegir Capa" , database.getTranslation("ca", "Anadir_Capa")); |
|
70 |
TestCase.assertEquals("Layer hinzuf?gen" , database.getTranslation("de", "Anadir_Capa")); |
|
71 |
TestCase.assertEquals("Ayuda" , database.getTranslation("es", "Ayuda")); |
|
72 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
73 |
|
|
74 |
// add a translation |
|
75 |
database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe"); |
|
76 |
// is it present now? |
|
77 |
TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
78 |
|
|
79 |
// remove the translation |
|
80 |
database.removeTranslation("es", "test_case.clave_que_no_existe"); |
|
81 |
// was really removed? |
|
82 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
83 |
|
|
84 |
// add the translation again |
|
85 |
database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe"); |
|
86 |
// save to disk |
|
87 |
database.save(); |
|
88 |
// load from disk |
|
89 |
database.load(); |
|
90 |
// is the translation still there? |
|
91 |
TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
92 |
|
|
93 |
// remove the translation again and save to disk |
|
94 |
database.removeTranslation("es", "test_case.clave_que_no_existe"); |
|
95 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
|
96 |
TestCase.assertEquals("", database.getTranslation("es", "prueba")); |
|
97 |
database.save(); |
|
98 |
} |
|
99 |
|
|
100 |
public void testKeys() { |
|
101 |
ConfigOptions config = loadConfig(); |
|
102 |
Keys keys = new Keys(config); |
|
103 |
keys.load(); |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
0 | 107 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<config> |
|
3 |
<!-- Aquí especificamos algunas variables de configuración --> |
|
4 |
<!-- En este fichero se muestran todas las opciones posibles, en sus valores por defecto --> |
|
5 |
|
|
6 |
<!-- Nombre base por defecto de los ficheros con las traducciones. En nuestro caso suele ser "text", |
|
7 |
de forma que los ficheros toman nombres como "text.properties", "text_en.properties". Nótese |
|
8 |
que sólo es el nombre por defecto. Cada proyecto puede especificar un baseName distinto --> |
|
9 |
<variable name="basename" value="text" /> |
|
10 |
|
|
11 |
<!-- Directorio base. Las rutas relativas especificadas en otras variables (databaseDir, directorios |
|
12 |
de proyecto) tomarán este directorio como directorio base. Por defecto es el directorio |
|
13 |
desde el que se llama a la aplicación --> |
|
14 |
<variable name="basedir" value="test-data" /> |
|
15 |
|
|
16 |
<!-- Lista de idiomas que se tendrán en cuenta --> |
|
17 |
<variable name="languages" value="ca;cs;de;en;es;eu;fr;gl;it;pt" /> |
|
18 |
|
|
19 |
<!-- El directorio que contendrá la base de datos de traducciones por idioma. Por defecto es el |
|
20 |
directorio "database", relativo al directorio especificado en la variable "basedir". --> |
|
21 |
<variable name="databaseDir" value="database" /> |
|
22 |
|
|
23 |
<!-- El directorio por defecto que contendrá los property files que almacenan las claves de cada |
|
24 |
proyecto". Esto se usa en los proyectos que no especifican un atributo "propertyDir". Si el |
|
25 |
directorio no es absoluto, entonces es relativo al directorio de cada proyecto. --> |
|
26 |
<variable name="defaultPropertyDir" value="config" /> |
|
27 |
|
|
28 |
<variable name="sourceKeys" value="sources" /> |
|
29 |
</config> |
|
30 |
<projects> |
|
31 |
<!-- Los proyectos que se van a leer. Es necesario especificar un directorio (relativo o absoluto), |
|
32 |
y opcionalmente se puede incluir un atributo "basename" para especificar un nombre base |
|
33 |
distinto del nombre base por defecto --> |
|
34 |
<!-- The projects which are going to be read. An absolute or relative directory name must be specified, |
|
35 |
in which the property files are located. An optional "basename" attribute is also accepted, |
|
36 |
to override the default basename --> |
|
37 |
<project dir="src/appgvSIG" basename="otro" sourceKeys="sources" propertyDir="config" /> |
|
38 |
<project dir="src/_fwAndami" /> |
|
39 |
</projects> |
|
0 | 40 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/AllTests.java | ||
---|---|---|
1 |
package org.gvsig.i18n; |
|
2 |
|
|
3 |
import junit.framework.Test; |
|
4 |
import junit.framework.TestSuite; |
|
5 |
|
|
6 |
public class AllTests { |
|
7 |
|
|
8 |
public static Test suite() { |
|
9 |
TestSuite suite = new TestSuite("Test for org.gvsig.i18n"); |
|
10 |
//$JUnit-BEGIN$ |
|
11 |
suite.addTestSuite(TestMessages.class); |
|
12 |
//$JUnit-END$ |
|
13 |
return suite; |
|
14 |
} |
|
15 |
|
|
16 |
} |
|
0 | 17 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset1/text.properties | ||
---|---|---|
1 |
#text.properties |
|
2 |
aceptar=Aceptar |
|
3 |
cancelar=Cancelar |
|
4 |
Cascada=Cascada |
|
5 |
cascada_enable=Debe haber al menos una ventana abierta |
|
0 | 6 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset1/text_en.properties | ||
---|---|---|
1 |
#text_en.properties |
|
2 |
aceptar=OK |
|
3 |
cancelar=Cancel |
|
4 |
Cascada=Cascade |
|
5 |
ventana=Window |
|
6 |
otro=other |
|
0 | 7 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset1/text_fr.properties | ||
---|---|---|
1 |
#text_fr.properties |
|
2 |
aceptar=Accepter |
|
3 |
Cascada=Cascade |
|
4 |
Configurar=Configurer |
|
0 | 5 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/TestMessages.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package org.gvsig.i18n; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.net.MalformedURLException; |
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.Locale; |
|
10 |
|
|
11 |
import junit.framework.TestCase; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author cesar |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class TestMessages extends TestCase { |
|
18 |
|
|
19 |
/* |
|
20 |
* @see TestCase#setUp() |
|
21 |
*/ |
|
22 |
protected void setUp() throws Exception { |
|
23 |
super.setUp(); |
|
24 |
} |
|
25 |
|
|
26 |
/* |
|
27 |
* @see TestCase#tearDown() |
|
28 |
*/ |
|
29 |
protected void tearDown() throws Exception { |
|
30 |
super.tearDown(); |
|
31 |
} |
|
32 |
|
|
33 |
public void testSetPreferredLocales() { |
|
34 |
setPreferredLocales(); |
|
35 |
removeLocales(); |
|
36 |
} |
|
37 |
|
|
38 |
private void setPreferredLocales() { |
|
39 |
ArrayList preferred = new ArrayList(); |
|
40 |
preferred.add(new Locale("en")); |
|
41 |
preferred.add(new Locale("es")); |
|
42 |
Messages.setPreferredLocales(preferred); |
|
43 |
ArrayList resultPref = Messages.getPreferredLocales(); |
|
44 |
|
|
45 |
TestCase.assertEquals(resultPref.size(), 2); |
|
46 |
|
|
47 |
Locale lang1 = (Locale) resultPref.get(0); |
|
48 |
TestCase.assertEquals(lang1.getLanguage(), "en"); |
|
49 |
Locale lang2 = (Locale) resultPref.get(1); |
|
50 |
TestCase.assertEquals(lang2.getLanguage(), "es"); |
|
51 |
} |
|
52 |
|
|
53 |
private void removeLocales() { |
|
54 |
Locale lang1 = new Locale("en"); |
|
55 |
Locale lang2 = new Locale("es"); |
|
56 |
ArrayList resultPref = Messages.getPreferredLocales(); |
|
57 |
Messages.removeLocale(lang1); |
|
58 |
TestCase.assertEquals(resultPref.size(), 1); |
|
59 |
Messages.removeLocale(lang2); |
|
60 |
TestCase.assertEquals(resultPref.size(), 0); |
|
61 |
} |
|
62 |
|
|
63 |
public void testAddResourceFamily() { |
|
64 |
setPreferredLocales(); |
|
65 |
//this.getClass().getClassLoader().getResource("text_en.properties"); |
|
66 |
|
|
67 |
try { |
|
68 |
Messages.addResourceFamily("text", new File("src-test/org/gvsig/i18n/dataset1/")); |
|
69 |
} catch (MalformedURLException e) { |
|
70 |
TestCase.fail("Fichero de recursos no encontrado"); |
|
71 |
} |
|
72 |
TestCase.assertEquals(5, Messages.size(new Locale("en"))); |
|
73 |
TestCase.assertEquals(4,Messages.size(new Locale("es"))); |
|
74 |
TestCase.assertEquals(0,Messages.size(new Locale("fr"))); |
|
75 |
|
|
76 |
TestCase.assertEquals("OK", Messages.getText("aceptar")); |
|
77 |
TestCase.assertEquals("Cancel", Messages.getText("cancelar")); |
|
78 |
TestCase.assertEquals("Cascade", Messages.getText("Cascada")); |
|
79 |
TestCase.assertEquals("Window", Messages.getText("ventana")); |
|
80 |
TestCase.assertEquals("Debe haber al menos una ventana abierta", Messages.getText("cascada_enable")); |
|
81 |
TestCase.assertEquals("Configurar", Messages.getText("Configurar")); |
|
82 |
TestCase.assertEquals(null, Messages.getText("Configurar", false)); |
|
83 |
|
|
84 |
// load another file now |
|
85 |
try { |
|
86 |
Messages.addResourceFamily("text", new File( |
|
87 |
"src-test/org/gvsig/i18n/dataset2/")); |
|
88 |
} catch (MalformedURLException e) { |
|
89 |
TestCase.fail("Fichero de recursos no encontrado"); |
|
90 |
} |
|
91 |
// check that the right amount of translations was loaded |
|
92 |
TestCase.assertEquals(7, Messages.size(new Locale("en"))); |
|
93 |
TestCase.assertEquals(6, Messages.size(new Locale("es"))); |
|
94 |
TestCase.assertEquals(0, Messages.size(new Locale("fr"))); |
|
95 |
|
|
96 |
// test that keys didn't get overwritten by the new files |
|
97 |
// (only new keys should have been added for each language) |
|
98 |
TestCase.assertEquals("OK", Messages.getText("aceptar")); |
|
99 |
TestCase.assertEquals("Cancel", Messages.getText("cancelar")); |
|
100 |
TestCase.assertEquals("Cascade", Messages.getText("Cascada")); |
|
101 |
// check the new keys |
|
102 |
TestCase.assertEquals("At least one window should be open", Messages.getText("cascada_enable")); |
|
103 |
TestCase.assertEquals("Insert first corner point", Messages.getText("insert_first_point_corner")); |
|
104 |
TestCase.assertEquals("Capa exportada", Messages.getText("capa_exportada")); |
|
105 |
TestCase.assertEquals("Circunscrito", Messages.getText("circumscribed")); |
|
106 |
|
|
107 |
Messages.removeResources(); |
|
108 |
TestCase.assertEquals(0, Messages.size(new Locale("en"))); |
|
109 |
TestCase.assertEquals(0, Messages.size(new Locale("es"))); |
|
110 |
TestCase.assertEquals(0, Messages.size(new Locale("fr"))); |
|
111 |
|
|
112 |
removeLocales(); |
|
113 |
} |
|
114 |
} |
|
0 | 115 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset2/text.properties | ||
---|---|---|
1 |
#text.properties |
|
2 |
aceptar=baceptar |
|
3 |
cancelar=amancebar |
|
4 |
capa_exportada=Capa exportada |
|
5 |
circumscribed=Circunscrito |
|
0 | 6 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset2/text_en.properties | ||
---|---|---|
1 |
#text_en.properties |
|
2 |
insert_first_point_corner=Insert first corner point |
|
3 |
cascada_enable=At least one window should be open |
|
4 |
cancelar=arancelar |
|
0 | 5 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset2/text_fr.properties | ||
---|---|---|
1 |
#text_fr.properties |
|
2 |
aceptar=Accepter |
|
3 |
Cascada=Cascade |
|
4 |
Configurar=Configurer |
|
0 | 5 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_it.properties | ||
---|---|---|
1 |
#Translations for language [it] |
|
2 |
#Tue Nov 07 12:30:01 CET 2006 |
|
3 |
aceptar=Accetta |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas= |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase= |
|
7 |
No_se_encontro_la_traduccion_para=Non si \u00e9 incontrata la traduzione per |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text.properties | ||
---|---|---|
1 |
#Translations for language [es] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Aceptar |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas=Las traducciones no pudieron ser cargadas |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=No hay lista de idiomas preferidos. Quiza olvido inicializar la clase |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=No hay lista de idiomas preferidos. Quiz\u00e1 olvid\u00f3 inicializar la clase. |
|
7 |
No_se_encontro_la_traduccion_para=No se encontr\u00f3 la traducci\u00f3n para |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_en.properties | ||
---|---|---|
1 |
#Translations for language [en] |
|
2 |
#Wed Nov 08 12:31:46 CET 2006 |
|
3 |
=\=\=\=\=\=\= |
|
4 |
<<<<<<<=text_en.properties |
|
5 |
>>>>>>>=1.6 |
|
6 |
aceptar=Accept |
|
7 |
Las_traducciones_no_pudieron_ser_cargadas=Translations couldn't be loaded |
|
8 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=There is no list of favorite languages probably you forgot initialice the class |
|
9 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=There is not preferred languages list. Maybe the Messages class was not initiated |
|
10 |
No_se_encontro_la_traduccion_para=Cannot find translation for |
|
0 | 11 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_gl.properties | ||
---|---|---|
1 |
#Translations for language [gl] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Aceptar |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas=As traducci\u00f3ns non se puideron cargar |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=Non se atopou a lista de idiomas preferidos.Quiz\u00e1s non se lembrou de inicializar a clase |
|
7 |
No_se_encontro_la_traduccion_para=Non se atopou a traducci\u00f3n para |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_ca.properties | ||
---|---|---|
1 |
#Translations for language [ca] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Acceptar |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas=Les traduccions no s'han pogut carregar |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=No s'ha trobat la llista d'idiomes preferits. Potser ha oblidat inicialitzar la classe |
|
7 |
No_se_encontro_la_traduccion_para=No s'ha trobat la traducci\u00f3 per a |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_pt.properties | ||
---|---|---|
1 |
#Translations for language [pt] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Aceitar |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas= |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase= |
|
7 |
No_se_encontro_la_traduccion_para=N\u00e3o se encontrou a tradu\u00e7\u00e3o de |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_cs.properties | ||
---|---|---|
1 |
#Translations for language [cs] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Budi\u017e |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas= |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase= |
|
7 |
No_se_encontro_la_traduccion_para=Nelze nal\u00e9zt p\u0159eklad pro |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_fr.properties | ||
---|---|---|
1 |
#Translations for language [fr] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Accepter |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas=Les traductions ne peuvent pas \u00eatre charg\u00e9es. |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=Impossible de trouver la liste des langues pr\u00e9f\u00e9r\u00e9es. Vous avez peut-\u00eatre oubli\u00e9 d'installer la classe. |
|
7 |
No_se_encontro_la_traduccion_para=Impossible de trouver les traductions pour |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_de.properties | ||
---|---|---|
1 |
#Translations for language [de] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=OK |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas= |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase= |
|
7 |
No_se_encontro_la_traduccion_para=Konnte \u00dcbersetzung nicht finden f\u00fcr\: |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/config/text_eu.properties | ||
---|---|---|
1 |
#Translations for language [eu] |
|
2 |
#Mon Oct 30 09:38:21 CET 2006 |
|
3 |
aceptar=Ados |
|
4 |
Las_traducciones_no_pudieron_ser_cargadas=Itzulpenak ezin izan dira kargatu |
|
5 |
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase= |
|
6 |
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=\=Ez da hobetsitako hizkuntzen zerrenda aurkitu. Agian klasea hasieratzea ahaztu zaizu |
|
7 |
No_se_encontro_la_traduccion_para=Ez da itzulpenik aurkitu honetarako\: |
|
0 | 8 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-utils/org/gvsig/i18n/utils/UpdateTrans.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
|
|
43 |
/** |
|
44 |
* |
|
45 |
*/ |
|
46 |
package org.gvsig.i18n.utils; |
|
47 |
|
|
48 |
import java.io.BufferedWriter; |
|
49 |
import java.io.File; |
|
50 |
import java.io.FileNotFoundException; |
|
51 |
import java.io.FileOutputStream; |
|
52 |
import java.io.IOException; |
|
53 |
import java.io.OutputStreamWriter; |
|
54 |
import java.io.UnsupportedEncodingException; |
|
55 |
import java.util.ArrayList; |
|
56 |
import java.util.HashMap; |
|
57 |
import java.util.Iterator; |
|
58 |
import java.util.TreeMap; |
|
59 |
|
|
60 |
/** |
|
61 |
* @author cesar |
|
62 |
* |
|
63 |
*/ |
|
64 |
public class UpdateTrans { |
|
65 |
// The filename which stores the configuration (may be overriden by the command line parameter) |
|
66 |
private String configFileName = "config.xml"; |
|
67 |
|
|
68 |
// Object to load and store the config options |
|
69 |
private ConfigOptions config; |
|
70 |
|
|
71 |
private TranslationDatabase database; |
|
72 |
|
|
73 |
/** |
|
74 |
* @param args |
|
75 |
*/ |
|
76 |
public static void main(String[] args) { |
|
77 |
UpdateTrans process = new UpdateTrans(); |
|
78 |
|
|
79 |
// load command line parameters |
|
80 |
if (!process.readParameters(args)) { |
|
81 |
usage(); |
|
82 |
System.exit(-1); |
|
83 |
} |
|
84 |
|
|
85 |
// transfer control to the program's main loop |
|
86 |
process.start(); |
|
87 |
} |
|
88 |
|
|
89 |
private void start() { |
|
90 |
// load config options from the config file |
|
91 |
if (!loadConfig()) { |
|
92 |
System.out.println("Error leyendo el fichero de configuraci?n."); |
|
93 |
usage(); |
|
94 |
System.exit(-1); |
|
95 |
} |
|
96 |
|
|
97 |
loadKeys(); |
|
98 |
loadDataBase(); |
|
99 |
|
|
100 |
updateDB(); |
|
101 |
} |
|
102 |
|
|
103 |
private void updateDB(){ |
|
104 |
String lang, auxLang; |
|
105 |
String key, value, dbValue; |
|
106 |
|
|
107 |
HashMap newKeys = detectNewKeys(); |
|
108 |
TreeMap newKeysDict; |
|
109 |
HashMap removedKeys = new HashMap(); |
|
110 |
|
|
111 |
ArrayList removedKeysDict; |
|
112 |
|
|
113 |
/** |
|
114 |
* Process the new or changed keys |
|
115 |
*/ |
|
116 |
for (int i=0; i<config.languages.length; i++) { |
|
117 |
lang = config.languages[i]; |
|
118 |
File langDir = new File(config.outputDir+File.separator+lang); |
|
119 |
langDir.mkdirs(); |
|
120 |
|
|
121 |
// process the keys |
|
122 |
newKeysDict = (TreeMap) newKeys.get(lang); |
|
123 |
removedKeysDict = new ArrayList(); |
|
124 |
removedKeys.put(lang, removedKeysDict); |
|
125 |
Iterator newKeysIterator = newKeysDict.keySet().iterator(); |
|
126 |
while (newKeysIterator.hasNext()) { |
|
127 |
int numValues=0; |
|
128 |
value = null; |
|
129 |
key = (String) newKeysIterator.next(); |
|
130 |
|
|
131 |
dbValue = database.getTranslation(lang, key); |
|
132 |
ArrayList newKeyList = (ArrayList) newKeysDict.get(key); |
|
133 |
String[] newKey; |
|
134 |
boolean equal=true; |
|
135 |
for (int j=0; j<newKeyList.size(); j++) { |
|
136 |
newKey = (String[]) newKeyList.get(j); |
|
137 |
if (!newKey[0].equals("")) { |
|
138 |
if (dbValue!=null && !dbValue.equals(newKey[0])) |
|
139 |
equal = false; |
|
140 |
if (numValues==0) { //if there are several non-empty values, take the first one |
|
141 |
value = newKey[0]; |
|
142 |
} |
|
143 |
else if (!value.equals(newKey[0])) { |
|
144 |
equal=false; |
|
145 |
} |
|
146 |
numValues++; |
|
147 |
} |
|
148 |
} |
|
149 |
if (equal==false) { |
|
150 |
System.err.println("\nAtenci?n -- La clave '"+key+"' tiene diferentes valores para el idioma " + lang + "."); |
|
151 |
System.err.println("Valor en base de datos: "+key+"="+dbValue); |
|
152 |
for (int j=0; j<newKeyList.size(); j++) { |
|
153 |
newKey = (String[]) newKeyList.get(j); |
|
154 |
System.err.println(newKey[1] + " -- " + key + "=" + newKey[0]); |
|
155 |
} |
|
156 |
} |
|
157 |
if (value!=null && !value.equals("")) { // the translation has a value |
|
158 |
if (dbValue==null) { |
|
159 |
// new translation |
|
160 |
database.setTranslation(lang, key, value); |
|
161 |
// it has been added to database, it isn't new anymore |
|
162 |
// we add the key to the list of keys to remove. We don't remove it now because then there is troubles with the iterator |
|
163 |
removedKeysDict.add(key); |
|
164 |
} |
|
165 |
else if (!dbValue.equals("")) { |
|
166 |
// if dbValue contains a translation, it isn't a new translation |
|
167 |
removedKeysDict.add(key); |
|
168 |
} |
|
169 |
/* |
|
170 |
* else { // if dbValue.equals(""), it means that the key has been changed, and it must be sent for translation |
|
171 |
* //It should not be added to the database with the value from the property file, as it is not valid anymore. |
|
172 |
* |
|
173 |
* } |
|
174 |
*/ |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
// remove |
|
180 |
for (int i=0; i<config.languages.length; i++) { |
|
181 |
lang = config.languages[i]; |
|
182 |
removedKeysDict = (ArrayList) removedKeys.get(lang); |
|
183 |
newKeysDict = (TreeMap) newKeys.get(lang); |
|
184 |
Iterator removeIterator = removedKeysDict.iterator(); |
|
185 |
while (removeIterator.hasNext()) { |
|
186 |
key = (String) removeIterator.next(); |
|
187 |
newKeysDict.remove(key); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
removedKeys = new HashMap(); |
|
192 |
|
|
193 |
// we already added all the new keys with value to the database |
|
194 |
// now we try to find a translation for the keys without translation |
|
195 |
for (int i=0; i<config.languages.length; i++) { |
|
196 |
lang = config.languages[i]; |
|
197 |
File langDir = new File(config.outputDir+File.separator+lang); |
|
198 |
langDir.mkdirs(); |
|
199 |
|
|
200 |
// process the keys |
|
201 |
newKeysDict = (TreeMap) newKeys.get(lang); |
|
202 |
removedKeysDict = new ArrayList(); |
|
203 |
removedKeys.put(lang, removedKeysDict); |
|
204 |
Iterator newKeysIterator = newKeysDict.keySet().iterator(); |
|
205 |
while (newKeysIterator.hasNext()) { |
|
206 |
key = (String) newKeysIterator.next(); |
|
207 |
value = ""; |
|
208 |
String auxValue; |
|
209 |
for (int currentAuxLang=0; currentAuxLang<config.languages.length && (value==null || value.equals("")); currentAuxLang++) { |
|
210 |
auxLang = config.languages[currentAuxLang]; |
|
211 |
auxValue = database.getTranslation(auxLang, key); |
|
212 |
if (auxValue!=null && !auxValue.equals("")) { |
|
213 |
ArrayList keyList = database.getAssociatedKeys(auxLang, value); |
|
214 |
if (keyList!=null) { |
|
215 |
for (int j=0; j<keyList.size() && (value==null || !value.equals("")); j++) { |
|
216 |
value = database.getTranslation(lang, (String)keyList.get(j)); |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
if (value!=null && !value.equals("")) { // the translation has a value |
|
222 |
dbValue = database.getTranslation(lang, key); |
|
223 |
if (dbValue==null || !dbValue.equals("")) { |
|
224 |
/* if dbValue == "" means that the key has been changed and should be sent for translation. |
|
225 |
* It should not be added to the database with the value from the property file, as it is not valid anymore. |
|
226 |
*/ |
|
227 |
|
|
228 |
database.setTranslation(lang, key, value); |
|
229 |
// it has been added to database, it isn't new anymore |
|
230 |
// we add the key to the list of keys to remove. We don't remove it now because then there is troubles with the iterator |
|
231 |
removedKeysDict.add(key); |
|
232 |
} |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
// remove |
|
238 |
for (int i=0; i<config.languages.length; i++) { |
|
239 |
lang = config.languages[i]; |
|
240 |
removedKeysDict = (ArrayList) removedKeys.get(lang); |
|
241 |
newKeysDict = (TreeMap) newKeys.get(lang); |
|
242 |
Iterator removeIterator = removedKeysDict.iterator(); |
|
243 |
while (removeIterator.hasNext()) { |
|
244 |
key = (String) removeIterator.next(); |
|
245 |
newKeysDict.remove(key); |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 |
// output the keys to be translated |
|
250 |
outputNewKeys(newKeys); |
|
251 |
|
|
252 |
// update the values of each project's property files and store to disk |
|
253 |
saveKeys(); |
|
254 |
|
|
255 |
// store datase to disk |
|
256 |
database.save(); |
|
257 |
} |
|
258 |
|
|
259 |
private void outputNewKeys(HashMap newKeys) { |
|
260 |
String lang, auxLang; |
|
261 |
/** |
|
262 |
* Process the new or changed keys |
|
263 |
*/ |
|
264 |
for (int i=0; i<config.languages.length; i++) { |
|
265 |
lang = config.languages[i]; |
|
266 |
File langDir = new File(config.outputDir+File.separator+lang); |
|
267 |
langDir.mkdirs(); |
|
268 |
HashMap outputFiles = new HashMap(); |
|
269 |
HashMap outputPropertiesStream = new HashMap(); |
|
270 |
HashMap outputProperties = new HashMap(); |
|
271 |
|
|
272 |
// open the output files, one for each defined language |
|
273 |
for (int j=0; j<config.outputLanguages.length; j++) { |
|
274 |
auxLang = config.outputLanguages[j]; |
|
275 |
FileOutputStream fos, fosProp; |
|
276 |
OrderedProperties prop; |
|
277 |
try { |
|
278 |
fos = new FileOutputStream(langDir.getPath()+File.separator+config.defaultBaseName+"_"+auxLang+".properties-"+config.outputEncoding); |
|
279 |
fosProp = new FileOutputStream(langDir.getPath()+File.separator+config.defaultBaseName+"_"+auxLang+".properties"); |
|
280 |
prop = new OrderedProperties(); |
|
281 |
outputPropertiesStream.put(auxLang, fosProp); |
|
282 |
outputProperties.put(auxLang, prop); |
|
283 |
try { |
|
284 |
outputFiles.put(auxLang, new BufferedWriter(new OutputStreamWriter(fos, config.outputEncoding))); |
|
285 |
} catch (UnsupportedEncodingException e) { |
|
286 |
// TODO Auto-generated catch block |
|
287 |
System.err.println(e.getLocalizedMessage()); |
|
288 |
System.exit(-1); |
|
289 |
} |
|
290 |
} catch (FileNotFoundException e) { |
|
291 |
// TODO Auto-generated catch block |
|
292 |
System.err.println(e.getLocalizedMessage()); |
|
293 |
System.exit(-1); |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
297 |
// also open the file for language we're processing currently |
|
298 |
if (!outputFiles.containsKey(lang)) { |
|
299 |
FileOutputStream fos, fosProp; |
|
300 |
OrderedProperties prop; |
|
301 |
try { |
|
302 |
fos = new FileOutputStream(langDir.getPath()+File.separator+config.defaultBaseName+"_"+lang+".properties-"+config.outputEncoding); |
|
303 |
fosProp = new FileOutputStream(langDir.getPath()+File.separator+config.defaultBaseName+"_"+lang+".properties"); |
|
304 |
prop = new OrderedProperties(); |
|
305 |
outputPropertiesStream.put(lang, fosProp); |
|
306 |
outputProperties.put(lang, prop); |
|
307 |
try { |
|
308 |
outputFiles.put(lang, new BufferedWriter(new OutputStreamWriter(fos, config.outputEncoding))); |
|
309 |
} catch (UnsupportedEncodingException e) { |
|
310 |
// TODO Auto-generated catch block |
|
311 |
System.err.println(e.getLocalizedMessage()); |
|
312 |
System.exit(-1); |
|
313 |
} |
|
314 |
} catch (FileNotFoundException e) { |
|
315 |
// TODO Auto-generated catch block |
|
316 |
System.err.println(e.getLocalizedMessage()); |
|
317 |
System.exit(-1); |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
TreeMap dict = (TreeMap) newKeys.get(lang); |
|
322 |
Iterator keyIterator = dict.keySet().iterator(); |
|
323 |
String key, value; |
|
324 |
while (keyIterator.hasNext()) { |
|
325 |
key = (String) keyIterator.next(); |
|
326 |
|
|
327 |
Iterator files = outputFiles.keySet().iterator(); |
|
328 |
BufferedWriter writer; |
|
329 |
while (files.hasNext()) { |
|
330 |
// we output the pair key-value for the defined output languages (they're used for reference by translators) |
|
331 |
auxLang = (String) files.next(); |
|
332 |
writer = (BufferedWriter) outputFiles.get(auxLang); |
|
333 |
value = database.getTranslation(auxLang, key); |
|
334 |
try { |
|
335 |
if (value!=null) |
|
336 |
writer.write(key+"="+value+"\n"); |
|
337 |
else |
|
338 |
writer.write(key+"=\n"); |
|
339 |
} catch (IOException e) { |
|
340 |
// TODO Auto-generated catch block |
|
341 |
e.printStackTrace(); |
|
342 |
} |
|
343 |
} |
|
344 |
Iterator props = outputProperties.keySet().iterator(); |
|
345 |
OrderedProperties prop; |
|
346 |
while (props.hasNext()) { |
|
347 |
// we output the pair key-value for the defined output languages (they're used for reference by translators) |
|
348 |
auxLang = (String) props.next(); |
|
349 |
prop = (OrderedProperties) outputProperties.get(auxLang); |
|
350 |
value = database.getTranslation(auxLang, key); |
|
351 |
if (value!=null) |
|
352 |
prop.put(key, value); |
|
353 |
else |
|
354 |
prop.put(key, ""); |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
Iterator props = outputProperties.keySet().iterator(); |
|
359 |
OrderedProperties prop; |
|
360 |
FileOutputStream fos; |
|
361 |
while (props.hasNext()) { |
|
362 |
auxLang = (String) props.next(); |
|
363 |
fos = (FileOutputStream) outputPropertiesStream.get(auxLang); |
|
364 |
prop = (OrderedProperties) outputProperties.get(auxLang); |
|
365 |
try { |
|
366 |
prop.store(fos, "Translations for language ["+auxLang+"]"); |
|
367 |
} catch (IOException e) { |
|
368 |
// TODO Auto-generated catch block |
|
369 |
e.printStackTrace(); |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
// close the files now |
|
374 |
Iterator files = outputFiles.keySet().iterator(); |
|
375 |
while (files.hasNext()) { |
|
376 |
auxLang = (String) files.next(); |
|
377 |
BufferedWriter writer = (BufferedWriter) outputFiles.get(auxLang); |
|
378 |
try { |
|
379 |
writer.close(); |
|
380 |
} catch (IOException e) { |
|
381 |
// do nothing here |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
private HashMap detectNewKeys() { |
|
388 |
Project currentProject; |
|
389 |
String lang; |
|
390 |
OrderedProperties dict; |
|
391 |
TreeMap auxDict; |
|
392 |
Iterator keys; |
|
393 |
String key, value, dbValue; |
|
394 |
HashMap newKeys = new HashMap(); |
|
395 |
for (int i=0; i<config.languages.length; i++) { |
|
396 |
lang = config.languages[i]; |
|
397 |
newKeys.put(lang, new TreeMap()); |
|
398 |
} |
|
399 |
|
|
400 |
/** |
|
401 |
* Detect the new or changed keys |
|
402 |
* We just make a list, we will check the list later (to detect conflicting changes) |
|
403 |
*/ |
|
404 |
for (int i=0; i<config.projects.size(); i++) { |
|
405 |
currentProject = (Project) config.projects.get(i); |
|
406 |
for (int j=0; j<config.languages.length; j++) { |
|
407 |
lang = config.languages[j]; |
|
408 |
dict = (OrderedProperties) currentProject.dictionaries.get(lang); |
|
409 |
keys = dict.keySet().iterator(); |
|
410 |
while (keys.hasNext()) { |
|
411 |
key = (String) keys.next(); |
|
412 |
value = dict.getProperty(key); |
|
413 |
dbValue = database.getTranslation(lang, key); |
|
414 |
if (dbValue==null || dbValue.equals("") || (!value.equals("") && !dbValue.equals(value))) { |
|
415 |
String []newKey = new String[2]; |
|
416 |
newKey[0]=value; |
|
417 |
newKey[1]= currentProject.dir; |
|
418 |
auxDict = (TreeMap) newKeys.get(lang); |
|
419 |
ArrayList keyList = (ArrayList) auxDict.get(key); |
|
420 |
if (keyList==null) { |
|
421 |
keyList = new ArrayList(); |
|
422 |
} |
|
423 |
keyList.add(newKey); |
|
424 |
auxDict.put(key, keyList); |
|
425 |
} |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
return newKeys; |
|
430 |
} |
|
431 |
|
|
432 |
private static void usage() { |
|
433 |
System.out.println("Uso: UpdateTrans [OPCION]"); |
|
434 |
System.out.println("\t-c\t--config=configFile"); |
|
435 |
} |
|
436 |
|
|
437 |
/** |
|
438 |
* Reads the command line parameters */ |
|
439 |
private boolean readParameters(String[] args) { |
|
440 |
String configPair[]; |
|
441 |
|
|
442 |
for (int i=0; i<args.length; i++) { |
|
443 |
configPair = args[i].split("=",2); |
|
444 |
if ( (configPair[0].equals("-c") || configPair[0].equals("--config")) |
|
445 |
&& configPair.length==2) { |
|
446 |
configFileName = configPair[1]; |
|
447 |
} |
|
448 |
else { |
|
449 |
return false; |
|
450 |
} |
|
451 |
} |
|
452 |
return true; |
|
453 |
} |
|
454 |
|
|
455 |
private boolean loadConfig() { |
|
456 |
config = new ConfigOptions(configFileName); |
|
457 |
config.load(); |
|
458 |
return true; |
|
459 |
} |
|
460 |
|
|
461 |
/** |
|
462 |
* Reads the translation keys from the projects speficied in |
|
463 |
* the config file. The keys are stored for each project in |
|
464 |
* 'config.projects'. |
|
465 |
* |
|
466 |
* @return |
|
467 |
*/ |
|
468 |
private void loadKeys() { |
|
469 |
Keys keys = new Keys(config); |
|
470 |
keys.load(); |
|
471 |
} |
|
472 |
|
|
473 |
private void saveKeys() { |
|
474 |
Project project; |
|
475 |
OrderedProperties dict; |
|
476 |
String lang; |
|
477 |
|
|
478 |
for (int currentProject=0; currentProject<config.projects.size(); currentProject++) { |
|
479 |
project = ((Project)config.projects.get(currentProject)); |
|
480 |
|
|
481 |
for (int currentLang=0; currentLang<config.languages.length; currentLang++) { |
|
482 |
lang = (String) config.languages[currentLang]; |
|
483 |
dict = (OrderedProperties) project.dictionaries.get(lang); |
|
484 |
String dbValue, key; |
|
485 |
|
|
486 |
Iterator keysIterator = dict.keySet().iterator(); |
|
487 |
while (keysIterator.hasNext()) { |
|
488 |
key = (String) keysIterator.next(); |
|
489 |
dbValue = database.getTranslation(lang, key); |
|
490 |
if (dbValue!=null) { |
|
491 |
dict.setProperty(key, dbValue); |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
|
|
497 |
Keys keys = new Keys(config); |
|
498 |
keys.save(); |
|
499 |
} |
|
500 |
|
|
501 |
private void loadDataBase() { |
|
502 |
database = new TranslationDatabase(config); |
|
503 |
database.load(); |
|
504 |
} |
|
505 |
|
|
506 |
} |
|
0 | 507 |
tags/v2_0_0_Build_2050/libraries/libInternationalization/src-utils/org/gvsig/i18n/utils/Keys.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package org.gvsig.i18n.utils; |
|
5 |
|
|
6 |
import java.io.BufferedReader; |
|
7 |
import java.io.File; |
|
8 |
import java.io.FileInputStream; |
|
9 |
import java.io.FileNotFoundException; |
|
10 |
import java.io.FileOutputStream; |
|
11 |
import java.io.IOException; |
|
12 |
import java.io.InputStreamReader; |
|
13 |
import java.io.UnsupportedEncodingException; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.HashSet; |
|
16 |
import java.util.Iterator; |
|
17 |
import java.util.regex.Matcher; |
|
18 |
import java.util.regex.Pattern; |
|
19 |
|
|
20 |
import org.kxml2.io.KXmlParser; |
|
21 |
import org.xmlpull.v1.XmlPullParserException; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author cesar |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class Keys { |
|
28 |
private ConfigOptions config; |
|
29 |
|
|
30 |
public Keys(ConfigOptions config) { |
|
31 |
this.config = config; |
|
32 |
} |
|
33 |
|
|
34 |
public void load() { |
|
35 |
Project project; |
|
36 |
for (int currentProject=0; currentProject<config.projects.size(); currentProject++) { |
|
37 |
project = ((Project)config.projects.get(currentProject)); |
|
38 |
/** |
|
39 |
* There is two options, "properties" and "sources". "sources" is the default, so |
|
40 |
* if there was something different to "properties", we assume "sources". |
|
41 |
*/ |
|
42 |
if (!project.sourceKeys.equals("properties")) { |
|
43 |
project.dictionaries = loadProjectFromSources(project); |
|
44 |
} |
|
45 |
else { |
|
46 |
// load the keys for each language from the property file |
|
47 |
project.dictionaries = loadProjectFromProperties(project); |
|
48 |
// add missing keys tp each language |
|
49 |
completeKeys(project); |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
public void save() { |
|
55 |
Project project; |
|
56 |
OrderedProperties dict; |
|
57 |
FileOutputStream stream=null; |
|
58 |
String lang; |
|
59 |
|
|
60 |
for (int currentProject=0; currentProject<config.projects.size(); currentProject++) { |
|
61 |
project = ((Project)config.projects.get(currentProject)); |
|
62 |
|
|
63 |
for (int currentLang=0; currentLang<config.languages.length; currentLang++) { |
|
64 |
lang = (String) config.languages[currentLang]; |
|
65 |
dict = (OrderedProperties) project.dictionaries.get(lang); |
|
66 |
|
|
67 |
if (dict.size()>0) { |
|
68 |
// ensure the directory exists |
|
69 |
File propertyDir = new File(project.propertyDir); |
|
70 |
if (propertyDir.mkdirs()) |
|
71 |
System.out.println("Aviso -- directorio creado: "+project.propertyDir); |
|
72 |
|
|
73 |
try { |
|
74 |
// different for spanish... |
|
75 |
if (lang.equals("es")) { |
|
76 |
stream = new FileOutputStream(project.propertyDir+File.separator+project.basename+".properties"); |
|
77 |
} |
|
78 |
else { |
|
79 |
stream = new FileOutputStream(project.propertyDir+File.separator+project.basename+"_"+lang+".properties"); |
|
80 |
} |
|
81 |
} catch (FileNotFoundException e) { |
|
82 |
// TODO Auto-generated catch block |
|
83 |
e.printStackTrace(); |
|
84 |
} |
|
85 |
|
|
86 |
try { |
|
87 |
dict.store(stream, "Translations for language ["+lang+"]"); |
|
88 |
} catch (IOException e) { |
|
89 |
// TODO Auto-generated catch block |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
private HashMap loadProjectFromSources(Project project) { |
|
98 |
// always start with an empty HashMap when loading |
|
99 |
HashMap dictionaries = new HashMap(); |
|
100 |
String lang; |
|
101 |
|
|
102 |
/** |
|
103 |
* The keys obtained from the sources and the config.xml files of the |
|
104 |
* plugins. |
|
105 |
*/ |
|
106 |
HashSet keys = new HashSet(); |
|
107 |
/** |
|
108 |
* The translations loaded from the property files of the project. |
|
109 |
*/ |
|
110 |
|
|
111 |
dictionaries = loadProjectFromProperties(project); |
|
112 |
|
|
113 |
for (int i=0; i<project.srcDirs.length; i++) { |
|
114 |
try { |
|
115 |
keys = loadKeysFromSources(ConfigOptions.getAbsolutePath(File.separator, project.dir+File.separator+project.srcDirs[i]), keys); |
|
116 |
} |
|
117 |
catch (IOException ex) { |
|
118 |
// It there was an error reading the directory, just warn and skip the dir |
|
119 |
System.err.println(project.dir +" -- Aviso: no se pudo leer el directorio "+project.dir+File.separator+project.srcDirs[i]); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
for (int currentLang=0; currentLang<config.languages.length; currentLang++) { |
|
124 |
lang = config.languages[currentLang]; |
|
125 |
|
|
126 |
OrderedProperties currentDict = (OrderedProperties) dictionaries.get(lang); |
|
127 |
Iterator keysIterator = keys.iterator(); |
|
128 |
String key; |
|
129 |
// add missing keys |
|
130 |
while (keysIterator.hasNext()) { |
|
131 |
key = (String) keysIterator.next(); |
|
132 |
if (!currentDict.containsKey(key)) { |
|
133 |
currentDict.put(key, ""); |
|
134 |
System.out.println(project.dir+" -- Aviso -- clave a?adida: "+key); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
// remove extra keys |
|
139 |
// first make a list of keys to remove, because it's not possible to access the iterator and the TreeMap at the same time |
|
140 |
/* HashSet removedKeys = new HashSet(); |
|
141 |
Iterator dictKey = currentDict.keySet().iterator(); |
|
142 |
while (dictKey.hasNext()) { |
|
143 |
key = (String) dictKey.next(); |
|
144 |
if (!keys.contains(key)) { |
|
145 |
removedKeys.add(key); |
|
146 |
System.out.println(project.dir+" -- Aviso -- clave eliminada: "+key); |
|
147 |
} |
|
148 |
} |
|
149 |
// now we really remove the keys |
|
150 |
Iterator removedKeysIt = removedKeys.iterator(); |
Also available in: Unified diff