private Map < String , Configuration > loadAllMessageFilesForRegisteredLanguages ( ) { Map < String , Configuration > langToKeyAndValuesMappingMutable = Maps . newHashMap ( ) ; // Load default messages: Configuration defaultLanguage = loadLanguageConfiguration ( "conf/messages.properties" ) ; // Make sure we got the file. // Everything else does not make much sense. if ( defaultLanguage == null ) { throw new RuntimeException ( "Did not find conf/messages.properties. Please add a default language file." ) ; } else { langToKeyAndValuesMappingMutable . put ( "" , defaultLanguage ) ; } // Get the languages from the application configuration. String [ ] applicationLangs = ninjaProperties . getStringArray ( NinjaConstant . applicationLanguages ) ; // If we don't have any languages declared we just return. // We'll use the default messages.properties file. if ( applicationLangs == null ) { return ImmutableMap . copyOf ( langToKeyAndValuesMappingMutable ) ; } // Load each language into the HashMap containing the languages: for ( String lang : applicationLangs ) { // First step: Load complete language eg. en-US Configuration configuration = loadLanguageConfiguration ( String . format ( "conf/messages_%s.properties" , lang ) ) ; Configuration configurationLangOnly = null ; // If the language has a country code load the default values for // the language, too. For instance missing variables in en-US will // be // Overwritten by the default languages. if ( lang . contains ( "-" ) ) { // get the lang String langOnly = lang . split ( "-" ) [ 0 ] ; // And load the configuraion configurationLangOnly = loadLanguageConfiguration ( String . format ( "conf/messages_%s.properties" , langOnly ) ) ; } // This is strange. If you defined the language in application.conf // it should be there propably. if ( configuration == null ) { logger . info ( "Did not find conf/messages_{}.properties but it was specified in application.conf. Using default language instead." , lang ) ; } else { // add new language, but combine with default language if stuff // is missing... CompositeConfiguration compositeConfiguration = new CompositeConfiguration ( ) ; // Add eg. "en-US" compositeConfiguration . addConfiguration ( configuration ) ; // Add eg. "en" if ( configurationLangOnly != null ) { compositeConfiguration . addConfiguration ( configurationLangOnly ) ; } // Add messages.conf (default pack) compositeConfiguration . addConfiguration ( defaultLanguage ) ; // and add the composed configuration to the hashmap with the // mapping. langToKeyAndValuesMappingMutable . put ( lang , ( Configuration ) compositeConfiguration ) ; } } return ImmutableMap . copyOf ( langToKeyAndValuesMappingMutable ) ; }
Does all the loading of message files .