List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:eu.delving.core.util.MessageSourceRepo.java
private String objectKey(Locale locale) { if (locale != null) { return CONTENT + "_" + locale.getLanguage(); } else {/*from w w w . ja va 2 s .c o m*/ return CONTENT; } }
From source file:com.erudika.scoold.controllers.LanguagesController.java
@PostMapping("/{langkey}") public String post(@PathVariable String langkey, HttpServletRequest req, HttpServletResponse res) { Locale locale = utils.getCurrentLocale(langkey, req); if (locale != null) { int maxAge = 60 * 60 * 24 * 365; //1 year Utils.setRawCookie(LOCALE_COOKIE, locale.getLanguage(), req, res, false, maxAge); }//from w w w. ja v a2 s.co m return "redirect:" + languageslink; }
From source file:org.smigo.species.vernacular.JdbcVernacularDao.java
@Override public Vernacular getVernacularByName(String name, Locale locale) { final String sql = "SELECT * FROM VERNACULARS WHERE VERNACULAR_NAME=? AND LANGUAGE=? AND COUNTRY=?"; Object[] args = { name, locale.getLanguage(), locale.getCountry() }; return jdbcTemplate.queryForObject(sql, args, vernacularRowMapper); }
From source file:cn.vlabs.duckling.vwb.ui.servlet.AbstractLoginServlet.java
private void redirectToUmt(HttpServletRequest request, HttpServletResponse response, String viewUrl) throws IOException, ServletException { Oauth oauth = new Oauth(properties); int siteId = getVwbcontext(request).getSiteId(); VWBContainer container = VWBContainerImpl.findContainer(); Locale locale = request.getLocale(); String language = locale.getLanguage() + "_" + locale.getCountry(); if (!locale.equals(Locale.CHINA)) { language = Locale.US.getLanguage() + "_" + Locale.US.getCountry(); }// w w w . ja v a 2 s. c o m if (StringUtils.isEmpty(language)) { language = container.getSiteConfig().getProperty(siteId, KeyConstants.SITE_LANGUAGE); } try { String redirectUrl = oauth.getAuthorizeURL(request) + "&state=" + URLEncoder.encode(viewUrl, "UTF-8") + "&locale=" + language; response.sendRedirect(redirectUrl); } catch (UMTOauthConnectException e) { throw new ServletException(e); } }
From source file:org.iti.agrimarket.view.UserController.java
@RequestMapping(value = { "/profile.htm" }) public String getUserProfile(HttpServletRequest request, Locale locale, Model model) { String language = locale.getLanguage(); User user = (User) request.getSession().getAttribute("user"); if (user != null) { // for (Object col : user.getUserOfferProductFixeds()) { // UserOfferProductFixed fixed = (UserOfferProductFixed) col; // System.out.println("user offer product fixed" + fixed.getId()); // } // user=userService.getUserEager(user.getId()); model.addAttribute("user", user); }/*from w w w.j a v a 2 s . c o m*/ model.addAttribute("lang", locale); return "profile"; }
From source file:de.iew.web.taglibs.requirejs.I18n.java
@Override protected int doStartTagInternal() throws Exception { Locale renderLocale = getRenderLocale(); if (renderLocale != null) { StringBuffer sb = new StringBuffer("i18n:{"); sb.append("locale:'").append(renderLocale.getLanguage().toLowerCase()).append("-") .append(renderLocale.getCountry().toLowerCase()).append("'").append("}"); RequireJS requireJS = (RequireJS) getParent(); requireJS.addRenderedConfig(sb.toString()); }/*from ww w .j av a 2s.com*/ return SKIP_BODY; }
From source file:com.puppycrawl.tools.checkstyle.checks.FileSetCheckLifecycleTest.java
@Test public void testProcessCallsFinishBeforeCallingDestroy() throws Exception { DefaultConfiguration dc = new DefaultConfiguration("configuration"); DefaultConfiguration twConf = createCheckConfig(TreeWalker.class); dc.addAttribute("charset", "UTF-8"); dc.addChild(twConf);//w w w . j a v a 2 s .c o m twConf.addChild(new DefaultConfiguration(FileContentsHolder.class.getName())); twConf.addChild(new DefaultConfiguration(AvoidStarImportCheck.class.getName())); final Checker checker = new Checker(); final Locale locale = Locale.ROOT; checker.setLocaleCountry(locale.getCountry()); checker.setLocaleLanguage(locale.getLanguage()); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); checker.configure(dc); checker.addListener(new BriefLogger(stream)); checker.addFileSetCheck(new TestFileSetCheck()); final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; verify(checker, getPath("InputIllegalTokens.java"), expected); assertTrue("FileContent should be available during finishProcessing() call", TestFileSetCheck.isFileContentAvailable()); }
From source file:com.bellman.bible.android.Bible.java
public void initAll(Application application) { this.application = application; Log.i(TAG, "OS:" + System.getProperty("os.name") + " ver " + System.getProperty("os.version")); Log.i(TAG, "Java:" + System.getProperty("java.vendor") + " ver " + System.getProperty("java.version")); Log.i(TAG, "Java home:" + System.getProperty("java.home")); Log.i(TAG,/*from w w w . j a va 2s .c o m*/ "User dir:" + System.getProperty("user.dir") + " Timezone:" + System.getProperty("user.timezone")); // fix for null context class loader (http://code.google.com/p/android/issues/detail?id=5697) // this affected jsword dynamic classloading Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); installJSwordErrorReportListener(); // initialise link to Android progress control display in Notification bar ProgressNotificationManager.getInstance().initialise(); Locale locale = Locale.getDefault(); Log.i(TAG, "Locale language:" + locale.getLanguage() + " Variant:" + locale.getDisplayName()); // various initialisations required every time at app startup Initialisation.getInstance().initialiseEventually(); }
From source file:org.shredzone.cilla.plugin.flattr.FlattrLanguage.java
/** * Finds a Flattr {@link LanguageId} for the given {@link Locale}. The result is * cached. For generic locales (like "es"), an attempt is made to find a matching * common Flattr language ("es_ES").//from ww w . jav a2s. com * * @param locale * {@link Locale} to find a {@link LanguageId} for * @return {@link LanguageId} or {@code null} if this locale is not supported by * Flattr */ public LanguageId findLanguageId(Locale locale) { // Is there a locale and language set? if (locale == null || locale.getLanguage() == null || locale.getLanguage().isEmpty()) { return null; } // Fetch/update the language set updateLanguageSet(); // Variant is to be ignored completely // Check the language/country code (e.g. "en_US") for a perfect match if (locale.getCountry() != null && !locale.getCountry().isEmpty()) { String result = locale.getLanguage() + '_' + locale.getCountry(); if (languageSet.contains(result)) { return Language.withId(result); } } // Only check the language code (e.g. "fr") String language = locale.getLanguage(); // Check if there is a common transformation available String common = transformCommonCodes(language); if (languageSet.contains(common)) { return Language.withId(common); } // Find the next language code that starts with the language language += '_'; final String languageF = language; return languageSet.stream().filter(it -> it.startsWith(languageF)).map(Language::withId).findFirst() .orElse(null); // The language is not supported by Flattr }
From source file:de.alpharogroup.resourcebundle.properties.PropertiesFileExtensions.java
/** * Load the properties file from the given class object. The filename from the properties file * is the same as the simple name from the class object and it looks at the same path as the * given class object. If locale is not null than the language will be added to the filename * from the properties file.//from w w w. j a va 2 s. c o m * * @param clazz * the clazz * @param locale * the locale * @return the properties * @throws IOException * Signals that an I/O exception has occurred. */ public static Properties loadPropertiesFromClassObject(final Class<?> clazz, final Locale locale) throws IOException { if (null == clazz) { throw new IllegalArgumentException("Class object must not be null!!!"); } StringBuilder propertiesName = new StringBuilder(); Properties properties = null; String language = null; String filename = null; String pathAndFilename = null; File propertiesFile = null; String absoluteFilename = null; final String packagePath = PackageExtensions.getPackagePathWithSlash(clazz); final List<String> missedFiles = new ArrayList<>(); if (null != locale) { propertiesName.append(clazz.getSimpleName()); language = locale.getLanguage(); if ((null != language) && !language.isEmpty()) { propertiesName.append("_").append(language); } final String country = locale.getCountry(); if ((null != country) && !country.isEmpty()) { propertiesName.append("_").append(country); } propertiesName.append(FileExtension.PROPERTIES.getExtension()); filename = propertiesName.toString().trim(); pathAndFilename = packagePath + filename; URL url = ClassExtensions.getResource(clazz, filename); if (url != null) { absoluteFilename = url.getFile(); } else { missedFiles.add("File with filename '" + filename + "' does not exists."); } if (null != absoluteFilename) { propertiesFile = new File(absoluteFilename); } if ((null != propertiesFile) && propertiesFile.exists()) { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); } else { propertiesName = new StringBuilder(); if (null != locale) { propertiesName.append(clazz.getSimpleName()); language = locale.getLanguage(); if ((null != language) && !language.isEmpty()) { propertiesName.append("_").append(language); } propertiesName.append(FileExtension.PROPERTIES.getExtension()); filename = propertiesName.toString().trim(); pathAndFilename = packagePath + filename; url = ClassExtensions.getResource(clazz, filename); if (url != null) { absoluteFilename = url.getFile(); } else { missedFiles.add("File with filename '" + filename + "' does not exists."); } if (null != absoluteFilename) { propertiesFile = new File(absoluteFilename); } if ((null != propertiesFile) && propertiesFile.exists()) { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); } } } } if (null == properties) { propertiesName = new StringBuilder(); propertiesName.append(clazz.getSimpleName()).append(FileExtension.PROPERTIES.getExtension()); filename = propertiesName.toString().trim(); pathAndFilename = packagePath + filename; final URL url = ClassExtensions.getResource(clazz, filename); if (url != null) { absoluteFilename = url.getFile(); } else { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); missedFiles.add("File with filename '" + filename + "' does not exists."); } if (null != absoluteFilename) { propertiesFile = new File(absoluteFilename); } if ((null != propertiesFile) && propertiesFile.exists()) { properties = PropertiesFileExtensions.loadProperties(pathAndFilename); } } return properties; }