Revision 28461
trunk/extensions/extI18n/src/org/gvsig/i18n/I18nManager.java | ||
---|---|---|
152 | 152 |
File exportFile) throws I18nException; |
153 | 153 |
|
154 | 154 |
/** |
155 |
* Exports the translations of a list of locales to update or complete its |
|
156 |
* translation, into a jar file. Into the file is also included the |
|
157 |
* translations of another existing locale to be used as reference for |
|
158 |
* updating the locale. |
|
159 |
* |
|
160 |
* @param locales |
|
161 |
* the locales to update or complete |
|
162 |
* @param referenceLocale |
|
163 |
* the locale to be used as reference |
|
164 |
* @param exportFile |
|
165 |
* the jar file to export to |
|
166 |
* @throws I18nException |
|
167 |
* if the locale could not be exported for update |
|
168 |
*/ |
|
169 |
void exportLocalesForUpdate(Locale[] locales, Locale referenceLocale, |
|
170 |
File exportFile) throws I18nException; |
|
171 |
|
|
172 |
/** |
|
155 | 173 |
* Exports the keys of text to translate to a new locale to a jar file. Into |
156 | 174 |
* the file is also included the translations of another existing locale to |
157 | 175 |
* be used as reference for translating to the new locale. |
... | ... | |
169 | 187 |
File exportFile) throws I18nException; |
170 | 188 |
|
171 | 189 |
/** |
190 |
* Exports the keys of text to translate to a new locale to a jar file. Into |
|
191 |
* the file is also included the translations of another existing locales to |
|
192 |
* be used as reference for translating to the new locale. |
|
193 |
* |
|
194 |
* @param locale |
|
195 |
* the new locale to translate to |
|
196 |
* @param referenceLocales |
|
197 |
* the locales to be used as reference |
|
198 |
* @param exportFile |
|
199 |
* the jar file to export to |
|
200 |
* @throws I18nException |
|
201 |
* if the locale could not be exported for translation |
|
202 |
*/ |
|
203 |
void exportLocaleForTranslation(Locale locale, Locale[] referenceLocales, |
|
204 |
File exportFile) throws I18nException; |
|
205 |
|
|
206 |
/** |
|
172 | 207 |
* Returns the list of default locales to use as reference when exporting to |
173 | 208 |
* translate a new locale, or update or complete an existing one. |
174 | 209 |
* |
trunk/extensions/extI18n/src/org/gvsig/i18n/extension/preferences/table/LocaleTableModel.java | ||
---|---|---|
39 | 39 |
*/ |
40 | 40 |
public class LocaleTableModel extends AbstractTableModel { |
41 | 41 |
|
42 |
// Start from 0 to enable de locale column again |
|
43 |
public static final int COLUMN_LOCALE = -1; |
|
44 |
|
|
42 | 45 |
public static final int COLUMN_LANGUAGE = 0; |
43 | 46 |
|
44 | 47 |
public static final int COLUMN_COUNTRY = 1; |
... | ... | |
75 | 78 |
|
76 | 79 |
public Object getValueAt(int rowIndex, int columnIndex) { |
77 | 80 |
switch (columnIndex) { |
81 |
case COLUMN_LOCALE: |
|
82 |
return locales[rowIndex]; |
|
78 | 83 |
case COLUMN_LANGUAGE: |
79 | 84 |
return manager.getLanguageDisplayName(locales[rowIndex]); |
80 | 85 |
case COLUMN_COUNTRY: |
... | ... | |
90 | 95 |
|
91 | 96 |
public String getColumnName(int columnIndex) { |
92 | 97 |
switch (columnIndex) { |
98 |
case COLUMN_LOCALE: |
|
99 |
return Messages.getText("I18nPreferencePage.Locale_code"); |
|
93 | 100 |
case COLUMN_LANGUAGE: |
94 | 101 |
return Messages.getText("I18nPreferencePage.Idioma"); |
95 | 102 |
case COLUMN_COUNTRY: |
... | ... | |
104 | 111 |
|
105 | 112 |
public Class getColumnClass(int columnIndex) { |
106 | 113 |
switch (columnIndex) { |
114 |
case COLUMN_LOCALE: |
|
107 | 115 |
case COLUMN_LANGUAGE: |
108 | 116 |
case COLUMN_COUNTRY: |
109 | 117 |
case COLUMN_VARIANT: |
trunk/extensions/extI18n/src/org/gvsig/i18n/extension/preferences/I18nPreferencePage.java | ||
---|---|---|
26 | 26 |
*/ |
27 | 27 |
package org.gvsig.i18n.extension.preferences; |
28 | 28 |
|
29 |
import java.awt.*; |
|
29 |
import java.awt.Component; |
|
30 |
import java.awt.Dimension; |
|
31 |
import java.awt.Font; |
|
32 |
import java.awt.GridBagConstraints; |
|
33 |
import java.awt.GridBagLayout; |
|
34 |
import java.awt.Insets; |
|
30 | 35 |
import java.awt.event.ActionEvent; |
31 | 36 |
import java.awt.event.ActionListener; |
32 | 37 |
import java.io.File; |
33 |
import java.util.*; |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.HashSet; |
|
40 |
import java.util.List; |
|
41 |
import java.util.Locale; |
|
42 |
import java.util.Set; |
|
34 | 43 |
|
35 |
import javax.swing.*; |
|
44 |
import javax.swing.Box; |
|
45 |
import javax.swing.BoxLayout; |
|
46 |
import javax.swing.ImageIcon; |
|
47 |
import javax.swing.JFileChooser; |
|
48 |
import javax.swing.JLabel; |
|
49 |
import javax.swing.JOptionPane; |
|
50 |
import javax.swing.JPanel; |
|
51 |
import javax.swing.JScrollPane; |
|
52 |
import javax.swing.JTable; |
|
53 |
import javax.swing.JTextArea; |
|
54 |
import javax.swing.ListSelectionModel; |
|
36 | 55 |
import javax.swing.filechooser.FileFilter; |
37 | 56 |
import javax.swing.table.TableColumn; |
38 | 57 |
|
39 | 58 |
import org.gvsig.gui.beans.swing.JButton; |
40 |
import org.gvsig.i18n.*; |
|
41 |
import org.gvsig.i18n.extension.preferences.table.*; |
|
59 |
import org.gvsig.i18n.I18nException; |
|
60 |
import org.gvsig.i18n.I18nManager; |
|
61 |
import org.gvsig.i18n.Messages; |
|
62 |
import org.gvsig.i18n.extension.preferences.table.LocaleTableModel; |
|
63 |
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellEditor; |
|
64 |
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellRenderer; |
|
42 | 65 |
import org.gvsig.i18n.impl.I18nManagerImpl; |
43 | 66 |
|
44 | 67 |
import com.iver.andami.preferences.AbstractPreferencePage; |
... | ... | |
197 | 220 |
* Updates the translation of a locale |
198 | 221 |
*/ |
199 | 222 |
private void exportLocaleForUpdate() { |
200 |
Locale locale = getSelectedLocale();
|
|
223 |
Locale[] locales = getSelectedLocales();
|
|
201 | 224 |
|
202 |
if (locale == null) { |
|
225 |
if (locales == null) {
|
|
203 | 226 |
JOptionPane.showMessageDialog(this, Messages |
204 | 227 |
.getText("I18nPreferencePage.seleccione_idioma"), Messages |
205 | 228 |
.getText("I18nPreferencePage.error_actualizar_idioma"), |
... | ... | |
208 | 231 |
else { |
209 | 232 |
// Select the reference language |
210 | 233 |
LocaleItem[] items = getLocaleItemsForSelection(manager |
211 |
.getInstalledLocales(), new Locale[] { locale }); |
|
212 |
LocaleItem selected; |
|
213 |
// Select by default the current locale, or the first one |
|
214 |
// if the current locale is the one to be updated |
|
215 |
if (locale.equals(manager.getCurrentLocale())) { |
|
216 |
selected = items[0]; |
|
217 |
} |
|
218 |
else { |
|
219 |
selected = new LocaleItem(manager.getCurrentLocale(), manager); |
|
220 |
} |
|
221 |
selected = (LocaleItem) JOptionPane |
|
222 |
.showInputDialog( |
|
223 |
this, |
|
224 |
Messages |
|
225 |
.getText("I18nPreferencePage.seleccione_idioma_referencia"), |
|
226 |
Messages |
|
227 |
.getText("I18nPreferencePage.exportar_idioma"), |
|
228 |
JOptionPane.QUESTION_MESSAGE, null, items, selected); |
|
234 |
.getInstalledLocales(), locales); |
|
235 |
LocaleItem selected = null; |
|
236 |
if (items != null && items.length > 0) { |
|
237 |
// Select by default the current locale, or the first one |
|
238 |
// if the current locale is one of the ones to be updated |
|
239 |
for (int i = 0; i < locales.length && selected == null; i++) { |
|
240 |
if (locales[i].equals(manager.getCurrentLocale())) { |
|
241 |
selected = items[0]; |
|
242 |
} |
|
243 |
} |
|
244 |
if (selected == null) { |
|
245 |
selected = new LocaleItem(manager.getCurrentLocale(), |
|
246 |
manager); |
|
247 |
} |
|
248 |
selected = (LocaleItem) JOptionPane |
|
249 |
.showInputDialog( |
|
250 |
this, |
|
251 |
Messages |
|
252 |
.getText("I18nPreferencePage.seleccione_idioma_referencia"), |
|
253 |
Messages |
|
254 |
.getText("I18nPreferencePage.exportar_idioma"), |
|
255 |
JOptionPane.QUESTION_MESSAGE, null, items, |
|
256 |
selected); |
|
229 | 257 |
|
230 |
if (selected == null) { |
|
231 |
return; |
|
258 |
if (selected == null) { |
|
259 |
return; |
|
260 |
} |
|
232 | 261 |
} |
233 | 262 |
// Select the file to export to |
234 | 263 |
JFileChooser fileChooser = getJarFileChooser(); |
235 |
fileChooser.setSelectedFile(new File(getLocaleJarFileName(locale))); |
|
264 |
fileChooser.setSelectedFile(new File( |
|
265 |
getLocaleJarFileName(locales[0]))); |
|
236 | 266 |
|
237 | 267 |
if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { |
238 | 268 |
File saveFile = fileChooser.getSelectedFile(); |
239 | 269 |
try { |
240 |
manager.exportLocaleForUpdate(locale, selected.getLocale(), |
|
270 |
Locale fileNameLocale = selected == null ? manager |
|
271 |
.getCurrentLocale() : selected.getLocale(); |
|
272 |
manager.exportLocalesForUpdate(locales, fileNameLocale, |
|
241 | 273 |
saveFile); |
242 |
|
|
274 |
|
|
243 | 275 |
JOptionPane |
244 | 276 |
.showMessageDialog( |
245 | 277 |
this, |
246 | 278 |
Messages |
247 | 279 |
.getText("I18nPreferencePage.exportado_textos_idioma") |
248 | 280 |
+ " " |
249 |
+ manager.getDisplayName(locale) |
|
250 |
+ Messages |
|
251 |
.getText("I18nPreferencePage.al_archivo") |
|
252 | 281 |
+ saveFile, |
253 | 282 |
Messages |
254 | 283 |
.getText("I18nPreferencePage.exportar_idioma"), |
... | ... | |
264 | 293 |
* Prepares a locale for translation. |
265 | 294 |
*/ |
266 | 295 |
private void exportLocaleForTranslation() { |
267 |
// Get the selected locale as the one for reference |
|
268 |
Locale refLocale = getSelectedLocale();
|
|
296 |
// Get the selected locale as the ones for reference
|
|
297 |
Locale[] refLocales = getSelectedLocales();
|
|
269 | 298 |
|
270 |
if (refLocale == null) { |
|
299 |
if (refLocales == null) {
|
|
271 | 300 |
JOptionPane |
272 | 301 |
.showMessageDialog( |
273 | 302 |
this, |
... | ... | |
304 | 333 |
File saveFile = fileChooser.getSelectedFile(); |
305 | 334 |
try { |
306 | 335 |
manager.exportLocaleForTranslation(selected.getLocale(), |
307 |
refLocale, saveFile); |
|
336 |
refLocales, saveFile);
|
|
308 | 337 |
|
309 | 338 |
JOptionPane |
310 | 339 |
.showMessageDialog( |
... | ... | |
329 | 358 |
|
330 | 359 |
private LocaleItem[] getLocaleItemsForSelection(Locale[] locales, |
331 | 360 |
Locale[] exceptions) { |
332 |
LocaleItem[] items = new LocaleItem[locales.length - 1];
|
|
361 |
List items = new ArrayList();
|
|
333 | 362 |
Set exceptionsSet = new HashSet(exceptions.length); |
334 | 363 |
for (int i = 0; i < exceptions.length; i++) { |
335 | 364 |
exceptionsSet.add(exceptions[i]); |
... | ... | |
339 | 368 |
for (int i = 0; i < locales.length; i++) { |
340 | 369 |
// Only add locales not included in the exceptions list |
341 | 370 |
if (!exceptionsSet.contains(locales[i])) { |
342 |
items[j] = new LocaleItem(locales[i], manager);
|
|
371 |
items.add(new LocaleItem(locales[i], manager));
|
|
343 | 372 |
j++; |
344 | 373 |
} |
345 | 374 |
} |
346 |
return items;
|
|
375 |
return (LocaleItem[]) items.toArray(new LocaleItem[items.size()]);
|
|
347 | 376 |
} |
348 | 377 |
|
349 | 378 |
/** |
... | ... | |
381 | 410 |
} |
382 | 411 |
|
383 | 412 |
/** |
384 |
* Removes an installed locale from gvSIG.
|
|
413 |
* Removes some installed locales from gvSIG.
|
|
385 | 414 |
*/ |
386 | 415 |
private void uninstallSelectedLocale() { |
387 |
Locale locale = getSelectedLocale();
|
|
416 |
Locale[] locales = getSelectedLocales();
|
|
388 | 417 |
|
389 |
if (locale == null) { |
|
418 |
if (locales == null) {
|
|
390 | 419 |
JOptionPane |
391 | 420 |
.showMessageDialog( |
392 | 421 |
this, |
... | ... | |
395 | 424 |
Messages |
396 | 425 |
.getText("I18nPreferencePage.error_desinstalar_idioma"), |
397 | 426 |
JOptionPane.ERROR_MESSAGE); |
427 |
return; |
|
398 | 428 |
} |
399 |
else if (locale.equals(manager.getCurrentLocale())) { |
|
400 |
JOptionPane |
|
401 |
.showMessageDialog( |
|
402 |
this, |
|
403 |
Messages |
|
404 |
.getText("I18nPreferencePage.idioma_actual_no_puede_desinstalar"), |
|
405 |
Messages |
|
406 |
.getText("I18nPreferencePage.error_desinstalar_idioma"), |
|
407 |
JOptionPane.ERROR_MESSAGE); |
|
408 |
} |
|
409 |
else { |
|
410 |
int option = JOptionPane |
|
411 |
.showConfirmDialog( |
|
412 |
this, |
|
413 |
Messages |
|
414 |
.getText("I18nPreferencePage.seguro_desea_desinstalar_idioma") |
|
415 |
+ " " |
|
416 |
+ manager.getDisplayName(locale) |
|
417 |
+ "?", |
|
418 |
Messages |
|
419 |
.getText("I18nPreferencePage.confirmar_desinstalar_idioma"), |
|
420 |
JOptionPane.YES_NO_OPTION); |
|
421 |
if (option == JOptionPane.YES_OPTION) { |
|
422 |
try { |
|
423 |
tableModel.removeLocale(locale); |
|
424 |
} catch (I18nException ex) { |
|
425 |
ex.showError(); |
|
429 |
|
|
430 |
for (int i = 0; i < locales.length; i++) { |
|
431 |
|
|
432 |
if (locales[i].equals(manager.getCurrentLocale())) { |
|
433 |
JOptionPane |
|
434 |
.showMessageDialog( |
|
435 |
this, |
|
436 |
Messages |
|
437 |
.getText("I18nPreferencePage.idioma_actual_no_puede_desinstalar"), |
|
438 |
Messages |
|
439 |
.getText("I18nPreferencePage.error_desinstalar_idioma"), |
|
440 |
JOptionPane.ERROR_MESSAGE); |
|
441 |
} else { |
|
442 |
int option = JOptionPane |
|
443 |
.showConfirmDialog( |
|
444 |
this, |
|
445 |
Messages |
|
446 |
.getText("I18nPreferencePage.seguro_desea_desinstalar_idioma") |
|
447 |
+ " " |
|
448 |
+ manager.getDisplayName(locales[i]) |
|
449 |
+ "?", |
|
450 |
Messages |
|
451 |
.getText("I18nPreferencePage.confirmar_desinstalar_idioma"), |
|
452 |
JOptionPane.YES_NO_OPTION); |
|
453 |
if (option == JOptionPane.YES_OPTION) { |
|
454 |
try { |
|
455 |
tableModel.removeLocale(locales[i]); |
|
456 |
} catch (I18nException ex) { |
|
457 |
ex.showError(); |
|
458 |
} |
|
426 | 459 |
} |
427 | 460 |
} |
428 | 461 |
} |
429 | 462 |
} |
430 | 463 |
|
431 | 464 |
/** |
432 |
* Returns the Locale selected in the table of available locales. |
|
465 |
* Returns the Locales selected in the table of available locales.
|
|
433 | 466 |
*/ |
434 |
private Locale getSelectedLocale() { |
|
435 |
int rowIndex = localesTable.getSelectedRow(); |
|
436 |
if (rowIndex >= 0) { |
|
437 |
return tableModel.getLocale(rowIndex); |
|
467 |
private Locale[] getSelectedLocales() { |
|
468 |
int[] rowIndexes = localesTable.getSelectedRows(); |
|
469 |
if (rowIndexes != null && rowIndexes.length > 0) { |
|
470 |
Locale[] locales = new Locale[rowIndexes.length]; |
|
471 |
for (int i = 0; i < locales.length; i++) { |
|
472 |
locales[i] = tableModel.getLocale(rowIndexes[i]); |
|
473 |
} |
|
474 |
return locales; |
|
438 | 475 |
} |
439 | 476 |
else { |
440 | 477 |
return null; |
... | ... | |
453 | 490 |
activeColumn.setCellEditor(new RadioButtonCellEditor()); |
454 | 491 |
activeColumn.setCellRenderer(new RadioButtonCellRenderer()); |
455 | 492 |
|
456 |
// Only single selection, as we will use the selected row as the source |
|
457 |
// for the actions of the panel buttons. |
|
458 |
localesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
493 |
localesTable |
|
494 |
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
|
459 | 495 |
localesTable.getSelectionModel().setSelectionInterval(0, 0); |
460 | 496 |
JScrollPane scrollPane = new JScrollPane(localesTable); |
461 | 497 |
|
... | ... | |
464 | 500 |
localesPanel.setLayout(new BoxLayout(localesPanel, BoxLayout.Y_AXIS)); |
465 | 501 |
localesPanel.add(scrollPane); |
466 | 502 |
localesPanel.setAlignmentX(CENTER_ALIGNMENT); |
467 |
localesPanel.setPreferredSize(new Dimension(236, 240));
|
|
468 |
localesPanel.setMaximumSize(new Dimension(500, 240));
|
|
503 |
localesPanel.setPreferredSize(new Dimension(236, 230));
|
|
504 |
localesPanel.setMaximumSize(new Dimension(500, 230));
|
|
469 | 505 |
|
470 | 506 |
return localesPanel; |
471 | 507 |
} |
... | ... | |
603 | 639 |
} |
604 | 640 |
|
605 | 641 |
public String toString() { |
606 |
return manager.getDisplayName(locale).concat(" (").concat( |
|
607 |
locale.toString()).concat(")"); |
|
642 |
return manager.getDisplayName(locale); |
|
608 | 643 |
} |
609 | 644 |
|
610 | 645 |
public boolean equals(Object obj) { |
trunk/extensions/extI18n/src/org/gvsig/i18n/impl/I18nManagerImpl.java | ||
---|---|---|
128 | 128 |
registeredLocales.add(defaultLocales[i]); |
129 | 129 |
} |
130 | 130 |
storeInstalledLocales(); |
131 |
} |
|
132 |
else { |
|
131 |
} else { |
|
133 | 132 |
XMLEntity localesEntity = getRegisteredLocalesPersistence(); |
134 | 133 |
registeredLocales = new HashSet(localesEntity |
135 | 134 |
.getChildrenCount()); |
... | ... | |
185 | 184 |
name.append(locale.getDisplayVariant(displayLocale)); |
186 | 185 |
} |
187 | 186 |
|
187 |
name.append(" (").append(locale.toString()).append(")"); |
|
188 |
|
|
188 | 189 |
return name.toString(); |
189 | 190 |
} |
190 | 191 |
|
... | ... | |
212 | 213 |
if ("__valenciano".equals(displayName)) { |
213 | 214 |
displayName = Messages.getText("__catalan"); |
214 | 215 |
} |
215 |
} |
|
216 |
else { |
|
216 |
} else { |
|
217 | 217 |
displayName = locale.getDisplayLanguage(displayLocale); |
218 | 218 |
} |
219 | 219 |
|
... | ... | |
237 | 237 |
if (i >= 0) { |
238 | 238 |
country = region.substring(0, i); |
239 | 239 |
variant = region.substring(i + 1); |
240 |
} |
|
241 |
else { |
|
240 |
} else { |
|
242 | 241 |
country = region; |
243 | 242 |
variant = ""; |
244 | 243 |
} |
245 |
} |
|
246 |
else { |
|
244 |
} else { |
|
247 | 245 |
country = (String) AccessController |
248 | 246 |
.doPrivileged(new GetPropertyAction("user.country", "")); |
249 | 247 |
variant = (String) AccessController |
... | ... | |
266 | 264 |
ZipFile zipFile = new ZipFile(importFile); |
267 | 265 |
|
268 | 266 |
Map locales = getZipFileNonReferenceLocales(zipFile); |
269 |
|
|
267 |
|
|
270 | 268 |
if (locales == null || locales.size() == 0) { |
271 | 269 |
return null; |
272 | 270 |
} |
... | ... | |
319 | 317 |
public void exportLocaleForUpdate(Locale locale, Locale referenceLocale, |
320 | 318 |
File exportFile) throws I18nException { |
321 | 319 |
|
322 |
exportLocale(locale, referenceLocale, exportFile, true); |
|
320 |
exportLocalesForUpdate(new Locale[] { locale }, referenceLocale, |
|
321 |
exportFile); |
|
323 | 322 |
} |
324 | 323 |
|
324 |
public void exportLocalesForUpdate(Locale[] locales, |
|
325 |
Locale referenceLocale, File exportFile) throws I18nException { |
|
326 |
|
|
327 |
exportLocale(locales, new Locale[] { referenceLocale }, exportFile, |
|
328 |
true); |
|
329 |
} |
|
330 |
|
|
325 | 331 |
public void exportLocaleForTranslation(Locale locale, |
326 | 332 |
Locale referenceLocale, File exportFile) throws I18nException { |
333 |
|
|
334 |
exportLocaleForTranslation(locale, new Locale[] { referenceLocale }, |
|
335 |
exportFile); |
|
336 |
} |
|
327 | 337 |
|
328 |
exportLocale(locale, referenceLocale, exportFile, false); |
|
338 |
public void exportLocaleForTranslation(Locale locale, |
|
339 |
Locale[] referenceLocales, File exportFile) throws I18nException { |
|
340 |
|
|
341 |
exportLocale(new Locale[] { locale }, referenceLocales, exportFile, |
|
342 |
false); |
|
329 | 343 |
} |
330 | 344 |
|
331 | 345 |
public Locale[] getReferenceLocales() { |
... | ... | |
340 | 354 |
this.defaultLocales = defaultLocales; |
341 | 355 |
} |
342 | 356 |
|
343 |
private void exportLocale(Locale locale, Locale referenceLocale,
|
|
357 |
private void exportLocale(Locale[] locales, Locale[] referenceLocales,
|
|
344 | 358 |
File exportFile, boolean update) throws I18nException { |
345 | 359 |
|
346 |
Locale[] refArray = getReferenceLocalesToExport(locale, referenceLocale); |
|
360 |
Locale[] refArray = getReferenceLocalesToExport(locales, |
|
361 |
referenceLocales); |
|
347 | 362 |
|
348 | 363 |
try { |
349 | 364 |
FileOutputStream fos = new FileOutputStream(exportFile); |
350 | 365 |
ZipOutputStream zipos = new ZipOutputStream(fos); |
351 | 366 |
|
352 | 367 |
// Create the index file |
353 |
writeZipFileLocales(zipos, locale, refArray); |
|
368 |
writeZipFileLocales(zipos, locales, refArray);
|
|
354 | 369 |
|
355 | 370 |
PrintStream ps = new PrintStream(zipos); |
356 | 371 |
Map texts = null; |
357 | 372 |
|
358 | 373 |
if (update) { |
359 |
// First, export the locale to update |
|
360 |
texts = getAllTexts(locale); |
|
361 |
putResourceInZip(zipos, ps, texts, getResourceFileName(locale)); |
|
374 |
// First, export the locales to update |
|
375 |
if (locales != null) { |
|
376 |
for (int i = 0; i < locales.length; i++) { |
|
377 |
texts = getAllTexts(locales[i]); |
|
378 |
putResourceInZip(zipos, ps, texts, |
|
379 |
getResourceFileName(locales[i])); |
|
380 |
} |
|
381 |
} |
|
382 |
} else { // translate |
|
383 |
// First, export the locales to translate, taking the keys from |
|
384 |
// the reference locales, but without values |
|
385 |
// We will use the keys of the reference locales |
|
386 |
texts = getAllTexts(referenceLocales[0]); |
|
387 |
if (locales != null) { |
|
388 |
for (int i = 0; i < locales.length; i++) { |
|
389 |
putResourceInZip(zipos, ps, texts, |
|
390 |
getResourceFileName(locales[i]), false); |
|
391 |
} |
|
392 |
} |
|
362 | 393 |
} |
363 |
else { // translate |
|
364 |
// First, export the locale to translate, taking the keys from |
|
365 |
// the reference locale, but without values |
|
366 |
// We will use the keys of the reference locale |
|
367 |
texts = getAllTexts(referenceLocale); |
|
368 |
putResourceInZip(zipos, ps, texts, getResourceFileName(locale), |
|
369 |
false); |
|
370 | 394 |
|
371 |
} |
|
372 |
|
|
373 | 395 |
// Next, export the reference locales |
374 |
for (int i = 0; i < refArray.length; i++) { |
|
375 |
texts = getAllTexts(refArray[i]); |
|
376 |
putResourceInZip(zipos, ps, texts, |
|
377 |
getResourceFileName(refArray[i])); |
|
396 |
if (refArray != null) { |
|
397 |
for (int i = 0; i < refArray.length; i++) { |
|
398 |
texts = getAllTexts(refArray[i]); |
|
399 |
putResourceInZip(zipos, ps, texts, |
|
400 |
getResourceFileName(refArray[i])); |
|
401 |
} |
|
378 | 402 |
} |
379 | 403 |
|
380 | 404 |
ps.flush(); |
... | ... | |
382 | 406 |
zipos.close(); |
383 | 407 |
fos.close(); |
384 | 408 |
} catch (IOException ex) { |
385 |
throw new ExportLocaleException(locale, ex); |
|
409 |
throw new ExportLocaleException(locales, ex);
|
|
386 | 410 |
} |
387 | 411 |
} |
388 | 412 |
|
389 | 413 |
/** |
390 | 414 |
* Returns the list of reference locales to export, as the union of the |
391 | 415 |
* default reference locales list and the one selected as reference. The |
392 |
* locale to translate or update is extracted from the list.
|
|
416 |
* locales to translate or update are extracted from the list.
|
|
393 | 417 |
*/ |
394 |
private Locale[] getReferenceLocalesToExport(Locale locale,
|
|
395 |
Locale referenceLocale) {
|
|
418 |
private Locale[] getReferenceLocalesToExport(Locale[] locales,
|
|
419 |
Locale[] referenceLocalesSelected) {
|
|
396 | 420 |
// The reference locales to export are the default ones plus the |
397 | 421 |
// selected by the user. |
398 | 422 |
Set exportRefLocales = new HashSet(referenceLocales.length); |
399 | 423 |
for (int i = 0; i < referenceLocales.length; i++) { |
400 | 424 |
exportRefLocales.add(referenceLocales[i]); |
401 | 425 |
} |
402 |
exportRefLocales.add(referenceLocale); |
|
403 |
exportRefLocales.remove(locale); |
|
426 |
if (referenceLocalesSelected != null) { |
|
427 |
for (int i = 0; i < referenceLocalesSelected.length; i++) { |
|
428 |
exportRefLocales.add(referenceLocalesSelected[i]); |
|
429 |
} |
|
430 |
} |
|
431 |
if (locales != null) { |
|
432 |
for (int i = 0; i < locales.length; i++) { |
|
433 |
exportRefLocales.remove(locales[i]); |
|
434 |
} |
|
435 |
} |
|
404 | 436 |
Locale[] refArray = (Locale[]) exportRefLocales |
405 | 437 |
.toArray(new Locale[exportRefLocales.size()]); |
406 | 438 |
return refArray; |
... | ... | |
438 | 470 |
String fileName = st.nextToken(); |
439 | 471 |
if (CSV_SEPARATOR.equals(fileName)) { |
440 | 472 |
throw new LocaleFileNameRequiredException(line); |
441 |
} |
|
442 |
else { |
|
473 |
} else { |
|
443 | 474 |
// Read the next separator |
444 | 475 |
st.nextToken(); |
445 | 476 |
} |
... | ... | |
447 | 478 |
String language = st.nextToken(); |
448 | 479 |
if (CSV_SEPARATOR.equals(language)) { |
449 | 480 |
throw new LocaleLanguageRequiredException(line); |
450 |
} |
|
451 |
else { |
|
481 |
} else { |
|
452 | 482 |
// Read the next separator |
453 | 483 |
st.nextToken(); |
454 | 484 |
} |
... | ... | |
456 | 486 |
String country = st.nextToken(); |
457 | 487 |
if (CSV_SEPARATOR.equals(country)) { |
458 | 488 |
country = null; |
459 |
} |
|
460 |
else { |
|
489 |
} else { |
|
461 | 490 |
// Read the next separator |
462 | 491 |
st.nextToken(); |
463 | 492 |
} |
... | ... | |
465 | 494 |
String variant = st.nextToken(); |
466 | 495 |
if (CSV_SEPARATOR.equals(variant)) { |
467 | 496 |
variant = null; |
468 |
} |
|
469 |
else { |
|
497 |
} else { |
|
470 | 498 |
// Read the next separator |
471 | 499 |
st.nextToken(); |
472 | 500 |
} |
... | ... | |
499 | 527 |
return locales; |
500 | 528 |
} |
501 | 529 |
|
502 |
private void writeZipFileLocales(ZipOutputStream zos, Locale locale,
|
|
530 |
private void writeZipFileLocales(ZipOutputStream zos, Locale[] locales,
|
|
503 | 531 |
Locale[] referenceLocales) throws IOException { |
504 | 532 |
ZipEntry zipEntry = new ZipEntry(LOCALES_FILE_NAME); |
505 | 533 |
|
506 | 534 |
zos.putNextEntry(zipEntry); |
507 | 535 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zos)); |
508 | 536 |
|
509 |
writeLocaleEntry(locale, writer, false); |
|
510 |
for (int i = 0; i < referenceLocales.length; i++) { |
|
511 |
writeLocaleEntry(referenceLocales[i], writer, true); |
|
537 |
if (locales != null) { |
|
538 |
for (int i = 0; i < locales.length; i++) { |
|
539 |
writeLocaleEntry(locales[i], writer, false); |
|
540 |
} |
|
512 | 541 |
} |
542 |
if (referenceLocales != null) { |
|
543 |
for (int i = 0; i < referenceLocales.length; i++) { |
|
544 |
writeLocaleEntry(referenceLocales[i], writer, true); |
|
545 |
} |
|
546 |
} |
|
513 | 547 |
|
514 | 548 |
writer.flush(); |
515 | 549 |
zos.closeEntry(); |
... | ... | |
586 | 620 |
if (withValue) { |
587 | 621 |
String valueEncoded = escape((String) entry.getValue(), false); |
588 | 622 |
ps.println(valueEncoded); |
589 |
} |
|
590 |
else { |
|
623 |
} else { |
|
591 | 624 |
ps.println(); |
592 | 625 |
} |
593 | 626 |
} |
... | ... | |
734 | 767 |
char c = value.charAt(i); |
735 | 768 |
if (c <= 0x80) { |
736 | 769 |
sb.append(c); |
737 |
} |
|
738 |
else { |
|
770 |
} else { |
|
739 | 771 |
sb.append("\\u"); |
740 | 772 |
String hexValue = Integer.toHexString((int) c); |
741 | 773 |
// Append 0 if the hex value has less than 4 digits |
trunk/extensions/extI18n/src/org/gvsig/i18n/impl/ExportLocaleException.java | ||
---|---|---|
39 | 39 |
|
40 | 40 |
private static final long serialVersionUID = -1386427767068278421L; |
41 | 41 |
|
42 |
private static final String MSG = "Unable to export the locale"; |
|
42 |
private static final String MSG = "Unable to export the locales";
|
|
43 | 43 |
|
44 | 44 |
private static final String KEY = "_ExportLocaleException"; |
45 | 45 |
|
46 |
private final Locale locale;
|
|
46 |
private final Locale[] locales;
|
|
47 | 47 |
|
48 |
public ExportLocaleException(Locale locale) {
|
|
48 |
public ExportLocaleException(Locale[] locales) {
|
|
49 | 49 |
super(MSG, KEY); |
50 |
this.locale = locale;
|
|
50 |
this.locales = locales;
|
|
51 | 51 |
} |
52 | 52 |
|
53 |
public ExportLocaleException(Locale locale, Throwable cause) {
|
|
53 |
public ExportLocaleException(Locale[] locales, Throwable cause) {
|
|
54 | 54 |
super(MSG, KEY, cause); |
55 |
this.locale = locale;
|
|
55 |
this.locales = locales;
|
|
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
public String getLocalizedMessage() { |
59 |
return super.getLocalizedMessage() + ": " + locale; |
|
59 |
StringBuffer buffer = new StringBuffer(); |
|
60 |
if (locales != null) { |
|
61 |
int i = 0; |
|
62 |
for (; i < locales.length - 1; i++) { |
|
63 |
buffer.append(locales[i]).append(','); |
|
64 |
} |
|
65 |
buffer.append(locales[i]); |
|
66 |
} |
|
67 |
return super.getLocalizedMessage() + ": " + buffer.toString(); |
|
60 | 68 |
} |
61 | 69 |
} |
Also available in: Unified diff