Search in sources :

Example 6 with PropertiesResourceBundle

use of org.phoenicis.configuration.localisation.PropertiesResourceBundle in project POL-POM-5 by PlayOnLinux.

the class LocalRepository method fetchInstallableApplications.

@Override
public RepositoryDTO fetchInstallableApplications() {
    if (!repositoryDirectory.exists()) {
        throw new RepositoryException(String.format("Repository %s directory does not exist.", repositoryDirectory));
    }
    final File[] typeDirectories = repositoryDirectory.listFiles();
    if (typeDirectories == null) {
        return new RepositoryDTO.Builder().build();
    }
    LOGGER.info("Reading directory : " + repositoryDirectory);
    final RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName(repositoryDirectory.getName()).withTypes(fetchTypes(typeDirectories));
    final File i18nDirectory = new File(repositoryDirectory, "i18n");
    if (i18nDirectory.exists()) {
        final File[] translationFiles = i18nDirectory.listFiles((dir, name) -> name.endsWith(Locale.getDefault().getLanguage() + ".properties"));
        Properties mergedProperties = new Properties();
        for (File translationFile : translationFiles) {
            try {
                Properties langProperties = new Properties();
                langProperties.load(new FileInputStream(translationFile));
                mergedProperties.putAll(langProperties);
            } catch (IOException e) {
                LOGGER.error("Could not read translation properties", e);
            }
        }
        repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(mergedProperties).build());
        Localisation.setAdditionalTranslations(new PropertiesResourceBundle(mergedProperties));
    }
    return repositoryDTOBuilder.build();
}
Also used : PropertiesResourceBundle(org.phoenicis.configuration.localisation.PropertiesResourceBundle) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

PropertiesResourceBundle (org.phoenicis.configuration.localisation.PropertiesResourceBundle)6 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)3 HashCodeBuilder (org.apache.commons.lang.builder.HashCodeBuilder)3 ToStringBuilder (org.apache.commons.lang.builder.ToStringBuilder)3 RepositoryException (org.phoenicis.repository.RepositoryException)3