=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java 2013-10-03 22:19:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java 2013-10-04 15:05:00 +0000 @@ -33,12 +33,16 @@ import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.i18n.locale.I18nLocale; +import org.hisp.dhis.system.util.LocaleUtils; +import org.hisp.dhis.system.util.TextUtils; import org.springframework.transaction.annotation.Transactional; @Transactional public class DefaultI18nLocaleService implements I18nLocaleService { + private static final String NAME_SEP = ", "; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -78,6 +82,32 @@ return countries; } + public boolean addI18nLocale( String language, String country ) + { + String languageName = languages.get( language ); + String countryName = countries.get( country ); + + if ( language == null || languageName == null ) + { + return false; // Language is required + } + + if ( country != null && countryName == null ) + { + return false; // Country not valid + } + + String loc = LocaleUtils.getLocaleString( language, country, null ); + + String name = languageName + ( countryName != null ? ( NAME_SEP + countryName ) : TextUtils.EMPTY ); + + I18nLocale locale = new I18nLocale( name, loc ); + + saveI18nLocale( locale ); + + return true; + } + public void saveI18nLocale( I18nLocale locale ) { localeStore.save( locale ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java 2013-10-03 22:19:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java 2013-10-04 15:05:00 +0000 @@ -34,10 +34,18 @@ public interface I18nLocaleService { + /** + * Returns available languages in a mapping between code and name. + */ Map getAvailableLanguages(); + /** + * Returns available countries in a mapping between code and name. + */ Map getAvailableCountries(); + boolean addI18nLocale( String language, String country ); + void saveI18nLocale( I18nLocale locale ); I18nLocale getI18nLocale( int id ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-10-04 14:34:08 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-10-04 15:05:00 +0000 @@ -1169,368 +1169,366 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java 2013-09-14 19:05:29 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java 2013-10-04 15:05:00 +0000 @@ -35,8 +35,10 @@ */ public class LocaleUtils { + private static final String SEP = "_"; + /** - * Creates a Locale object based on the input String + * Creates a Locale object based on the input string. * * @param localeStr String to parse * @return A locale object or null if not valid @@ -48,7 +50,7 @@ return null; } - String[] parts = localeStr.split( "_" ); + String[] parts = localeStr.split( SEP ); Locale thisLocale; @@ -71,4 +73,34 @@ return thisLocale; } + + /** + * Createa a locale string based on the given language, country and varient. + * + * @param language the language, cannot be null. + * @param country the country, can be null. + * @param variant the variant, can be null. + * @return a locale string. + */ + public static String getLocaleString( String language, String country, String variant ) + { + if ( language == null ) + { + return null; + } + + String locale = language; + + if ( country != null ) + { + locale += SEP + country; + } + + if ( variant != null ) + { + locale += SEP + variant; + } + + return locale; + } } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/AddLocaleAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/AddLocaleAction.java 2013-10-01 16:44:42 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/AddLocaleAction.java 2013-10-04 15:05:00 +0000 @@ -27,10 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Locale; - import org.hisp.dhis.i18n.I18nLocaleService; -import org.hisp.dhis.i18n.locale.I18nLocale; import org.springframework.beans.factory.annotation.Autowired; import com.opensymphony.xwork2.Action; @@ -52,13 +49,6 @@ // Input/Output // ------------------------------------------------------------------------- - private String name; - - public void setName( String name ) - { - this.name = name; - } - private String language; public void setLanguage( String language ) @@ -80,9 +70,7 @@ public String execute() throws Exception { - I18nLocale i18nLocale = new I18nLocale( name, (new Locale( language, country )).toString() ); - - localeService.saveI18nLocale( i18nLocale ); + localeService.addI18nLocale( language, country ); return SUCCESS; } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2013-10-04 14:34:08 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2013-10-04 15:05:00 +0000 @@ -335,6 +335,4 @@ language=Language country=Country locale_language_no_translation=Please select a language -locale_country_no_translation=Please select a country - - +locale_country_no_translation=Please select a country \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLocaleForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLocaleForm.vm 2013-10-01 16:44:42 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLocaleForm.vm 2013-10-04 15:05:00 +0000 @@ -15,9 +15,9 @@ @@ -26,9 +26,10 @@