/** * Resolves the {@link Locale} object from the given locale code. If not found the system * default locale will be taken. * * @param localeCode * the locale code * @return the {@link Locale} object. */ public static Locale resolveLocale(final String localeCode) { return resolveLocale(localeCode, true); }
/** * Resolves the locale from the given properties file. * * @param propertiesFile * the properties file * @param defaultLocale * the default locale * @param systemsDefault * if this flag is true the systems default locale will be taken if not found * @return the locale */ public static Locale resolveLocale(final File propertiesFile, final Locale defaultLocale, final boolean systemsDefault) { final String localeCode = propertiesFile.getName() .replaceAll("^" + resolveBundlename(propertiesFile) + "(_)?|\\.properties$", ""); return LocaleResolver.resolveLocale(localeCode, defaultLocale, systemsDefault); }
@Override protected void handleFile(final File file, final int depth, final Collection<File> results) throws IOException { final String localeCode = LocaleResolver.resolveLocaleCode(file); propertiesToLocale.put(file, localeCode); } };
/** * {@inheritDoc} */ @Override public List<BundleNames> importProperties(BundleApplications bundleApplication, List<KeyValuePair<File, Locale>> foundProperties) throws IOException { final List<BundleNames> list = new ArrayList<>(); for (final KeyValuePair<File, Locale> entry : foundProperties) { final File propertiesFile = entry.getKey(); final Locale locale = entry.getValue(); final String bundlename = LocaleResolver.resolveBundlename(propertiesFile); final Properties properties = PropertiesExtensions.loadProperties(propertiesFile); final BundleNames bundleNames = updateProperties(bundleApplication, properties, bundlename, locale, false); list.add(bundleNames); bundleApplication = bundleApplicationsService.merge(bundleApplication); } return list; }
/** * Resolves a {@link Locale} objects from the given language code. * * @param languageCode * the language code * @return the found {@link Locale} objects or an empty list if nothing found */ public static List<Locale> getLocales(@NonNull String languageCode) { List<Locale> locales = ListFactory.newArrayList(); getAvailableLocales().forEach(locale -> { if (locale.getLanguage().equals(languageCode)) { locales.add(locale); } }); return locales; }
/** * Resolves all the available Locales to the given resource bundle name in the given bundle * package. For now it is only for properties files. * * @param bundlepackage * The package that contains the properties files. * @param bundlename * The name of the resource bundle. * @return a Map of File objects with the corresponding Locales to it. */ public static Map<File, Locale> resolveLocales(final String bundlepackage, final String bundlename) { return resolveLocales(bundlepackage, bundlename, true); }
/** * Gets the display language name from the given language code in the given {@link Locale}. * * @param languageCode * the language code * @param inLocale * The locale for which to retrieve the display language * @return the language name */ public static String getLanguageName(String languageCode, Locale inLocale) { List<Locale> locales = LocaleResolver.getLocales(languageCode); Locale first = ListExtensions.getFirst(locales); if (first != null) { return first.getDisplayLanguage(inLocale); } return ""; }
/** * Gets the display country name from the given country code from the given {@link Locale}. If * not found the given default country name is returned. * * @param countryCode * the country code * @param inLocale * The locale for which to retrieve the display country * @param defaultCountryName * the default country name * @return the country name */ public static String getCountryName(String countryCode, Locale inLocale, String defaultCountryName) { Locale locale = LocaleResolver.getLocale(countryCode); if (locale != null) { return locale.getDisplayCountry(inLocale); } return defaultCountryName; }
/** * Resolves a {@link Locale} from the given country code. * * @param countryCode * the country code * @return the found {@link Locale} or null if not found */ public static Locale getLocale(@NonNull String countryCode) { List<Locale> locales = ListFactory.newArrayList(); getAvailableLocales().forEach(locale -> { if (locale.getCountry().equals(countryCode)) { locales.add(locale); } }); return ListExtensions.getFirst(locales); }
/** * Resolves the locale from the given properties file. * * @param propertiesFile * the properties file * @return the locale */ public static Locale resolveLocale(final File propertiesFile) { return LocaleResolver.resolveLocale(propertiesFile, true); }
/** * Resolves the {@link Locale} object from the given locale code. If the given default locale is * not null and the locale code does resolve to no locale the default locale will be returned. * * @param localeCode * the locale code * @param defaultLocale * the default locale * @param systemsDefault * if this flag is true the systems default locale will be taken if not found * otherwise not * @return the {@link Locale} object or null if not found and flag systemsDefault is false and * defaultLocale is null. */ public static Locale resolveLocale(final String localeCode, final Locale defaultLocale, final boolean systemsDefault) { Locale current = resolveLocaleCode(localeCode); if (current == null && defaultLocale != null) { current = defaultLocale; } if (current == null && systemsDefault) { current = Locale.getDefault(); } return current; }
/** * Resolves the {@link Locale} object from the given locale code. * * @param localeCode * the locale code * @param systemsDefault * if this flag is true the systems default locale will be taken if not found * otherwise not * @return the {@link Locale} object or null if not found and flag systemsDefault is false. */ public static Locale resolveLocale(final String localeCode, final boolean systemsDefault) { return resolveLocale(localeCode, null, systemsDefault); }
@Override public String getString(final BundleApplication bundleApplication, final String baseName, final String locale, final String key, final String defaultValue) { final BundleApplications owner = resourcebundlesService.find(bundleApplication.getName()); final Resourcebundles resourcebundles = resourcebundlesService.getResourcebundle(owner, baseName, LocaleResolver.resolveLocaleCode(locale), key); if (resourcebundles != null) { Resourcebundle domainObject = getMapper().toDomainObject(resourcebundles); return domainObject.getValue().getName(); } return defaultValue; }
/** * Resolves the locale from the given properties file. * * @param propertiesFile * the properties file * @param systemsDefault * if this flag is true the systems default locale will be taken if not found * @return the locale */ public static Locale resolveLocale(final File propertiesFile, final boolean systemsDefault) { return LocaleResolver.resolveLocale(propertiesFile, null, systemsDefault); }
@Override public String getString(final BundleApplication bundleApplication, final String baseName, final String locale, final String key) { final BundleApplications owner = resourcebundlesService.find(bundleApplication.getName()); final Resourcebundles resourcebundles = resourcebundlesService.getResourcebundle(owner, baseName, LocaleResolver.resolveLocaleCode(locale), key); if (resourcebundles != null) { Resourcebundle domainObject = getMapper().toDomainObject(resourcebundles); return domainObject.getValue().getName(); } return ""; }
/** * {@inheritDoc} */ @Override public Properties getProperties(BundleApplications owner, String baseName, String localeCode) { return getProperties(owner, baseName, LocaleResolver.resolveLocale(localeCode)); }
@Override public String getString(final BundleApplication bundleApplication, final String baseName, final String locale, final String key, final Object[] parameters) { final BundleApplications owner = resourcebundlesService.find(bundleApplication.getName()); final Resourcebundles resourcebundles = resourcebundlesService.getResourcebundle(owner, baseName, LocaleResolver.resolveLocaleCode(locale), key); String value = ""; if (resourcebundles != null) { Resourcebundle domainObject = getMapper().toDomainObject(resourcebundles); value = domainObject.getValue().getName(); value = ResourceBundleExtensions.format(value, parameters); } return value; }
@Override public Locale resolveLocale(LanguageLocales languageLocales) { Locale locale = null; if (languageLocales != null) { locale = LocaleResolver.resolveLocale(languageLocales.getLocale(), false); } return locale; }
@Override public String getString(final BundleApplication bundleApplication, final String baseName, final String locale, final String key, final String defaultValue, final Object[] parameters) { final BundleApplications owner = resourcebundlesService.find(bundleApplication.getName()); final Resourcebundles resourcebundles = resourcebundlesService.getResourcebundle(owner, baseName, LocaleResolver.resolveLocaleCode(locale), key); String value = defaultValue; if (resourcebundles != null) { Resourcebundle domainObject = getMapper().toDomainObject(resourcebundles); value = domainObject.getValue().getName(); value = ResourceBundleExtensions.format(value, parameters); } return value; }
@Override public BundleNames updateProperties(final @NonNull Properties properties, final @NonNull String owner, final @NonNull String baseName, final @NonNull String localeCode) { BundleApplications bundleApplications = bundleApplicationsService.find(owner); Locale locale = LocaleResolver.resolveLocale(localeCode, false); return updateProperties(bundleApplications, properties, baseName, locale); }