public Locales(CommandManager manager) { this.manager = manager; this.localeManager = LocaleManager.create(manager::getIssuerLocale); this.addBundleClassLoader(this.getClass().getClassLoader()); }
public boolean addMessageBundle(String bundleName, Locale locale) { boolean found = false; for(ClassLoader classLoader: this.registeredClassLoaders) { if(this.addMessageBundle(classLoader, bundleName, locale)) { found = true; } } return found; }
public void loadLanguages() { addMessageBundles("acf-core"); }
@Override public void loadLanguages() { super.loadLanguages(); String pluginName = "acf-" + manager.plugin.getName(); addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase()); } }
public String formatMessage(CommandIssuer issuer, MessageType type, MessageKeyProvider key, String... replacements) { String message = getLocales().getMessage(issuer, key.getMessageKey()); if (replacements.length > 0) { message = ACFUtil.replaceStrings(message, replacements); } message = getCommandReplacements().replace(message); message = getLocales().replaceI18NStrings(message); MessageFormatter formatter = formatters.getOrDefault(type, defaultFormatter); if (formatter != null) { message = formatter.format(message); } return message; }
public Locale getIssuerLocale(CommandIssuer issuer) { if (usingPerIssuerLocale() && issuer != null) { Locale locale = issuersLocale.get(issuer.getUniqueId()); if (locale != null) { return locale; } } return getLocales().getDefaultLocale(); }
/** * Adds a new locale to the list of automatic Locales to load Message Bundles for. * All bundles loaded under the previous supported languages will now automatically load for this new locale too. * * @param locale */ public void addSupportedLanguage(Locale locale) { supportedLanguages.add(locale); getLocales().loadMissingBundles(); }
public String replaceI18NStrings(String message) { if (message == null) { return null; } Matcher matcher = ACFPatterns.I18N_STRING.matcher(message); if (!matcher.find()) { return message; } CommandIssuer issuer = CommandManager.getCurrentCommandIssuer(); matcher.reset(); StringBuffer sb = new StringBuffer(message.length()); while (matcher.find()) { MessageKey key = MessageKey.of(matcher.group("key")); matcher.appendReplacement(sb, Matcher.quoteReplacement(getMessage(issuer, key))); } matcher.appendTail(sb); return sb.toString(); }
@Override public void loadLanguages() { super.loadLanguages(); String pluginName = "acf-" + manager.plugin.getDescription().getName(); addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase()); } }
value = value.toLowerCase(manager.getLocales().getDefaultLocale()); } else if (hasOption(options, UPPERCASE)) { value = value.toUpperCase(manager.getLocales().getDefaultLocale());
@Override public void loadLanguages() { super.loadLanguages(); String pluginName = "acf-" + manager.plugin.getDescription().getName(); addMessageBundles("acf-minecraft", pluginName, pluginName.toLowerCase()); }
public void addMessageBundles(String... bundleNames) { for (String bundleName : bundleNames) { //noinspection unchecked Set<Locale> supportedLanguages = manager.getSupportedLanguages(); for (Locale locale : supportedLanguages) { addMessageBundle(bundleName, locale); } } }
/** * Looks for all previously loaded bundles, and if any new Supported Languages have been added, load them. */ public void loadMissingBundles() { //noinspection unchecked Set<Locale> supportedLanguages = manager.getSupportedLanguages(); for (Locale locale : supportedLanguages) { for(SetMultimap<String, Locale> localeData: this.loadedBundles.values()) { for (String bundleName : new HashSet<>(localeData.keys())) { addMessageBundle(bundleName, locale); } } } }