private Map < String , Properties > loadRegisteredMessageResources ( String name ) { Map < String , Properties > messageResources = new TreeMap <> ( ) ; // Load default messages Properties defaultMessages = loadMessages ( String . format ( name , "" ) ) ; if ( defaultMessages == null ) { log . error ( "Could not locate the default messages resource '{}', please create it." , String . format ( name , "" ) ) ; } else { messageResources . put ( "" , defaultMessages ) ; } // Load the registered language resources List < String > registeredLanguages = languages . getRegisteredLanguages ( ) ; for ( String language : registeredLanguages ) { // First step: Load complete language eg. en-US Properties messages = loadMessages ( String . format ( name , "_" + language ) ) ; Properties messagesLangOnly = null ; // If the language has a country code load the default values for // the language. For example missing keys in en-US will // be filled-in by the default language. String langComponent = languages . getLanguageComponent ( language ) ; if ( ! langComponent . equals ( language ) ) { // see if we have already loaded the language messages messagesLangOnly = messageResources . get ( langComponent ) ; if ( messagesLangOnly == null ) { // load the language messages messagesLangOnly = loadMessages ( String . format ( name , "_" + langComponent ) ) ; } } // If a language is registered in application.properties it should // be there. if ( messages == null ) { log . error ( "Could not locate the '{}' messages resource '{}' specified in '{}'." , language , String . format ( name , "_" + language ) , PippoConstants . SETTING_APPLICATION_LANGUAGES ) ; } else { // add a new language // start with the default messages Properties compositeMessages = new Properties ( defaultMessages ) ; // put all the language component messages "en" if ( messagesLangOnly != null ) { compositeMessages . putAll ( messagesLangOnly ) ; // cache language component messages if ( ! messageResources . containsKey ( langComponent ) ) { Properties langResources = new Properties ( ) ; langResources . putAll ( compositeMessages ) ; messageResources . put ( langComponent , langResources ) ; } } // put all the language specific messages "en-US" compositeMessages . putAll ( messages ) ; // and add the composite messages to the hashmap with the // mapping. messageResources . put ( language . toLowerCase ( ) , compositeMessages ) ; } } return Collections . unmodifiableMap ( messageResources ) ; }
Loads all registered message resources .