Search in sources :

Example 1 with I18nLocale

use of org.hisp.dhis.i18n.locale.I18nLocale in project dhis2-core by dhis2.

the class RemoveLocaleAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    try {
        I18nLocale i18nLocale = localeService.getI18nLocale(id);
        localeService.deleteI18nLocale(i18nLocale);
    } catch (DeleteNotAllowedException ex) {
        if (ex.getErrorCode().equals(DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS)) {
            message = i18n.getString("object_not_deleted_associated_by_objects") + " " + ex.getMessage();
            return ERROR;
        }
    }
    return SUCCESS;
}
Also used : DeleteNotAllowedException(org.hisp.dhis.common.DeleteNotAllowedException) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale)

Example 2 with I18nLocale

use of org.hisp.dhis.i18n.locale.I18nLocale in project dhis2-core by dhis2.

the class DefaultI18nLocaleService method getAllLocales.

@Override
public List<Locale> getAllLocales() {
    List<Locale> locales = new ArrayList<>();
    for (I18nLocale locale : localeStore.getAll()) {
        locales.add(LocaleUtils.getLocale(locale.getLocale()));
    }
    Collections.sort(locales, LocaleNameComparator.INSTANCE);
    return locales;
}
Also used : Locale(java.util.Locale) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale) ArrayList(java.util.ArrayList) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale)

Example 3 with I18nLocale

use of org.hisp.dhis.i18n.locale.I18nLocale in project dhis2-core by dhis2.

the class DefaultI18nLocaleService method addI18nLocale.

@Override
public boolean addI18nLocale(String language, String country) {
    String languageName = languages.get(language);
    String countryName = countries.get(country);
    if (language == null || languageName == null) {
        // Language is required
        return false;
    }
    if (country != null && countryName == null) {
        // Country not valid
        return false;
    }
    String localeStr = LocaleUtils.getLocaleString(language, country, null);
    Locale locale = LocaleUtils.getLocale(localeStr);
    I18nLocale i18nLocale = new I18nLocale(locale);
    saveI18nLocale(i18nLocale);
    return true;
}
Also used : Locale(java.util.Locale) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale)

Example 4 with I18nLocale

use of org.hisp.dhis.i18n.locale.I18nLocale in project dhis2-core by dhis2.

the class I18nLocalePopulator method executeInTransaction.

@Override
public void executeInTransaction() {
    int count = localeService.getI18nLocaleCount();
    if (count > 0) {
        return;
    }
    for (String locale : DEFAULT_LOCALES) {
        localeService.saveI18nLocale(new I18nLocale(new Locale(locale)));
    }
    log.info("Populated default locales");
}
Also used : Locale(java.util.Locale) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale) I18nLocale(org.hisp.dhis.i18n.locale.I18nLocale)

Aggregations

I18nLocale (org.hisp.dhis.i18n.locale.I18nLocale)4 Locale (java.util.Locale)3 ArrayList (java.util.ArrayList)1 DeleteNotAllowedException (org.hisp.dhis.common.DeleteNotAllowedException)1