List of usage examples for java.util ResourceBundle getBundle
@CallerSensitive public static ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader)
From source file:it.imtech.configuration.ChooseServer.java
/** * Creates new form ChooseServer// ww w . ja v a2 s. co m */ public ChooseServer(XMLConfiguration config) { initComponents(); bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); Server[] servers = getServersFromConfig(config, bundle); choose_server.setModel(new javax.swing.DefaultComboBoxModel(servers)); choose_server.setSelectedItem(servers[0]); choose_server.setMinimumSize(new Dimension(400, 20)); getLanguagesFromConfig(config, bundle); choose_language.setModel(new javax.swing.DefaultComboBoxModel(Globals.LANGUAGES)); choose_language.setSelectedItem(this.selected_lang); choose_language.setMinimumSize(new Dimension(400, 20)); updateLanguage(); MigLayout choose_layout = new MigLayout("fillx, insets 10 20 10 50"); main_panel = new JPanel(choose_layout); main_panel.add(label_server_1, "wrap 20"); main_panel.add(label_server_2, "wrap 30"); main_panel.add(label_server_3, "wrap 5"); main_panel.add(choose_server, "wrap 10"); main_panel.add(label_server_4, "wrap 5"); main_panel.add(choose_language, "wrap 10"); this.setLayout(new BorderLayout()); this.add(BorderLayout.CENTER, main_panel); //Gestione eventi choose_language.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox comboBox = (JComboBox) event.getSource(); Language selected = (Language) comboBox.getSelectedItem(); selected_lang = selected; Globals.CURRENT_LOCALE = new Locale(selected.getCode()); updateLanguage(); Utility.setDefaultLangCurrent(); } }); this.setPreferredSize(this.getPreferredSize()); this.validate(); this.repaint(); }
From source file:com.icesoft.faces.utils.MessageUtils.java
private static void loadMessageInfo(String bundleName, Locale locale, String messageId, String[] messageInfo) { ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, getClassLoader(bundleName)); try {/*from w w w . ja v a 2 s.co m*/ messageInfo[SUMMARY] = bundle.getString(messageId); messageInfo[DETAIL] = bundle.getString(messageId + DETAIL_SUFFIX); } catch (MissingResourceException e) { } }
From source file:com.ibm.CloudResourceBundle.java
public static ResourceBundle getBundle(Locale locale, CloudDataConnection connection) { ResourceBundle rb = null;/*w w w .j av a 2s .com*/ try { rows = getServerResponse(connection); rb = ResourceBundle.getBundle("", locale, new CloudRBControl()); } catch (Exception e) { System.out.println("Error calling CloudIntegration service"); } return rb; }
From source file:it.imtech.configuration.StartWizard.java
/** * Creates a new wizard with active card (Select Language/Server) *///w w w . j a va 2 s . c o m public StartWizard() { Globals.setGlobalVariables(); ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); if (!checkAppDataFiles()) { JOptionPane.showMessageDialog(null, Utility.getBundleString("copy_appdata", bundle), Utility.getBundleString("copy_appdata_title", bundle), JOptionPane.ERROR_MESSAGE); System.exit(1); } DOMConfigurator.configure(Globals.LOG4J); logger = Logger.getLogger(StartWizard.class); logger.info("Starting Application Phaidra Importer"); mainFrame = new JFrame(); if (Utility.internetConnectionAvailable()) { Globals.ONLINE = true; } it.imtech.utility.Utility.cleanUndoDir(); XMLConfiguration internalConf = setConfiguration(); logger.info("Configuration path estabilished"); XMLConfiguration config = setConfigurationPaths(internalConf, bundle); headerPanel = new HeaderPanel(); footerPanel = new FooterPanel(); JButton nextButton = (JButton) footerPanel.getComponentByName("next_button"); JButton prevButton = (JButton) footerPanel.getComponentByName("prev_button"); nextButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (getCurrentCard() instanceof ChooseServer) { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); try { mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Server selected = chooseServer.getSelectedServer(); logger.info("Selected Server = " + selected.getServername()); SelectedServer.getInstance(null).makeEmpty(); SelectedServer.getInstance(selected); if (Globals.ONLINE) { logger.info("Testing server connection..."); ChooseServer.testServerConnection(SelectedServer.getInstance(null).getBaseUrl()); } chooseFolder.updateLanguage(); MetaUtility.getInstance().preInitializeData(); logger.info("Preinitialization done (Vocabulary and Languages"); c1.next(cardsPanel); mainFrame.setCursor(null); } catch (Exception ex) { logger.error(ex.getMessage()); JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("preinitializemetadataex", bundle)); } } else if (getCurrentCard() instanceof ChooseFolder) { mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); boolean error = chooseFolder.checkFolderSelectionValidity(); if (error == false) { BookImporter x = BookImporter.getInstance(); mainFrame.setCursor(null); mainFrame.setVisible(false); } } } }); prevButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (getCurrentCard() instanceof ChooseServer) { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); String title = Utility.getBundleString("dialog_1_title", bundle); String text = Utility.getBundleString("dialog_1", bundle); ConfirmDialog confirm = new ConfirmDialog(mainFrame, true, title, text, Utility.getBundleString("confirm", bundle), Utility.getBundleString("back", bundle)); confirm.setVisible(true); boolean close = confirm.getChoice(); confirm.dispose(); if (close == true) { mainFrame.dispose(); } } else { c1.previous(cardsPanel); } } }); cardsPanel = new JPanel(new CardLayout()); cardsPanel.setBackground(Color.WHITE); chooseServer = new ChooseServer(config); chooseFolder = new ChooseFolder(); cardsPanel.add(chooseServer, "1"); cardsPanel.add(chooseFolder, "2"); cardsPanel.setLayout(c1); c1.show(cardsPanel, "1"); //Main Panel style mainPanel = new JPanel(new BorderLayout()); mainPanel.add(BorderLayout.NORTH, headerPanel); mainPanel.add(BorderLayout.CENTER, cardsPanel); mainPanel.add(BorderLayout.PAGE_END, footerPanel); mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); String title = Utility.getBundleString("dialog_1_title", bundle); String text = Utility.getBundleString("dialog_1", bundle); ConfirmDialog confirm = new ConfirmDialog(mainFrame, true, title, text, Utility.getBundleString("confirm", bundle), Utility.getBundleString("back", bundle)); confirm.setVisible(true); boolean close = confirm.getChoice(); confirm.dispose(); if (close == true) { mainFrame.dispose(); } } }); //Add Style mainFrame.getContentPane().setBackground(Color.white); mainFrame.getContentPane().setLayout(new BorderLayout()); mainFrame.getContentPane().setPreferredSize(new Dimension(640, 400)); mainFrame.getContentPane().add(BorderLayout.CENTER, mainPanel); mainFrame.pack(); //Center frame in the screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int x = (dim.width - mainFrame.getSize().width) / 2; int y = (dim.height - mainFrame.getSize().height) / 2; mainFrame.setLocation(x, y); mainFrame.setVisible(true); }
From source file:com.googlecode.jtiger.modules.ecside.resource.TableResourceBundle.java
private ResourceBundle findResourceBundle(String resourceBundleLocation, Locale locale) { try {/* w ww. j av a 2 s . c om*/ return ResourceBundle.getBundle(resourceBundleLocation, locale, getClass().getClassLoader()); } catch (MissingResourceException e) { LogHandler.errorLog(logger, "The resource bundle [ " + resourceBundleLocation + "] was not found. Make sure the path and resource name is correct.", e); } return null; }
From source file:com.gettextresourcebundle.GettextResourceBundleControlTest.java
/** * test that PO files loaded from the file system will reload after * cache timeout occurs and modified dates are different * @throws IOException//w w w. ja va 2 s. com */ @Test public void testFileReloads() throws IOException { File localeDirectory = new File("./src/test/resources/locale"); File localeNewDirectory = new File("./src/test/resources/localeNew"); File targetDirectory = new File("./target/testLocales"); targetDirectory.mkdirs(); //unit test with 5 second cache time final long cacheTTL = 5 * 1000l; GettextResourceBundleControl.setCacheTTL(cacheTTL); FileUtils.copyDirectory(localeDirectory, targetDirectory, false); ResourceBundle en_US = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.US, GettextResourceBundleControl.getControl("test")); assertEquals("The locale key should be en_US for the en_US locale", "en_US", en_US.getString("locale")); ResourceBundle en_CA = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.CANADA, GettextResourceBundleControl.getControl("test")); assertEquals("The locale key should be en_CA for the en_CA locale", "en_CA", en_CA.getString("locale")); FileUtils.copyDirectory(localeNewDirectory, targetDirectory, false); en_US = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.US, GettextResourceBundleControl.getControl("test")); assertEquals("The locale key should be en_US for the en_US locale before cache expiry", "en_US", en_US.getString("locale")); en_CA = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.CANADA, GettextResourceBundleControl.getControl("test")); assertEquals("The locale key should be en_CA for the en_CA locale before cache expiry", "en_CA", en_CA.getString("locale")); //wait until cacheTTL passes so that cache expires long end = System.currentTimeMillis() + (cacheTTL); while (end > System.currentTimeMillis()) { try { Thread.sleep(end - System.currentTimeMillis()); } catch (InterruptedException e) { } } en_US = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.US, GettextResourceBundleControl.getControl("test")); assertEquals("The locale key should be en_US #2 for the en_US locale before cache expiry", "en_US #2", en_US.getString("locale")); en_CA = ResourceBundle.getBundle(targetDirectory.getAbsolutePath(), Locale.CANADA, GettextResourceBundleControl.getControl("test")); assertEquals("The locale key should be en_CA #2 for the en_CA locale before cache expiry", "en_CA #2", en_CA.getString("locale")); }
From source file:com.ultrapower.eoms.common.plugin.ecside.resource.TableResourceBundle.java
private ResourceBundle findResourceBundle(String resourceBundleLocation, Locale locale) { try {//from www .j av a2 s . c om return ResourceBundle.getBundle(resourceBundleLocation, locale, getClass().getClassLoader()); } catch (MissingResourceException e) { LogHandler.errorLog(logger,"The resource bundle [ " + resourceBundleLocation + "] was not found. Make sure the path and resource name is correct.", e); } return null; }
From source file:it.scoppelletti.programmerpower.security.DefaultRoleManager.java
public Map<String, String> loadRoles(Locale locale) { String desc, role;/* w w w. ja v a2s . c o m*/ ResourceBundle res; Map<String, String> map; Enumeration<String> keys; if (locale == null) { throw new ArgumentNullException("locale"); } map = new TreeMap<String, String>(); try { res = ResourceBundle.getBundle(DefaultRoleManager.BASENAME, locale, myLoader); } catch (MissingResourceException ex) { myLogger.warn(String.format("Resource bundle %1$s not found.", DefaultRoleManager.BASENAME), ex); return map; } keys = res.getKeys(); while (keys.hasMoreElements()) { role = keys.nextElement(); try { desc = res.getString(role); } catch (MissingResourceException ex) { desc = null; } if (Strings.isNullOrEmpty(desc)) { desc = role; } map.put(role, desc); } return map; }
From source file:com.projity.strings.Messages.java
public static void setMetaBundle(String bundleName) { metaBundle = ResourceBundle.getBundle(bundleName, Locale.getDefault(), ClassLoaderUtils.getLocalClassLoader()/*Messages.class.getClassLoader()*/); }
From source file:uk.co.grahamcox.yui.LanguageModuleBuilder.java
/** * Get the module file requested//from w w w.ja va2s . com * @param group the group of the module * @param file the file of the module * @return the contents of the module * @throws java.io.IOException if an error occurs loading module content */ public String getModuleFile(String group, String file, String language) throws IOException { if (groups.containsKey(group)) { ModuleGroup moduleGroup = groups.get(group); Module module = moduleGroup.findModule(file); if (module != null) { StringBuilder moduleOutput = new StringBuilder(); moduleOutput.append("YUI.add('lang/").append(module.getName()); if (language != null && !language.isEmpty()) { moduleOutput.append("_").append(language); } moduleOutput.append("', function (Y) {\n"); moduleOutput.append("Y.Intl.add(\n"); moduleOutput.append("'").append(module.getName()).append("',\n"); moduleOutput.append("'").append(language).append("',\n"); moduleOutput.append("{\n"); String resourceKey = module.getMessagesFile().toString(); Locale locale; if (language == null || language.isEmpty()) { locale = Locale.getDefault(); } else { locale = Locale.forLanguageTag(language); } ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceKey, locale, new LanguageControl()); Enumeration<String> keys = resourceBundle.getKeys(); boolean isFirst = true; while (keys.hasMoreElements()) { String key = keys.nextElement(); String value = resourceBundle.getString(key); if (!isFirst) { moduleOutput.append(","); } isFirst = false; moduleOutput.append("'").append(key).append("': '").append(value).append("'"); } moduleOutput.append("});\n"); moduleOutput.append("}, '").append(module.getVersion()).append("');"); return moduleOutput.toString(); } else { throw new UnknownModuleException(group, file); } } else { throw new UnknownGroupException(group); } }