List of usage examples for java.util Locale Locale
public Locale(String language)
From source file:egovframework.rte.tex.com.web.EgovCommonController.java
/** * ? ? ??.// w w w.j ava2 s .c om * @return "main/EgovMain" * @exception Exception */ @RequestMapping(value = "/com/egovMain.do", method = RequestMethod.GET) protected String changeLocale(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception { Locale locale = new Locale("kr"); //default = kr if (request.getParameter("locale") == null) { locale = localeResolver.resolveLocale(request); } else { locale = new Locale(request.getParameter("locale")); } // localeResolver? locale System.out.println("locale -------------- " + locale); localeResolver.setLocale(request, response, locale); MemberVO loginVO = EgovUserUtil.getMemberInfo(); model.addAttribute("loginVO", loginVO); return "main/EgovMain"; }
From source file:com.googlecode.l10nmavenplugin.model.PropertiesFileUtils.java
/** * Reverse logic of {@link Locale#toString} * //from www .j a v a 2s.co m * @param localeString * @return */ public static Locale getLocale(String localeString) { Locale locale = null; if (!StringUtils.isEmpty(localeString)) { String[] parts = localeString.split("_", MAX_LOCALE_PARTS); if (parts.length == 1) { locale = new Locale(parts[0]); } else if (parts.length == 2) { locale = new Locale(parts[0], parts[1]); } else if (parts.length == MAX_LOCALE_PARTS) { locale = new Locale(parts[0], parts[1], parts[2]); } } return locale; }
From source file:com.ocs.dynamo.utils.PasteUtilsTest.java
@Test public void testTranslateSeparators() { Assert.assertEquals("2,3", PasteUtils.translateSeparators("2,3", new Locale("nl"))); Assert.assertEquals("2,3", PasteUtils.translateSeparators("2.3", new Locale("nl"))); Assert.assertEquals("2.3", PasteUtils.translateSeparators("2,3", new Locale("us"))); Assert.assertEquals("2.3", PasteUtils.translateSeparators("2.3", new Locale("us"))); }
From source file:fi.helsinki.opintoni.util.CoursePageUriBuilderTest.java
@Test public void thatEmptyCoursePageReturnsNullLocalizedUri() { CoursePageCourseImplementation coursePage = new CoursePageCourseImplementation(); LocaleContextHolder.setLocale(new Locale("en")); assertThat(coursePageUriBuilder.getLocalizedUri(coursePage)).isNull(); LocaleContextHolder.setLocale(new Locale("fi")); assertThat(coursePageUriBuilder.getLocalizedUri(coursePage)).isNull(); LocaleContextHolder.setLocale(new Locale("sv")); assertThat(coursePageUriBuilder.getLocalizedUri(coursePage)).isNull(); }
From source file:fr.itinerennes.bundler.tasks.FeedInfoTask.java
@Override protected void execute() { final FeedInfo gFeedInfo = gtfs.getAllFeedInfos().iterator().next(); final Agency gAgency = gtfs.getAllAgencies().iterator().next(); final TimeZone tz = xGtfs.getTimeZone(gAgency.getId()); final fr.itinerennes.api.client.model.FeedInfo infos = new fr.itinerennes.api.client.model.FeedInfo(); infos.setPublisherName(gFeedInfo.getPublisherName()); infos.setPublisherUrl(gFeedInfo.getPublisherUrl()); infos.setLang(new Locale(gFeedInfo.getLang())); infos.setStart(gFeedInfo.getStartDate().getAsCalendar(tz).getTime()); infos.setEnd(gFeedInfo.getEndDate().getAsCalendar(tz).getTime()); infos.setVersion(gFeedInfo.getVersion()); final fr.itinerennes.api.client.model.Agency agency = new fr.itinerennes.api.client.model.Agency(); agency.setId(gAgency.getId());/*from w w w. j a v a 2 s .c o m*/ agency.setLang(new Locale(gAgency.getLang())); agency.setName(gAgency.getName()); agency.setPhone(gAgency.getPhone()); agency.setUrl(gAgency.getUrl()); agency.setTimezone(tz); try { write(infos, new File(output), "infos.json"); write(agency, new File(output, "agency"), String.format("%s.json", agency.getId())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:cz.muni.fi.mushroomhunter.restclient.AllMushroomsSwingWorker.java
@Override protected void done() { try {// w ww . j av a 2 s . c om get(); } catch (Exception e) { restClient.getlMessageMushrooms().setText("ERROR: server is unavailable."); return; } try { List<MushroomDto> list = get(); DefaultTableModel model = (DefaultTableModel) restClient.getTblMushroom().getModel(); model.setRowCount(0); for (int i = 0; i < list.size(); i++) { RestClient.getMushroomIDs().add(list.get(i).getId()); SimpleDateFormat MMMMFormat = new SimpleDateFormat("MMMM", new Locale("en_US")); String startOfOccurence = MMMMFormat.format(list.get(i).getStartOfOccurence()); String endOfOccurence = MMMMFormat.format(list.get(i).getEndOfOccurence()); model.addRow(new Object[] { list.get(i).getName(), list.get(i).getType().toString(), startOfOccurence, endOfOccurence }); } } catch (ExecutionException ex) { } catch (InterruptedException ex) { throw new RuntimeException("Operation interrupted", ex); } }
From source file:fi.helsinki.opintoni.web.rest.privateapi.RecommendationResourceTest.java
private void testCourseRecommendationsWithLocale(String languageCode, String expectedTitle, String expectedLink) throws Exception { leikiServer.expectCourseRecommendationsResult(STUDENT_NUMBER, "courserecommendationresults.json"); mockMvc.perform(// www . j a va 2 s .co m get("/api/private/v1/recommendations/courses").with(securityContext(studentSecurityContext())) .locale(new Locale(languageCode)).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(2))) .andExpect(jsonPath("$[0].title").value(expectedTitle)) .andExpect(jsonPath("$[0].link").value(expectedLink)); }
From source file:at.alladin.rmbt.controlServer.SyncResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/*from w ww . jav a2s . c om*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; System.out.println(MessageFormat.format(labels.getString("NEW_SYNC_REQUEST"), getIP())); if (entity != null && !entity.isEmpty()) // try parse the string to a JSON object try { request = new JSONObject(entity); String lang = request.optString("language"); // Load Language Files for Client final List<String> langs = Arrays .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) { errorList.setLanguage(lang); labels = ResourceManager.getSysMsgBundle(new Locale(lang)); } else lang = settings.getString("RMBT_DEFAULT_LANGUAGE"); // System.out.println(request.toString(4)); if (conn != null) { final JSONArray syncList = new JSONArray(); UUID uuid = null; if (request.optString("uuid").length() > 0) uuid = UUID.fromString(request.getString("uuid")); if (uuid != null && request.optString("sync_code").length() == 0) { String syncCode = ""; try { final PreparedStatement st = conn .prepareStatement("SELECT rmbt_get_sync_code(CAST (? AS UUID)) AS code"); st.setString(1, uuid.toString()); final ResultSet rs = st.executeQuery(); if (rs.next()) syncCode = rs.getString("code"); else errorList.addError("ERROR_DB_GET_SYNC_SQL"); // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); rs.close(); st.close(); } catch (final SQLException e) { e.printStackTrace(); errorList.addError("ERROR_DB_GET_SYNC_SQL"); // errorList.addError("ERROR_DB_GET_CLIENT_SQL"); } if (errorList.getLength() == 0) { final JSONObject jsonItem = new JSONObject(); //lower case code is easier to enter on mobile devices jsonItem.put("sync_code", syncCode.toLowerCase(Locale.US)); syncList.put(jsonItem); } } else if (uuid != null && request.optString("sync_code").length() > 0) { final String syncCode = request.getString("sync_code").toUpperCase(Locale.US); int syncGroup1 = 0; int uid1 = 0; int syncGroup2 = 0; int uid2 = 0; String msgTitle = labels.getString("SYNC_SUCCESS_TITLE"); String msgText = labels.getString("SYNC_SUCCESS_TEXT"); boolean error = false; try { PreparedStatement st = conn.prepareStatement( "SELECT * FROM client WHERE sync_code = ? AND sync_code_timestamp + INTERVAL '1 month' > NOW()"); st.setString(1, syncCode); ResultSet rs = st.executeQuery(); if (rs.next()) { syncGroup1 = rs.getInt("sync_group_id"); uid1 = rs.getInt("uid"); } else { msgTitle = labels.getString("SYNC_CODE_TITLE"); msgText = labels.getString("SYNC_CODE_TEXT"); error = true; // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); } rs.close(); st.close(); st = conn.prepareStatement("SELECT * FROM client WHERE uuid = CAST(? AS UUID)"); st.setString(1, uuid.toString()); rs = st.executeQuery(); if (rs.next()) { syncGroup2 = rs.getInt("sync_group_id"); uid2 = rs.getInt("uid"); } else { msgTitle = labels.getString("SYNC_UUID_TITLE"); msgText = labels.getString("SYNC_UUID_TEXT"); error = true; // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); } rs.close(); st.close(); if (syncGroup1 > 0 && syncGroup1 == syncGroup2) { msgTitle = labels.getString("SYNC_GROUP_TITLE"); msgText = labels.getString("SYNC_GROUP_TEXT"); error = true; } if (uid1 > 0 && uid1 == uid2) { msgTitle = labels.getString("SYNC_CLIENT_TITLE"); msgText = labels.getString("SYNC_CLIENT_TEXT"); error = true; } if (!error) if (syncGroup1 == 0 && syncGroup2 == 0) { int key = 0; // create new group st = conn.prepareStatement("INSERT INTO sync_group(tstamp) " + "VALUES(now())", Statement.RETURN_GENERATED_KEYS); int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_STORE_SYNC_GROUP"); else { rs = st.getGeneratedKeys(); if (rs.next()) // Retrieve the auto generated // key(s). key = rs.getInt(1); rs.close(); } st.close(); if (key > 0) { st = conn.prepareStatement( "UPDATE client SET sync_group_id = ? WHERE uid = ? OR uid = ?"); st.setInt(1, key); st.setInt(2, uid1); st.setInt(3, uid2); affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); } } else if (syncGroup1 == 0 && syncGroup2 > 0) { // add 1 to 2 st = conn.prepareStatement("UPDATE client SET sync_group_id = ? WHERE uid = ?"); st.setInt(1, syncGroup2); st.setInt(2, uid1); final int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); } else if (syncGroup1 > 0 && syncGroup2 == 0) { // add 2 to 1 st = conn .prepareStatement("UPDATE client SET sync_group_id = ? WHERE uid = ? "); st.setInt(1, syncGroup1); st.setInt(2, uid2); final int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); } else if (syncGroup1 > 0 && syncGroup2 > 0) { // add all of 2 to 1 st = conn.prepareStatement( "UPDATE client SET sync_group_id = ? WHERE sync_group_id = ?"); st.setInt(1, syncGroup1); st.setInt(2, syncGroup2); int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); else { // Delete empty group st = conn.prepareStatement("DELETE FROM sync_group WHERE uid = ?"); st.setInt(1, syncGroup2); affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_DELETE_SYNC_GROUP"); } } } catch (final SQLException e) { e.printStackTrace(); errorList.addError("ERROR_DB_GET_SYNC_SQL"); // errorList.addError("ERROR_DB_GET_CLIENT_SQL"); } if (errorList.getLength() == 0) { final JSONObject jsonItem = new JSONObject(); jsonItem.put("msg_title", msgTitle); jsonItem.put("msg_text", msgText); jsonItem.put("success", !error); syncList.put(jsonItem); } } answer.put("sync", syncList); } else errorList.addError("ERROR_DB_CONNECTION"); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSDON Data " + e.toString()); } else errorList.addErrorString("Expected request is missing."); try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); return answerString; }
From source file:edu.kit.trufflehog.model.configdata.PropertiesDataModelTest.java
/** * <p>/*from w ww .ja v a2 s. com*/ * Tests whether the german property file can be loaded and whether the test property can be accessed. * </p> * * @throws Exception Passes any errors that occurred during the test on */ @Test @Ignore public void testDe() throws Exception { this.propertiesDataModel = new PropertiesDataModel(new Locale("de"), fileSystem); String value = propertiesDataModel.get("test_property"); assertEquals("das ist ein test", value); }
From source file:ch.silviowangler.dox.TranslationServiceImpl.java
@Override @Transactional(readOnly = true, propagation = SUPPORTS) public String findTranslation(String key, Locale locale) throws NoTranslationFoundException { logger.debug("Trying to find message for key '{}' and locale '{}'", key, locale.getDisplayName()); Translation translation = translationRepository.findByKeyAndLocale(key, locale); if (translation == null) { final Locale fallbackLocale = new Locale(locale.getLanguage()); logger.debug("No translation found for key '{}' and locale '{}'. Falling back to locale '{}'", new Object[] { key, locale.getDisplayName(), fallbackLocale.getDisplayName() }); translation = translationRepository.findByKeyAndLocale(key, fallbackLocale); if (translation == null && !fallbackLocale.equals(GERMAN)) { translation = translationRepository.findByKeyAndLocale(key, GERMAN); if (translation == null) { logger.warn("No translation found for key '{}' and locale '{}'", key, locale); throw new NoTranslationFoundException(key, locale); }/* ww w . j a v a2 s . c o m*/ return translation.getLanguageSpecificTranslation(); } else { logger.debug("Found translation of key '{}' using fallback locale '{}'", key, fallbackLocale.getDisplayName()); if (translation == null) throw new NoTranslationFoundException(key, locale); return translation.getLanguageSpecificTranslation(); } } else { logger.debug("Found translation of key '{}' on first attempt using locale '{}'", key, locale.getDisplayName()); return translation.getLanguageSpecificTranslation(); } }