private List<MessageResourceEntry> convertMessageMapToResourceEntries(List<TableEntry> input) { Map<String, MessageResourceEntry> entries = new HashMap<String, MessageResourceEntry>(input.size()); for (TableEntry entry : input) { if (entries.containsKey(entry.getCodeId())) { entries.get(entry.getCodeId()).addLang(LocaleUtils.toLocale(entry.getLangId()), entry.message); } else { MessageResourceEntry data = new MessageResourceEntry(); data.setCodeId(entry.getCodeId()); data.addLang(LocaleUtils.toLocale(entry.getLangId()), entry.getMessage()); data.setType(entry.getType()); entries.put(entry.getCodeId(), data); } } List<MessageResourceEntry> result = new ArrayList<MessageResourceEntry>(entries.size()); result.addAll(entries.values()); return result; }
/** * {@inheritDoc} * * @see MessageManagementService#putMessage(java.lang.String, java.util.Locale, * java.lang.String) */ @Override public void putMessage(String codeId, Locale locale, String message, String type) throws I18nException { Assert.hasLength(codeId); Assert.notNull(locale); LocaleUtils.toLocale(locale.toString()); // this validates the locale Assert.hasLength(message); MessageResource persisted = this.messageSourceDao.findTopByCodeAndLang(codeId, locale.toString()); if (persisted != null) { //update case persisted.message(message).type(type); } else { //insert case persisted = new MessageResource() .code(codeId) .lang(locale.toString()) .message(message) .type(type); persisted.id((type == null ? "" : type) + codeId + locale.toString()); } this.messageSourceDao.save(persisted); }
private List<MessageResourceEntry> convertMessageMapToResourceEntries(List<MessageResource> input) { Map<String, MessageResourceEntry> entries = new HashMap<>(input.size()); for (MessageResource entry : input) { if (entries.containsKey(entry.getCode())) { entries.get(entry.getCode()).addLang(LocaleUtils.toLocale(entry.getLang()), entry.getMessage()); } else { MessageResourceEntry data = new MessageResourceEntry(); data.setCodeId(entry.getCode()); data.addLang(LocaleUtils.toLocale(entry.getLang()), entry.getMessage()); data.setType(entry.getType()); entries.put(entry.getCode(), data); } } List<MessageResourceEntry> result = new ArrayList<>(entries.size()); result.addAll(entries.values()); return result; }
@Override public List<String> splitSentences(String text, String language_code) throws Exception { LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200))); List<String> sentences = new ArrayList<String>(); text = de.tudarmstadt.lt.utilities.StringUtils.trim_and_replace_emptyspace(text, " "); for(LineIterator iter = new LineIterator(new StringReader(text)); iter.hasNext();){ String line = iter.nextLine(); BreakIterator sentence_bounds = BreakIterator.getSentenceInstance(LocaleUtils.toLocale(language_code)); sentence_bounds.setText(line); int begin_s = sentence_bounds.first(); for (int end_s = sentence_bounds.next(); end_s != BreakIterator.DONE; begin_s = end_s, end_s = sentence_bounds.next()) { String sentence = de.tudarmstadt.lt.utilities.StringUtils.trim(line.substring(begin_s, end_s)); if(sentence.isEmpty()) continue; sentences.add(sentence); LOG.trace(String.format("Current sentence: %s", StringUtils.abbreviate(sentence, 200))); } } LOG.trace(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200), sentences.size())); return sentences; }
@Override public RestUserSessionInfo getSessionInfoByTokenValue(String tokenValue) { RestUserSessionInfo sessionInfo = accessTokenValueToSessionInfoStore.get(tokenValue); if (sessionInfo == null && serverConfig.getRestStoreTokensInDb()) { AccessToken accessToken = getAccessTokenByTokenValueFromDatabase(tokenValue); if (accessToken != null) { String localeStr = accessToken.getLocale(); if (!Strings.isNullOrEmpty(localeStr)) { Locale locale = LocaleUtils.toLocale(localeStr); return new RestUserSessionInfo(null, locale); } } } return sessionInfo; }
/** * Get the defaultLocale of current domain. * * @param request * the HTTP request * @return the defaultLocale of current domain, null if not specified or * domain is null. */ private Locale getDomainDefaultLocale(final HttpServletRequest request) { Domain domain = DomainFilter.getDomain(request); if (domain != null) { String defaultLocale = domain.getConfiguration().get( "defaultLocale"); if (DEBUG) { LOG.debug("domain default locale: " + defaultLocale); } return LocaleUtils.toLocale(defaultLocale); } else { if (DEBUG) { LOG.debug("domain is null."); } return null; } }
public Locale onLocale() { String _langStr = null; // 先尝试取URL参数变量 if (WebContext.getContext() != null) { _langStr = WebContext.getRequestContext().getAttribute(I18N_LANG_KEY); if (StringUtils.trimToNull(_langStr) == null) { // 再尝试从请求参数中获取 _langStr = WebContext.getRequest().getParameter(I18N_LANG_KEY); if (StringUtils.trimToNull(_langStr) == null) { // 最后一次机会,尝试读取Cookies _langStr = CookieHelper.bind(WebContext.getContext().getOwner()).getCookie(I18N_LANG_KEY).toStringValue(); } } } Locale _locale = null; try { _locale = LocaleUtils.toLocale(StringUtils.trimToNull(_langStr)); } catch (IllegalArgumentException e) { _locale = WebContext.getContext().getLocale(); } return _locale; }
private static void initMessageSource() { locale = LocaleUtils.toLocale(CoreGlobalProperty.LOCALE); logger.debug(String.format("using locale[%s] for i18n logging messages", locale.toString())); if (loader == null) { throw new CloudRuntimeException("ComponentLoader is null. i18n has not been initialized, you call it too early"); } BeanFactory beanFactory = loader.getSpringIoc(); if (beanFactory == null) { throw new CloudRuntimeException("BeanFactory is null. i18n has not been initialized, you call it too early"); } if (!(beanFactory instanceof MessageSource)) { throw new CloudRuntimeException("BeanFactory is not a spring MessageSource. i18n cannot be used"); } messageSource = (MessageSource)beanFactory; }
@Override public void init(NamedList args) { Locale locale = Locale.ROOT; String localeParam = (String)args.remove(LOCALE_PARAM); if (null != localeParam) { locale = LocaleUtils.toLocale(localeParam); } Object defaultTimeZoneParam = args.remove(DEFAULT_TIME_ZONE_PARAM); DateTimeZone defaultTimeZone = DateTimeZone.UTC; if (null != defaultTimeZoneParam) { defaultTimeZone = DateTimeZone.forID(defaultTimeZoneParam.toString()); } Collection<String> formatsParam = args.removeConfigArgs(FORMATS_PARAM); if (null != formatsParam) { for (String value : formatsParam) { formats.put(value, DateTimeFormat.forPattern(value).withZone(defaultTimeZone).withLocale(locale)); } } super.init(args); }
protected Locale getLocale() { if (locale != null) return locale; locale = Locale.getDefault(); Object obj = null; if (jConfig.getJRParameters() != null) { obj = jConfig.getJRParameters().get(JRParameter.REPORT_LOCALE); if (obj == null) { String str = jConfig.getProperty(JRFiller.PROPERTY_DEFAULT_LOCALE); if (str != null) obj = LocaleUtils.toLocale(str); } } if (obj != null && obj instanceof Locale) locale = (Locale) obj; return locale; }
/** * * * @param locale */ private void addToChoiceBox(Locale locale, String translation) { Locale defaultLocale = Locale.getDefault(); String defaultLocaleFromProperties = this.cfg.getProp(ConfigString.DEFAULT_LOCALE); if (!defaultLocaleFromProperties.isEmpty()) { defaultLocale = LocaleUtils.toLocale(defaultLocaleFromProperties); } // String language = locale.getDisplayLanguage(); languageBox.getItems().add(translation); if (locale == Locale.GERMAN) { } if (locale.getLanguage().equals(defaultLocale.getLanguage())) { languageBox.getSelectionModel().select(translation); } }
/** * Send an email by processing a template with request form parameters and the recipient * {@link org.obiba.agate.domain.User} as a context. The Template is expected to be located in a folder having * the application name. * * @param subject * @param templateName * @param context * @param recipients */ private void sendTemplateEmail(String subject, String templateName, Map<String, String[]> context, Set<User> recipients) { org.thymeleaf.context.Context ctx = new org.thymeleaf.context.Context(); context.forEach((k, v) -> { if(v != null && v.length == 1) { ctx.setVariable(k, v[0]); } else { ctx.setVariable(k, v); } }); String templateLocation = getApplicationName() + "/" + templateName; recipients.forEach(rec -> { ctx.setVariable("user", rec); ctx.setLocale(LocaleUtils.toLocale(rec.getPreferredLanguage())); mailService .sendEmail(rec.getEmail(), subject, templateEngine.process(templateLocation, ctx)); }); }
@NotNull Configuration fromDto(@NotNull Agate.ConfigurationDtoOrBuilder dto) { Configuration configuration = new Configuration(); configuration.setName(dto.getName()); if(dto.hasDomain()) configuration.setDomain(dto.getDomain()); if(dto.hasPublicUrl()) configuration.setPublicUrl(dto.getPublicUrl()); dto.getLanguagesList().forEach(lang -> configuration.getLocales().add(LocaleUtils.toLocale(lang))); configuration.setShortTimeout(dto.getShortTimeout()); configuration.setLongTimeout(dto.getLongTimeout()); configuration.setInactiveTimeout(dto.getInactiveTimeout()); configuration.setJoinWithUsername(dto.getJoinWithUsername()); if(dto.getUserAttributesCount() > 0) dto.getUserAttributesList().forEach(c -> configuration.addUserAttribute(fromDto(c))); if(dto.hasStyle()) configuration.setStyle(dto.getStyle()); if(dto.getTranslationsCount() > 0) configuration.setTranslations(localizedStringDtos.fromDto(dto.getTranslationsList())); return configuration; }
public void resetPassword(User user) throws IOException { ObjectMapper mapper = new ObjectMapper(); String keyData = mapper.writeValueAsString(new HashMap<String, String>() {{ put("username", user.getName()); put("expire", DateTime.now().plusHours(1).toString()); }}); String key = configurationService.encrypt(keyData); RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "registration."); Context ctx = new Context(); String organization = configurationService.getConfiguration().getName(); ctx.setLocale(LocaleUtils.toLocale(user.getPreferredLanguage())); ctx.setVariable("user", user); ctx.setVariable("organization", organization); ctx.setVariable("publicUrl", configurationService.getPublicUrl()); ctx.setVariable("key", key); mailService .sendEmail(user.getEmail(), "[" + organization + "] " + propertyResolver.getProperty("resetPasswordSubject"), templateEngine.process("resetPasswordEmail", ctx)); }
@Subscribe public void sendPendingEmail(UserJoinedEvent userJoinedEvent) throws SignatureException { log.info("Sending pending review email: {}", userJoinedEvent.getPersistable()); PropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "registration."); List<User> administrators = userRepository.findByRole("agate-administrator"); Context ctx = new Context(); User user = userJoinedEvent.getPersistable(); String organization = configurationService.getConfiguration().getName(); ctx.setLocale(LocaleUtils.toLocale(user.getPreferredLanguage())); ctx.setVariable("user", user); ctx.setVariable("organization", organization); ctx.setVariable("publicUrl", configurationService.getPublicUrl()); administrators.stream().forEach(u -> mailService .sendEmail(u.getEmail(), "[" + organization + "] " + propertyResolver.getProperty("pendingForReviewSubject"), templateEngine.process("pendingForReviewEmail", ctx))); mailService .sendEmail(user.getEmail(), "[" + organization + "] " + propertyResolver.getProperty("pendingForApprovalSubject"), templateEngine.process("pendingForApprovalEmail", ctx)); }
@Subscribe public void sendConfirmationEmail(UserApprovedEvent userApprovedEvent) throws SignatureException { log.info("Sending confirmation email: {}", userApprovedEvent.getPersistable()); PropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "registration."); Context ctx = new Context(); User user = userApprovedEvent.getPersistable(); String organization = configurationService.getConfiguration().getName(); ctx.setLocale(LocaleUtils.toLocale(user.getPreferredLanguage())); ctx.setVariable("user", user); ctx.setVariable("organization", organization); ctx.setVariable("publicUrl", configurationService.getPublicUrl()); ctx.setVariable("key", configurationService.encrypt(user.getName())); mailService .sendEmail(user.getEmail(), "[" + organization + "] " + propertyResolver.getProperty("confirmationSubject"), templateEngine.process("confirmationEmail", ctx)); }
public void onReadAvailableLanguages(ActionEvent event) throws IOException { this.availableLanguages.clear(); for (UploadItem item : this.uploadedConcepts) { byte[] fileData; if (item.isTempFile()) { fileData = FileUtils.readFileToByteArray(item.getFile()); } else { fileData = item.getData(); } String xml = new String(fileData); String[] languages = metaDataFacade.getLanguagesAvailableForImport( xml); for (String lang : languages) { lang = lang.replaceAll("-", "_"); Locale locale = LocaleUtils.toLocale(lang); this.availableLanguages.put(locale.getDisplayLanguage(), lang); } } }
@Override public Locale localeForCommandSender(CommandSender sender) { if(sender instanceof BlockCommandSender) return commandBlockLocale; if(sender instanceof ConsoleCommandSender) return consoleLocale; if(sender instanceof RemoteConsoleCommandSender) return remoteConsoleLocale; if(sender instanceof Player) return LocaleUtils.toLocale(fetcher.getLocaleForPlayer((Player) sender)); return Locale.ENGLISH; }
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skipInit) { getLog().info("Skiping initialize site."); return; } Locale loc = null; if (StringUtils.isNotEmpty(locale)) { loc = LocaleUtils.toLocale(locale); } try { siteManager.initialize(baseDirectory, loc); } catch (Exception e) { throw new MojoFailureException(e.getMessage(), e); } }
private void updateThemeConfigurationFile(SiteConfigImpl siteConfig, File themeDir) throws MojoFailureException{ File config = new File(themeDir, "theme.yml"); if (!config.exists()) { throw new MojoFailureException("Config file '" + config + "' not exists."); } Locale loc = Locale.getDefault(); //locale from parameter String localeString = locale; //locale from site configuration if(StringUtils.isBlank(localeString)){ localeString = siteConfig.get("locale"); } if (StringUtils.isNotEmpty(localeString)) { loc = LocaleUtils.toLocale(localeString); } File localeConfig = new File(themeDir, "theme_" + loc.toString() + ".yml"); if (localeConfig.exists()) { config.renameTo(new File(themeDir, "theme-original.yml")); localeConfig.renameTo(config); } }
@SuppressWarnings("unchecked") private static Locale getBestFitLocale(Locale _locale, Collection<Locale> _locales) { List<Locale> lookups = (List<Locale>) LocaleUtils.localeLookupList(_locale); for (Locale lookup : lookups) { if (_locales.contains(lookup)) { return lookup; } } // There is no best fit, return English as the default locale return Locale.ENGLISH; }
private List<Locale> convertStringLangsToLocale(List<String> languages) { List<Locale> locales = new ArrayList<>(languages.size()); for (String lang : languages) { locales.add(LocaleUtils.toLocale(lang)); } return locales; }
public void writePropertiesSet( List<MessageResourceEntry> entries, String defaultLanguage, String resourceName, File outputDir, String encoding, long lastModified) { this.writePropertiesSet(entries, LocaleUtils.toLocale(defaultLanguage), resourceName, outputDir, encoding, lastModified); }
/** * resolves fallbacks by configured scenarios. * * @param code code to get the fallback message for * @param locale the original locale, including possibel variants * @param country the language + country locale * @param language the language only locale */ private String getScenarioFallback(String code, Locale locale, Locale country, Locale language) { // fallback scenarios if (LOG.isDebugEnabled()) { LOG.debug("Use further fallbacks based on configuration for code[" + code + "] lang[" + locale + "]"); } List<String> locales = this.messageSourceDao.findDistinctLang(); // fallback languages are based on any existing matching locale de de_CH de_CH_xyz boolean langKnown = locales.contains(locale.toString()) || locales.contains(country.toString()) || locales.contains(language.toString()); if (this.fallbackForUnknownLanguages && !langKnown || this.fallbackForKnownLanguages && langKnown) { for (Entry<Integer, String> fallback : this.fallbacks.entrySet()) { String msg = this.getMessageForLocaleFromBackend(code, LocaleUtils.toLocale(fallback.getValue())); if (StringUtils.hasText(msg)) { if (LOG.isDebugEnabled()) { LOG.debug("found fallback for code [" + code + "] lang[" + locale + "] :" + msg); } return msg; } } } return null; }
private Locale getLocaleFromFileName(String fileName) { if (StringUtils.indexOf(fileName, "_") == -1) { return null; } String ext = FileUtils.getFileExt(fileName); String fileNameWithoutExt = StringUtils.substringBefore(fileName, ext); try { return LocaleUtils.toLocale(StringUtils.substring(fileNameWithoutExt, fileNameWithoutExt.length() - 5, fileNameWithoutExt.length())); } catch (Exception e) { return null; } }
@Override public List<String> tokenizeSentence_intern(String sentence, String language_code){ ArrayList<String> tokens = new ArrayList<String>(); BreakIterator token_bounds = BreakIterator.getWordInstance(LocaleUtils.toLocale(language_code)); token_bounds.setText(sentence.trim()); int begin_t = token_bounds.first(); for (int end_t = token_bounds.next(); end_t != BreakIterator.DONE; begin_t = end_t, end_t = token_bounds.next()) { String token = de.tudarmstadt.lt.utilities.StringUtils.trim_and_replace_emptyspace(sentence.substring(begin_t, end_t), "_"); if(!token.isEmpty()){ // add token iff token is not empty tokens.add(token); } } return tokens; }
@Test public void test() { final String lang = "de_DE"; final Locale loc = new Locale(lang); System.out.println(loc.GERMANY); System.out.println(loc); final Locale loc2 = LocaleUtils.toLocale(lang); System.out.println(loc2); }
@Override public Object build(String string) { if (string == null) return null; return Arrays.stream(string.split(";")) .map(item -> item.split("\\|")) .collect(Collectors.toMap( parts -> parts[0], parts -> LocaleUtils.toLocale(parts[1]) )); }
protected Locale getUserLocale(LocalizedCredentials credentials, User user) { Locale userLocale = null; if (credentials.isOverrideLocale()) { userLocale = credentials.getLocale(); } if (userLocale == null) { if (user.getLanguage() != null) { userLocale = LocaleUtils.toLocale(user.getLanguage()); } else { userLocale = messages.getTools().trimLocale(messages.getTools().getDefaultLocale()); } } return userLocale; }
@RequestMapping(value = "", method = RequestMethod.POST) public FormValidationResultDto createUser(@RequestBody @Valid UserForm userForm, BindingResult bindingResult) { log.debug("save() - userForm: " + userForm); if (bindingResult.hasErrors()) { List<FormErrorDto> formErrors = ValidationUtil.extractFormErrors(bindingResult); return new FormValidationResultDto(userForm, formErrors); } String userPassword = userService.generateUserPassword(); User user = userService.buildUser(userForm, userPassword); User savedUser = userService.createUser(user); userForm.setId(savedUser.getId()); Map<String, String> params = new HashMap<>(); params.put("email", user.getUsername()); params.put("password", userPassword); params.put("firstName", user.getFirstName()); params.put("lastName", user.getLastName()); params.put("accountActivationUrl", "http://localhost:8080/login#/?activation-key=" + user.getHashKey()); String subject = messageSource.getMessage("email.userAccountActivation.subject", null, LocaleUtils.toLocale(userForm.getSelectedLanguage().getSelectedLanguage().toLowerCase())); //TODO mailService.sendMail(user.getUsername(), params, MailService.USER_ACCOUNT_ACTIVATION_MAIL + "_" + userForm.getSelectedLanguage().getSelectedLanguage().toLowerCase(), subject); return new FormValidationResultDto(userForm); }
@Test public void testDoFilterInternalEmpty() throws ServletException, IOException { service.addLocale(LocaleUtils.toLocale("en_US")); assertEquals(0, Collections.list(request.getLocales()).size()); assertEquals(1, service.getAvailableLocales().size()); ualf.doFilterInternal(request, response, filterChain); Collection<Locale> locales = UserAgentLocalesFilter .getUserAgentLocales(request); assertTrue(locales.isEmpty()); }
@Test public void testDoFilterInternalDuplication() throws ServletException, IOException { request.addLocale(LocaleUtils.toLocale("en_US")); request.addLocale(LocaleUtils.toLocale("zh_CN")); request.addLocale(LocaleUtils.toLocale("en_US")); service.addLocale(LocaleUtils.toLocale("en_US")); service.addLocale(LocaleUtils.toLocale("ja_JP")); service.addLocale(LocaleUtils.toLocale("zh_CN")); service.addLocale(LocaleUtils.toLocale("zh_TW")); assertEquals(3, Collections.list(request.getLocales()).size()); assertEquals(4, service.getAvailableLocales().size()); ualf.doFilterInternal(request, response, filterChain); Collection<Locale> actualLocales = UserAgentLocalesFilter .getUserAgentLocales(request); assertEquals(2, actualLocales.size()); Collection<Locale> expectedLocales = new LinkedHashSet<Locale>(); expectedLocales.add(LocaleUtils.toLocale("en_US")); expectedLocales.add(LocaleUtils.toLocale("zh_CN")); ArrayAssert.assertEquals(expectedLocales.toArray(), actualLocales .toArray()); }
/** * Set the available locales. * * @param availableLocales * the available locales to set */ public void setAvailableLocales(final Collection<String> availableLocales) { this.availableLocales = new LinkedHashSet<Locale>(availableLocales .size()); for (String language : availableLocales) { this.availableLocales.add(LocaleUtils.toLocale(language)); } this.availableLocales = Collections .unmodifiableCollection(this.availableLocales); }
@Override public Locale getLocale() { Locale locale = null; String localeStr = getProperty(EnvParametersKeys.class.getName() + "." + EnvParametersKeys.DEFAULT_LOCALE.name()); if (StringUtils.isNotEmpty(localeStr)) { locale = LocaleUtils.toLocale(localeStr); } return locale == null ? DEFAULT_LOCALE : locale; }
@Override public void init(NamedList args) { String localeParam = (String)args.remove(LOCALE_PARAM); if (null != localeParam) { locale = LocaleUtils.toLocale(localeParam); } super.init(args); }
/** * Attempts to parse given String to an instance of a given class. The class may also * have a generic type. It will throw {@link java.lang.IllegalStateException} in case this * method was not able to parse the value. * * @param str String to parse * @param toClass a class to turn value into * @param generic generic class * @return parsed value, an instance of the given class */ public static Object parseString(String str, Class<?> toClass, Class<?> generic) { if (isBlank(str, toClass)) { return (String.class.isAssignableFrom(toClass)) ? "" : null; } if (isDateOrPeriod(toClass)) { return parseDateOrPeriod(toClass, str); } try { if (toClass.isEnum()) { Class<? extends Enum> enumClass = (Class<? extends Enum>) toClass; return Enum.valueOf(enumClass, str); } if (Collection.class.isAssignableFrom(toClass)) { return parseStringToCollection(str, toClass, generic); } else if (Map.class.isAssignableFrom(toClass)) { return parseStringToMap(str); } else if (Locale.class.isAssignableFrom(toClass)) { return LocaleUtils.toLocale(str); } else if (Byte[].class.isAssignableFrom(toClass)) { return ArrayUtils.toObject(str.getBytes()); } else { return MethodUtils.invokeStaticMethod(toClass, "valueOf", str); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException("Unable to parse value " + str + " to " + toClass, e); } }
private synchronized void processBundle(Bundle bundle) { for (String path : I18N_RESOURCES_PATHS) { Enumeration resources = bundle.getEntryPaths(path); if (resources != null) { while (resources.hasMoreElements()) { try { Object resource = resources.nextElement(); String fullPath = resource.toString(); String file = fullPath.replace(path, ""); int underscore = file.indexOf('_'); int dot = file.indexOf('.', underscore); if ("messages.properties".equals(file)) { addMsgs(DEFAULT_LOCALE, loadFromResource(bundle.getResource(fullPath))); } else if (underscore != -1 && dot != -1) { String fileName = FilenameUtils.getBaseName(file); String parts[] = fileName.split("_", 2); String langLong = parts[1]; // we want to handle locale such as zh_TW.Big5 String forLocaleUtils = langLong.replaceAll("\\.", "_"); Locale locale = LocaleUtils.toLocale(forLocaleUtils); String langFull = WordUtils.capitalize(locale.getDisplayLanguage(locale)); languages.put(langLong, langFull); addMsgs(locale, loadFromResource(bundle.getResource(fullPath))); } } catch (IOException e) { LOGGER.error("While reading resource from path {} from bundle {}", path, bundle); } } } } }
@Inject(optional = true) protected void setConfigurator(Configurator configurator) { Optional<FileConfiguration> configurationOptional = configurator.getConfig("locales"); if(configurationOptional.isPresent()) { FileConfiguration config = configurationOptional.get(); commandBlockLocale = LocaleUtils.toLocale(config.getString("commandBlock", "en_US")); remoteConsoleLocale = LocaleUtils.toLocale(config.getString("remoteConsole", "en_US")); consoleLocale = LocaleUtils.toLocale(config.getString("console", "en_US")); } }