List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:com.cyclopsgroup.waterview.core.DefaultModuleManager.java
/** * Get i18n instance//from w ww . j a v a2 s. c o m * * @param path Module path * @param locale Locale * @return I18N instance */ synchronized I18N getInternationalization(Path path, Locale locale) { String key = "internationalization/" + locale.getCountry() + "/" + locale.getLanguage() + "/" + path.getFullPath(); I18N loc = null; if (cache.contains(this, key)) { loc = (I18N) cache.get(this, key); } else { List resourceBundles = new ArrayList(); //TODO addBundleToList(resourceBundles, externalBundle, locale); addBundleToList(resourceBundles, path.getPackage() + path.getPathWithoutExtension() + "_ResourceBundle", locale); addBundleToList(resourceBundles, path.getPackage() + "/ResourceBundle", locale); loc = new DefaultI18N(locale, resourceBundles, this); cache.put(this, key, loc); } return loc; }
From source file:org.datacleaner.user.UsageLogger.java
@Inject protected UsageLogger(UserPreferences userPreferences) { _userPreferences = userPreferences;/*from www . ja v a 2 s . c o m*/ _executorService = SharedExecutorService.get(); _javaVendor = System.getProperty("java.vendor"); _javaVersion = System.getProperty("java.version"); _osName = System.getProperty("os.name"); _osArch = System.getProperty("os.arch"); final Locale defaultLocale = Locale.getDefault(); _country = defaultLocale.getCountry(); _language = defaultLocale.getLanguage(); logger.debug( "Determined installation details as:\nJava version: {}\nJava vendor: {}\nOS name: {}\nOS arch: {}\nUser country: {}\nUser language: {}", _javaVersion, _javaVendor, _osName, _osArch, _country, _language); }
From source file:net.sourceforge.fenixedu.presentationTier.backBeans.base.FenixBackingBean.java
public Boolean getRenderInEnglish() { final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); return locale.getLanguage().equals(Locale.ENGLISH.getLanguage()); }
From source file:iqq.app.core.service.impl.I18nServiceImpl.java
private ResourceBundle getResourceBundle(Locale locale) { BufferedInputStream bis = null; try {//from w ww .ja va2 s.c o m // ??_?_?.properties String flag = locale.getLanguage() + "_" + locale.getCountry(); String filename = I18N_DIR + I18N_BUNDLE + "_" + flag + ".properties"; ResourceBundle resourceBundle = resourceBundleMap.get(flag); // ??? if (resourceBundle != null) return resourceBundle; if (!new File(filename).exists()) { filename = I18N_DIR + I18N_BUNDLE + ".properties"; } LOG.debug(filename); bis = new BufferedInputStream(new FileInputStream(filename)); resourceBundle = new PropertyResourceBundle(bis); resourceBundleMap.put(flag, resourceBundle); return resourceBundle; } catch (FileNotFoundException e) { LOG.error("?", e); } catch (IOException e) { LOG.error("??", e); } finally { if (bis != null) try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:com.agiletec.apsadmin.system.BaseAction.java
/** * Return the current system language used in the back-end interface. If this language does not * belong to those known by the system the default language is returned. A log line will * report the problem./*from w ww.j ava2 s .co m*/ * @return The current language. */ public Lang getCurrentLang() { Locale locale = this.getLocale(); String langCode = locale.getLanguage(); Lang currentLang = this.getLangManager().getLang(langCode); if (null != currentLang) { return currentLang; } else { _logger.info("Required Lang '{}' invalid", langCode); return this.getLangManager().getDefaultLang(); } }
From source file:de.gesundkrank.wikipedia.hadoop.io.WikiDumpLoader.java
/** * Loads new dump and unpack it into hdfs * * @param fs HDFS//from w w w .j a v a 2 s . c o m * @param basePath * @param time * @return * @throws java.io.IOException */ private Path loadNewDump(FileSystem fs, Path basePath, long time, Locale locale) throws IOException { System.out.println("loading new dump"); String localeDumpUrl = String.format(DUMP_URL, locale.getLanguage(), locale.getLanguage()); URLConnection connection = new URL(localeDumpUrl).openConnection(); try (BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(connection.getInputStream())) { String fileName = String.format("%swiki-latest-pages-articles.%d.xml", locale.getLanguage(), time); Path path = new Path(basePath, fileName); FSDataOutputStream outputStream = fs.create(path); final byte[] buffer = new byte[1024]; int n; while (-1 != (n = bzIn.read(buffer))) { outputStream.write(buffer, 0, n); } return path; } }
From source file:com.salesmanager.core.util.CheckoutUtil.java
/** * Creates an order product (OrderProduct) from a Product entity. An * OrderProduct is the entity used during checkout and persisted with the * order//from w w w . j a v a2 s. c o m * * @param productId * @param locale * @param currency * @return * @throws Exception */ public static OrderProduct createOrderProduct(long productId, Locale locale, String currency) throws Exception { CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); Product p = cservice.getProduct(productId); OrderProduct scp = new OrderProduct(); if (p != null) { scp.setMerchantId(p.getMerchantId()); // check if attributes exist Collection attrs = cservice.getProductAttributes(p.getProductId(), locale.getLanguage()); boolean hasPricedAttributes = false; if (attrs != null && attrs.size() > 0) { Iterator i = attrs.iterator(); while (i.hasNext()) { ProductAttribute pa = (ProductAttribute) i.next(); if (!pa.isAttributeDisplayOnly()) { hasPricedAttributes = true; } } } if (hasPricedAttributes) { scp.setAttributes(true); } scp.setProductName(""); // name Set descriptions = p.getDescriptions(); if (descriptions != null) { Iterator i = descriptions.iterator(); while (i.hasNext()) { ProductDescription pd = (ProductDescription) i.next(); if (pd.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(locale.getLanguage())) { scp.setProductName(pd.getProductName()); scp.setProductDescription(pd.getProductDescription()); break; } } } scp.setProductId(p.getProductId()); scp.setTaxClassId(p.getProductTaxClassId()); // get download ProductAttributeDownload download = cservice.getProductDownload(p.getProductId()); if (download != null) { OrderProductDownload opd = new OrderProductDownload(); opd.setDownloadCount(0); opd.setDownloadMaxdays(download.getProductAttributeMaxdays()); opd.setDownloadMaxdays(download.getProductAttributeMaxdays()); opd.setOrderProductFilename(download.getProductAttributeFilename()); opd.setFileId(download.getProductAttributeId()); Set downloads = new HashSet(); downloads.add(opd); scp.setDownloads(downloads); } // now determine price BigDecimal price = ProductUtil.determinePriceNoDiscount(p, locale, currency); scp.setFinalPrice(price); scp.setProductPrice(price); scp.setCurrency(currency); scp.setProductQuantityOrderMax(p.getProductQuantityOrderMax()); if (p.getSpecial() != null) { scp.setProductSpecialNewPrice(p.getSpecial().getSpecialNewProductPrice()); scp.setProductSpecialDateAvailable(p.getSpecial().getSpecialDateAvailable()); scp.setProductSpecialDateExpire(p.getSpecial().getExpiresDate()); } scp.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(price, currency)); scp.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(price, currency)); // original price scp.setOriginalProductPrice(price); scp.setProductImage(p.getProductImage()); scp.setProductType(p.getProductType()); scp.setProductVirtual(p.isProductVirtual()); scp.setProductWidth(p.getProductWidth()); scp.setProductWeight(p.getProductWeight()); scp.setProductHeight(p.getProductHeight()); scp.setProductLength(p.getProductLength()); scp.setProductId(p.getProductId()); Set pricesSet = p.getPrices(); if (pricesSet != null) { Set productSet = new HashSet(); Iterator i = pricesSet.iterator(); while (i.hasNext()) { ProductPrice pp = (ProductPrice) i.next(); ProductPriceSpecial pps = pp.getSpecial(); if (pps != null) { pps.setOriginalPriceAmount(pp.getProductPriceAmount()); } OrderProductPrice opp = new OrderProductPrice(); opp.setDefaultPrice(pp.isDefaultPrice()); opp.setProductPriceAmount(pp.getProductPriceAmount()); opp.setProductPriceModuleName(pp.getProductPriceModuleName()); opp.setProductPriceTypeId(pp.getProductPriceTypeId()); opp.setSpecial(pps); Set priceDescriptions = pp.getPriceDescriptions(); if (priceDescriptions != null && priceDescriptions.size() > 0) { String priceDescription = ""; for (Object o : priceDescriptions) { ProductPriceDescription ppd = (ProductPriceDescription) o; if (ppd.getId().getLanguageId() == LanguageUtil .getLanguageNumberCode(locale.getLanguage())) { priceDescription = ppd.getProductPriceName(); break; } } opp.setProductPriceName(priceDescription); } productSet.add(opp); } scp.setPrices(productSet); } if (cservice.isProductSubscribtion(p)) { scp.setProductSubscribtion(true); } if (!p.isProductVirtual()) { scp.setShipping(true); } } return scp; }
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
public ProcessPuzzleLocale(Locale locale) { this(locale.getLanguage(), locale.getCountry(), locale.getVariant()); try {/*from w w w. ja v a 2s . c om*/ this.setLegalTender(new Currency("", java.util.Currency.getInstance(locale).toString())); } catch (IllegalArgumentException e) { } }
From source file:com.erudika.scoold.controllers.TranslateController.java
@GetMapping({ "/{locale}", "/{locale}/{index}" }) public String translate(@PathVariable String locale, @PathVariable(required = false) String index, HttpServletRequest req, Model model) { Locale showLocale = utils.getLangutils().getProperLocale(locale); if (showLocale == null || "en".equals(showLocale.getLanguage())) { // can't translate default language return "redirect:" + LANGUAGESLINK; }/* w w w . ja v a 2s . c o m*/ int showIndex = -1; List<Translation> translationslist = Collections.emptyList(); Pager itemcount = utils.getPager("page", req); if (!StringUtils.isBlank(index)) { showIndex = getIndex(index, langkeys); // this is what is currently shown for translation translationslist = utils.getLangutils().readAllTranslationsForKey(showLocale.getLanguage(), langkeys.get(showIndex), itemcount); } String title = utils.getLang(req).get("translate.title") + " - " + showLocale.getDisplayName(showLocale); int showLocaleProgress = utils.getLangutils().getTranslationProgressMap().get(showLocale.getLanguage()); model.addAttribute("path", "translate.vm"); model.addAttribute("title", title); model.addAttribute("showIndex", showIndex); model.addAttribute("showLocale", showLocale); model.addAttribute("langkeys", langkeys); model.addAttribute("deflang", deflang); model.addAttribute("showLocaleProgress", showLocaleProgress); model.addAttribute("translationslist", translationslist); model.addAttribute("itemcount", itemcount); return "base"; }
From source file:com.evolveum.midpoint.web.component.menu.top.LocaleDescriptor.java
@Override public int compareTo(LocaleDescriptor o) { if (o == null) { return 0; }/*from w w w . j a v a 2 s .c o m*/ Locale other = o.getLocale(); int val = compareStrings(locale.getCountry(), other.getCountry()); if (val != 0) { return val; } val = compareStrings(locale.getLanguage(), other.getLanguage()); if (val != 0) { return val; } val = compareStrings(locale.getVariant(), other.getVariant()); if (val != 0) { return val; } return 0; }