/** * 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 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 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); }
/** * 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); }
/** * {@inheritDoc} */ @Override public Properties getProperties(BundleApplications owner, String baseName, String localeCode) { return getProperties(owner, baseName, LocaleResolver.resolveLocale(localeCode)); }
@Override public Locale resolveLocale(LanguageLocales languageLocales) { Locale locale = null; if (languageLocales != null) { locale = LocaleResolver.resolveLocale(languageLocales.getLocale(), false); } return locale; }
/** * 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 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); }
/** * 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. * @param systemsDefault * if this flag is true the systems default locale will be taken as the default * locale otherwise the value will be null for the default locale. * @return a Map of File objects with the corresponding Locales to it. */ public static Map<File, Locale> resolveLocales(final String bundlepackage, final String bundlename, final boolean systemsDefault) { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final File root = new File(loader.getResource(bundlepackage.replace('.', '/')).getFile()); final File[] files = root.listFiles(new PropertiesResourceBundleFilenameFilter(bundlename)); final Map<File, Locale> locales = new HashMap<>(); for (final File file : files) { final Locale current = LocaleResolver.resolveLocale(file, systemsDefault); locales.put(file, current); } return locales; }
@Override public Response findResourceBundles(String bundleappname, String baseName, String locale) { final BundleApplication bundleApplication = getDomainService().find(bundleappname); final Locale loc = LocaleResolver.resolveLocale(locale); List<Resourcebundle> resourceBundles = getDomainService() .findResourceBundles(bundleApplication, baseName, loc); return Response.ok(resourceBundles).build(); }
@Override public Response getOrCreateNewBundleName(String bundleappname, String baseName, String locale) { final BundleApplication bundleApplication = getDomainService().find(bundleappname); final Locale loc = LocaleResolver.resolveLocale(locale); BundleName bundleName = getDomainService().getOrCreateNewBundleName(bundleApplication, baseName, loc); return Response.ok(bundleName).build(); }
@Override protected void handleFile(final File file, final int depth, final Collection<File> results) throws IOException { final Locale locale = LocaleResolver.resolveLocale(file, defaultLocale, false); propertiesList .add(KeyValuePair.<File, Locale> builder().key(file).value(locale).build()); } };
/** * {@inheritDoc} */ @Override public Resourcebundle find(String bundleappname, String baseName, String locale, String key) { final BundleApplication bundleApplication = getDomainService().find(bundleappname); final Locale loc = LocaleResolver.resolveLocale(locale); return getDomainService().find(bundleApplication, baseName, loc, key); }
/** * {@inheritDoc} */ @Override public List<Resourcebundles> findResourceBundles(final BundleNames bundleName) { final String baseName = bundleName.getBaseName().getName(); final Locale locale = LocaleResolver.resolveLocale(bundleName.getLocale().getLocale()); final BundleApplications owner = bundleName.getOwner(); return findResourceBundles(owner, baseName, locale); }
@Override public Resourcebundle saveOrUpdateEntry(String bundleappname, String baseName, String locale, String key, String value) { final BundleApplication owner = find(bundleappname); Locale resolvedLocale = LocaleResolver.resolveLocale(locale, false); BundleName bundleName = bundleNameDomainService.find(owner, baseName, resolvedLocale); BundleNames bundleNames = getMapper().map(bundleName, BundleNames.class); Resourcebundles entity = resourcebundlesService.saveOrUpdateEntry(bundleNames, baseName, resolvedLocale, key, value, true); Resourcebundle domainObject = getMapper().toDomainObject(entity); return domainObject; }