List of usage examples for java.util Locale forLanguageTag
public static Locale forLanguageTag(String languageTag)
From source file:alfio.manager.NotificationManager.java
private static Function<Map<String, String>, byte[]> generateICS(EventRepository eventRepository, EventDescriptionRepository eventDescriptionRepository, TicketCategoryRepository ticketCategoryRepository) { return (model) -> { Event event;/*from w w w .j a va 2s .c o m*/ Locale locale; Integer categoryId; if (model.containsKey("eventId")) { //legacy branch, now we generate the ics as a reinterpreted ticket event = eventRepository.findById(Integer.valueOf(model.get("eventId"), 10)); locale = Json.fromJson(model.get("locale"), Locale.class); categoryId = null; } else { Ticket ticket = Json.fromJson(model.get("ticket"), Ticket.class); event = eventRepository.findById(ticket.getEventId()); locale = Locale.forLanguageTag(ticket.getUserLanguage()); categoryId = ticket.getCategoryId(); } TicketCategory category = Optional.ofNullable(categoryId).map(ticketCategoryRepository::getById) .orElse(null); String description = eventDescriptionRepository.findDescriptionByEventIdTypeAndLocale(event.getId(), EventDescription.EventDescriptionType.DESCRIPTION, locale.getLanguage()).orElse(""); return EventUtil.getIcalForEvent(event, category, description).orElse(null); }; }
From source file:org.myrobotlab.service.MarySpeech.java
@Override public void setLanguage(String l) { marytts.setLocale(Locale.forLanguageTag(l)); }
From source file:org.lunifera.ecview.xtext.builder.participant.impl.I18nRegistry.java
private Locale getLocale(URL url) { File file = null;// www . j a v a 2s.co m try { file = new File(FileLocator.toFileURL(url).toURI()); } catch (URISyntaxException e) { LOGGER.error("{}", e); return null; } catch (IOException e) { LOGGER.error("{}", e); return null; } String[] tokens = file.getName().replace(".properties", "").split("_"); StringBuilder builder = new StringBuilder(); if (tokens.length >= 2) { for (int i = 1; i < tokens.length; i++) { if (builder.length() > 0) { builder.append("-"); } builder.append(tokens[i]); } } Locale locale = Locale.forLanguageTag(builder.toString()); return locale; }
From source file:com.kaikoda.cah.TestDeck.java
@Test public void testDeckGetLocale() throws SAXException, IOException, ParserConfigurationException { Deck customDeck = new Deck(this.getDocument("/data/test/cards/netherlands.xml")); Locale expected = Locale.forLanguageTag("en-nl"); Locale result = customDeck.getLocale(); assertEquals(expected, result);//from w ww . ja va 2 s .c o m assertEquals("en-NL", result.toLanguageTag()); }
From source file:com.gnadenheimer.mg3.utils.Utils.java
public void printFactura(TblFacturas factura) { try {// w w w. j a v a 2 s .com Map parameters = new HashMap(); parameters.put("factura_id", factura.getNro()); parameters.put("fechahora", java.sql.Date.valueOf(factura.getFechahora().toLocalDate())); parameters.put("razon_social", factura.getRazonSocial()); parameters.put("ruc", factura.getRuc()); parameters.put("domicilio", factura.getDomicilio()); parameters.put("box", factura.getCasillaDeCorreo() == null ? "" : factura.getCasillaDeCorreo().toString()); parameters.put("usuario", factura.getIdUser().getNombrecompleto()); parameters.put("importe_aporte", factura.getImporteAporte()); parameters.put("importe_donacion", factura.getImporteDonacion()); parameters.put("logo", getClass().getResourceAsStream("/reports/cclogo200.png")); parameters.put("logo2", getClass().getResourceAsStream("/reports/cclogo200.png")); parameters.put("logo3", getClass().getResourceAsStream("/reports/cclogo200.png")); parameters.put(JRParameter.REPORT_LOCALE, Locale.forLanguageTag("es")); //JOptionPane.showMessageDialog(null, getClass().getResource("/reports/cclogo200.png").getPath()); String reportFactura = Preferences.userRoot().node("MG").get("formatoFactura", "Preimpreso sin rejilla"); if (reportFactura.equals("Preimpreso sin rejilla")) { reportFactura = "factura_con_rejilla"; } else if (reportFactura.equals("Preimpreso con rejilla")) { reportFactura = "factura"; } else if (reportFactura.equals("Preimpreso con rejilla modelo especial Bethel Theodor")) { reportFactura = "factura_bethel"; } JasperReport report = JasperCompileManager .compileReport(getClass().getResourceAsStream("/reports/" + reportFactura + ".jrxml")); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource()); jasperPrint.setLeftMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaLeftMargin", "0"))); jasperPrint.setTopMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaTopMargin", "0"))); //JasperViewer jReportsViewer = new JasperViewer(jasperPrint, false); //jReportsViewer.setVisible(true); jasperPrint.setLeftMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaLeftMargin", "0"))); jasperPrint.setTopMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaTopMargin", "0"))); JasperPrintManager.printReport(jasperPrint, false); } catch (Exception ex) { App.showException(Thread.currentThread().getStackTrace()[1].getMethodName(), ex.getMessage(), ex); LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); } }
From source file:com.haulmont.cuba.desktop.LoginDialog.java
protected Locale resolveLocale() { Locale appLocale;//from w ww. j a v a 2s . c o m String lastLocale = this.loginProperties.loadLastLocale(); if (StringUtils.isNotEmpty(lastLocale)) { appLocale = LocaleUtils.toLocale(lastLocale); } else { appLocale = Locale.getDefault(); } for (Locale locale : locales.values()) { if (locale.equals(appLocale)) { return locale; } } // if not found and application locale contains country, try to match by language only if (StringUtils.isNotEmpty(appLocale.getCountry())) { Locale languageTagLocale = Locale.forLanguageTag(appLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(languageTagLocale)) { return locale; } } } // return first locale set in the cuba.availableLocales app property return locales.values().iterator().next(); }
From source file:org.phenotips.vocabulary.translation.AbstractXliffTranslatedVocabularyExtension.java
/** * Check if the {@link #getTargetLocale() locale targeted by this translation} is in the list of supported locales * by this instance.// w w w .j a va 2 s . co m * * @return {@code true} if the current language is targeted, or if the instance is set as multilingual and the * targeted language is included in the list of supported locales, {@code false} otherwise */ protected boolean isTargetLocaleEnabled() { Locale currentLocale = this.localizationContext.getCurrentLocale(); if (isLocaleSupported(currentLocale)) { return true; } if (!this.config.getProperty("multilingual", Boolean.FALSE)) { return false; } Set<String> defaultValue = new HashSet<>(); defaultValue.add(currentLocale.getLanguage()); Set<String> enabledLanguages = this.config.getProperty("languages", defaultValue); for (String lang : enabledLanguages) { if (StringUtils.isBlank(lang)) { continue; } String trimmed = lang.trim(); if (isLocaleSupported(Locale.forLanguageTag(trimmed))) { return true; } } return false; }
From source file:com.gnadenheimer.mg.utils.Utils.java
public void printFactura(TblFacturas factura) { try {/*from w ww . j a va 2 s . co m*/ Map parameters = new HashMap(); parameters.put("factura_id", factura.getNro()); parameters.put("fechahora", java.sql.Date.valueOf(factura.getFechahora().toLocalDate())); parameters.put("razon_social", factura.getRazonSocial()); parameters.put("ruc", factura.getRuc()); parameters.put("domicilio", factura.getDomicilio()); parameters.put("box", factura.getCasillaDeCorreo() == null ? "" : factura.getCasillaDeCorreo().toString()); parameters.put("usuario", factura.getIdUser().getNombrecompleto()); parameters.put("importe_aporte", factura.getImporteAporte()); parameters.put("importe_donacion", factura.getImporteDonacion()); parameters.put("logo", getClass().getResourceAsStream("/reports/cclogo200.png")); parameters.put("logo2", getClass().getResourceAsStream("/reports/cclogo200.png")); parameters.put("logo3", getClass().getResourceAsStream("/reports/cclogo200.png")); parameters.put("logo-bethel", getClass().getResourceAsStream("/images/logo-bethel.png")); parameters.put("logo-bethel2", getClass().getResourceAsStream("/images/logo-bethel.png")); parameters.put("logo-friesen", getClass().getResourceAsStream("/images/logo-friesen.png")); parameters.put(JRParameter.REPORT_LOCALE, Locale.forLanguageTag("es")); //JOptionPane.showMessageDialog(null, getClass().getResource("/reports/cclogo200.png").getPath()); String reportFactura = Preferences.userRoot().node("MG").get("formatoFactura", "Preimpreso sin rejilla"); if (reportFactura.equals("Preimpreso sin rejilla")) { reportFactura = "factura_con_rejilla"; } else if (reportFactura.equals("Preimpreso sin rejilla - CREDITO")) { reportFactura = "factura_con_rejilla_credito"; } else if (reportFactura.equals("Preimpreso con rejilla")) { reportFactura = "factura"; } else if (reportFactura.equals("Preimpreso con rejilla modelo especial Bethel Theodor")) { reportFactura = "factura_bethel"; } else if (reportFactura.equals("Preimpreso sin rejilla Bethel")) { reportFactura = "factura_con_rejilla_bethel_full"; } JasperReport report = JasperCompileManager .compileReport(getClass().getResourceAsStream("/reports/" + reportFactura + ".jrxml")); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource()); jasperPrint.setLeftMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaLeftMargin", "0"))); jasperPrint.setTopMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaTopMargin", "0"))); //JasperViewer jReportsViewer = new JasperViewer(jasperPrint, false); //jReportsViewer.setVisible(true); jasperPrint.setLeftMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaLeftMargin", "0"))); jasperPrint.setTopMargin( Integer.getInteger(Preferences.userRoot().node("MG").get("facturaTopMargin", "0"))); JasperPrintManager.printReport(jasperPrint, false); } catch (Exception ex) { JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); } }
From source file:org.openhab.voice.googletts.internal.GoogleCloudAPI.java
@SuppressWarnings({ "unused", "null" }) private List<GoogleTTSVoice> listVoices() throws IOException { HttpRequestBuilder builder = HttpRequestBuilder.getFrom(LIST_VOICES_URL).withHeader(AUTH_HEADER_NAME, getAuthorization());/*w ww.j av a 2 s. c o m*/ ListVoicesResponse listVoicesResponse = gson.fromJson(builder.getContentAsString(), ListVoicesResponse.class); if (listVoicesResponse == null || listVoicesResponse.getVoices() == null) { return emptyList(); } List<GoogleTTSVoice> result = new ArrayList<>(); for (Voice voice : listVoicesResponse.getVoices()) { for (String languageCode : voice.getLanguageCodes()) { result.add(new GoogleTTSVoice(Locale.forLanguageTag(languageCode), voice.getName(), voice.getSsmlGender().name())); } } return result; }
From source file:net.pms.util.Languages.java
/** * Returns a UMS supported {@link java.util.Locale} from the given * <code>Local</code> if it can be found (<code>en</code> is translated to * <code>en-US</code>, <code>zh</code> to <code>zh-Hant</code> etc.). * Returns <code>null</code> if a valid <code>Locale</code> cannot be found. * @param locale Source {@link java.util.Locale}. * @return Resulting {@link java.util.Locale}. *///from ww w .j a va 2s .co m public static Locale toLocale(Locale locale) { if (locale != null) { String code = localeToLanguageCode(locale); if (code != null && isValid(code)) { return Locale.forLanguageTag(code); } } return null; }