Changeset 12644 in josm
- Timestamp:
- 2017-08-25T15:17:01+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r12643 r12644 51 51 import org.openstreetmap.josm.io.OsmApi; 52 52 import org.openstreetmap.josm.tools.CheckParameterUtil; 53 import org.openstreetmap.josm.tools.I18n;54 53 import org.openstreetmap.josm.tools.ImageProvider; 55 54 import org.openstreetmap.josm.tools.JosmRuntimeException; … … 712 711 public static void preConstructorInit() { 713 712 ProjectionPreference.setProjection(); 714 I18n.translateJavaInternalMessages();715 713 716 714 // init default coordinate format -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12643 r12644 265 265 // hooks for the jmapviewer component 266 266 FeatureAdapter.registerBrowserAdapter(OpenBrowser::displayUrl); 267 FeatureAdapter.registerTranslationAdapter(I18n .getTranslationAdapter());267 FeatureAdapter.registerTranslationAdapter(I18n::tr); 268 268 FeatureAdapter.registerLoggingAdapter(name -> Logging.getLogger()); 269 269 // UI update … … 710 710 FontsManager.initialize(); 711 711 712 I18n.setupLanguageFonts();712 GuiHelper.setupLanguageFonts(); 713 713 714 714 Handler.install(); … … 777 777 toolbar = new ToolbarPreferences(); 778 778 Main.toolbar = toolbar; 779 GuiHelper.translateJavaInternalMessages(); 779 780 preConstructorInit(); 780 781 -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r12634 r12644 26 26 import java.awt.image.FilteredImageSource; 27 27 import java.lang.reflect.InvocationTargetException; 28 import java.util.Arrays; 29 import java.util.Collection; 28 30 import java.util.Enumeration; 29 31 import java.util.EventObject; 32 import java.util.Locale; 30 33 import java.util.concurrent.Callable; 31 34 import java.util.concurrent.ExecutionException; … … 34 37 import javax.swing.GrayFilter; 35 38 import javax.swing.ImageIcon; 39 import javax.swing.JColorChooser; 36 40 import javax.swing.JComponent; 41 import javax.swing.JFileChooser; 37 42 import javax.swing.JLabel; 38 43 import javax.swing.JOptionPane; … … 51 56 import org.openstreetmap.josm.gui.ExtendedDialog; 52 57 import org.openstreetmap.josm.gui.MainApplication; 58 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 53 59 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 54 60 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 67 73 */ 68 74 public final class GuiHelper { 75 76 /* Localization keys for file chooser (and color chooser). */ 77 private static final String[] JAVA_INTERNAL_MESSAGE_KEYS = new String[] { 78 /* JFileChooser windows laf */ 79 "FileChooser.detailsViewActionLabelText", 80 "FileChooser.detailsViewButtonAccessibleName", 81 "FileChooser.detailsViewButtonToolTipText", 82 "FileChooser.fileAttrHeaderText", 83 "FileChooser.fileDateHeaderText", 84 "FileChooser.fileNameHeaderText", 85 "FileChooser.fileNameLabelText", 86 "FileChooser.fileSizeHeaderText", 87 "FileChooser.fileTypeHeaderText", 88 "FileChooser.filesOfTypeLabelText", 89 "FileChooser.homeFolderAccessibleName", 90 "FileChooser.homeFolderToolTipText", 91 "FileChooser.listViewActionLabelText", 92 "FileChooser.listViewButtonAccessibleName", 93 "FileChooser.listViewButtonToolTipText", 94 "FileChooser.lookInLabelText", 95 "FileChooser.newFolderAccessibleName", 96 "FileChooser.newFolderActionLabelText", 97 "FileChooser.newFolderToolTipText", 98 "FileChooser.refreshActionLabelText", 99 "FileChooser.saveInLabelText", 100 "FileChooser.upFolderAccessibleName", 101 "FileChooser.upFolderToolTipText", 102 "FileChooser.viewMenuLabelText", 103 104 /* JFileChooser gtk laf */ 105 "FileChooser.acceptAllFileFilterText", 106 "FileChooser.cancelButtonText", 107 "FileChooser.cancelButtonToolTipText", 108 "FileChooser.deleteFileButtonText", 109 "FileChooser.filesLabelText", 110 "FileChooser.filterLabelText", 111 "FileChooser.foldersLabelText", 112 "FileChooser.newFolderButtonText", 113 "FileChooser.newFolderDialogText", 114 "FileChooser.openButtonText", 115 "FileChooser.openButtonToolTipText", 116 "FileChooser.openDialogTitleText", 117 "FileChooser.pathLabelText", 118 "FileChooser.renameFileButtonText", 119 "FileChooser.renameFileDialogText", 120 "FileChooser.renameFileErrorText", 121 "FileChooser.renameFileErrorTitle", 122 "FileChooser.saveButtonText", 123 "FileChooser.saveButtonToolTipText", 124 "FileChooser.saveDialogTitleText", 125 126 /* JFileChooser motif laf */ 127 //"FileChooser.cancelButtonText", 128 //"FileChooser.cancelButtonToolTipText", 129 "FileChooser.enterFileNameLabelText", 130 //"FileChooser.filesLabelText", 131 //"FileChooser.filterLabelText", 132 //"FileChooser.foldersLabelText", 133 "FileChooser.helpButtonText", 134 "FileChooser.helpButtonToolTipText", 135 //"FileChooser.openButtonText", 136 //"FileChooser.openButtonToolTipText", 137 //"FileChooser.openDialogTitleText", 138 //"FileChooser.pathLabelText", 139 //"FileChooser.saveButtonText", 140 //"FileChooser.saveButtonToolTipText", 141 //"FileChooser.saveDialogTitleText", 142 "FileChooser.updateButtonText", 143 "FileChooser.updateButtonToolTipText", 144 145 /* gtk color chooser */ 146 "GTKColorChooserPanel.blueText", 147 "GTKColorChooserPanel.colorNameText", 148 "GTKColorChooserPanel.greenText", 149 "GTKColorChooserPanel.hueText", 150 "GTKColorChooserPanel.nameText", 151 "GTKColorChooserPanel.redText", 152 "GTKColorChooserPanel.saturationText", 153 "GTKColorChooserPanel.valueText", 154 155 /* JOptionPane */ 156 "OptionPane.okButtonText", 157 "OptionPane.yesButtonText", 158 "OptionPane.noButtonText", 159 "OptionPane.cancelButtonText" 160 }; 69 161 70 162 private GuiHelper() { … … 526 618 } 527 619 } 620 621 /** 622 * Localizations for file chooser dialog. 623 * For some locales (e.g. de, fr) translations are provided 624 * by Java, but not for others (e.g. ru, uk). 625 * @since 12644 (moved from I18n) 626 */ 627 public static void translateJavaInternalMessages() { 628 Locale l = Locale.getDefault(); 629 630 AbstractFileChooser.setDefaultLocale(l); 631 JFileChooser.setDefaultLocale(l); 632 JColorChooser.setDefaultLocale(l); 633 for (String key : JAVA_INTERNAL_MESSAGE_KEYS) { 634 String us = UIManager.getString(key, Locale.US); 635 String loc = UIManager.getString(key, l); 636 // only provide custom translation if it is not already localized by Java 637 if (us != null && us.equals(loc)) { 638 UIManager.put(key, tr(us)); 639 } 640 } 641 } 642 643 /** 644 * Setup special font for Khmer script, as the default Java fonts do not display these characters. 645 * @since 12644 (moved from I18n) 646 * @since 8282 647 */ 648 public static void setupLanguageFonts() { 649 // Use special font for Khmer script, as the default Java font do not display these characters 650 if ("km".equals(LanguageInfo.getJOSMLocaleCode())) { 651 Collection<String> fonts = Arrays.asList( 652 GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); 653 for (String f : new String[]{"Khmer UI", "DaunPenh", "MoolBoran"}) { 654 if (fonts.contains(f)) { 655 setUIFont(f); 656 break; 657 } 658 } 659 } 660 } 528 661 } -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r12627 r12644 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.awt.GraphicsEnvironment;5 4 import java.io.BufferedInputStream; 6 5 import java.io.File; … … 22 21 import java.util.jar.JarInputStream; 23 22 import java.util.zip.ZipEntry; 24 25 import javax.swing.JColorChooser;26 import javax.swing.JFileChooser;27 import javax.swing.UIManager;28 29 import org.openstreetmap.gui.jmapviewer.FeatureAdapter.TranslationAdapter;30 import org.openstreetmap.josm.gui.util.GuiHelper;31 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;32 23 33 24 /** … … 95 86 private static volatile String loadedCode = "en"; 96 87 97 /* Localization keys for file chooser (and color chooser). */ 98 private static final String[] JAVA_INTERNAL_MESSAGE_KEYS = new String[] { 99 /* JFileChooser windows laf */ 100 "FileChooser.detailsViewActionLabelText", 101 "FileChooser.detailsViewButtonAccessibleName", 102 "FileChooser.detailsViewButtonToolTipText", 103 "FileChooser.fileAttrHeaderText", 104 "FileChooser.fileDateHeaderText", 105 "FileChooser.fileNameHeaderText", 106 "FileChooser.fileNameLabelText", 107 "FileChooser.fileSizeHeaderText", 108 "FileChooser.fileTypeHeaderText", 109 "FileChooser.filesOfTypeLabelText", 110 "FileChooser.homeFolderAccessibleName", 111 "FileChooser.homeFolderToolTipText", 112 "FileChooser.listViewActionLabelText", 113 "FileChooser.listViewButtonAccessibleName", 114 "FileChooser.listViewButtonToolTipText", 115 "FileChooser.lookInLabelText", 116 "FileChooser.newFolderAccessibleName", 117 "FileChooser.newFolderActionLabelText", 118 "FileChooser.newFolderToolTipText", 119 "FileChooser.refreshActionLabelText", 120 "FileChooser.saveInLabelText", 121 "FileChooser.upFolderAccessibleName", 122 "FileChooser.upFolderToolTipText", 123 "FileChooser.viewMenuLabelText", 124 125 /* JFileChooser gtk laf */ 126 "FileChooser.acceptAllFileFilterText", 127 "FileChooser.cancelButtonText", 128 "FileChooser.cancelButtonToolTipText", 129 "FileChooser.deleteFileButtonText", 130 "FileChooser.filesLabelText", 131 "FileChooser.filterLabelText", 132 "FileChooser.foldersLabelText", 133 "FileChooser.newFolderButtonText", 134 "FileChooser.newFolderDialogText", 135 "FileChooser.openButtonText", 136 "FileChooser.openButtonToolTipText", 137 "FileChooser.openDialogTitleText", 138 "FileChooser.pathLabelText", 139 "FileChooser.renameFileButtonText", 140 "FileChooser.renameFileDialogText", 141 "FileChooser.renameFileErrorText", 142 "FileChooser.renameFileErrorTitle", 143 "FileChooser.saveButtonText", 144 "FileChooser.saveButtonToolTipText", 145 "FileChooser.saveDialogTitleText", 146 147 /* JFileChooser motif laf */ 148 //"FileChooser.cancelButtonText", 149 //"FileChooser.cancelButtonToolTipText", 150 "FileChooser.enterFileNameLabelText", 151 //"FileChooser.filesLabelText", 152 //"FileChooser.filterLabelText", 153 //"FileChooser.foldersLabelText", 154 "FileChooser.helpButtonText", 155 "FileChooser.helpButtonToolTipText", 156 //"FileChooser.openButtonText", 157 //"FileChooser.openButtonToolTipText", 158 //"FileChooser.openDialogTitleText", 159 //"FileChooser.pathLabelText", 160 //"FileChooser.saveButtonText", 161 //"FileChooser.saveButtonToolTipText", 162 //"FileChooser.saveDialogTitleText", 163 "FileChooser.updateButtonText", 164 "FileChooser.updateButtonToolTipText", 165 166 /* gtk color chooser */ 167 "GTKColorChooserPanel.blueText", 168 "GTKColorChooserPanel.colorNameText", 169 "GTKColorChooserPanel.greenText", 170 "GTKColorChooserPanel.hueText", 171 "GTKColorChooserPanel.nameText", 172 "GTKColorChooserPanel.redText", 173 "GTKColorChooserPanel.saturationText", 174 "GTKColorChooserPanel.valueText", 175 176 /* JOptionPane */ 177 "OptionPane.okButtonText", 178 "OptionPane.yesButtonText", 179 "OptionPane.noButtonText", 180 "OptionPane.cancelButtonText" 181 }; 88 182 89 private static volatile Map<String, String> strings; 183 90 private static volatile Map<String, String[]> pstrings; … … 679 586 } 680 587 681 /**682 * Localizations for file chooser dialog.683 * For some locales (e.g. de, fr) translations are provided684 * by Java, but not for others (e.g. ru, uk).685 */686 public static void translateJavaInternalMessages() {687 Locale l = Locale.getDefault();688 689 AbstractFileChooser.setDefaultLocale(l);690 JFileChooser.setDefaultLocale(l);691 JColorChooser.setDefaultLocale(l);692 for (String key : JAVA_INTERNAL_MESSAGE_KEYS) {693 String us = UIManager.getString(key, Locale.US);694 String loc = UIManager.getString(key, l);695 // only provide custom translation if it is not already localized by Java696 if (us != null && us.equals(loc)) {697 UIManager.put(key, tr(us));698 }699 }700 }701 702 588 private static int pluralEval(long n) { 703 589 switch(pluralMode) { … … 732 618 return 0; 733 619 } 734 735 public static TranslationAdapter getTranslationAdapter() {736 return I18n::tr;737 }738 739 /**740 * Setup special font for Khmer script, as the default Java fonts do not display these characters.741 *742 * @since 8282743 */744 public static void setupLanguageFonts() {745 // Use special font for Khmer script, as the default Java font do not display these characters746 if ("km".equals(LanguageInfo.getJOSMLocaleCode())) {747 Collection<String> fonts = Arrays.asList(748 GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());749 for (String f : new String[]{"Khmer UI", "DaunPenh", "MoolBoran"}) {750 if (fonts.contains(f)) {751 GuiHelper.setUIFont(f);752 break;753 }754 }755 }756 }757 620 }
Note:
See TracChangeset
for help on using the changeset viewer.