*/
String getI18nResources( @QueryParam( "locale" ) String locale )
throws ArchivaRestServiceException;
+
+ @Path( "getAllI18nResources" )
+ @GET
+ @Produces( { MediaType.TEXT_PLAIN } )
+ @RedbackAuthorization( noRestriction = true )
+ /**
+ * will return properties available in org/apache/archiva/i18n/default.properties
+ * load default (en) then override with locale used so at least en are returned if no
+ * translation in the locale asked.
+ * This method will add redback resources too. note Archva wins
+ */
+ String getAllI18nResources( @QueryParam( "locale" ) String locale )
+ throws ArchivaRestServiceException;
}
import org.apache.archiva.rest.api.services.CommonServices;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.codehaus.redback.rest.api.services.RedbackServiceException;
+import org.codehaus.redback.rest.api.services.UtilServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
+import javax.inject.Inject;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.util.Map;
import java.util.Properties;
private Logger log = LoggerFactory.getLogger( getClass() );
+ @Inject
+ private UtilServices utilServices;
+
public String getI18nResources( String locale )
throws ArchivaRestServiceException
{
log.warn( "skip error loading properties {}", resourceName.toString() );
}
- StringBuilder output = new StringBuilder();
-
- for ( Map.Entry<Object, Object> entry : properties.entrySet() )
- {
- output.append( (String) entry.getKey() ).append( '=' ).append( (String) entry.getValue() );
- output.append( '\n' );
- }
-
- return output.toString();
+ return fromProperties( properties );
}
private void loadResource( Properties properties, StringBuilder resourceName, String locale )
}
+ private String fromProperties( Properties properties )
+ {
+ StringBuilder output = new StringBuilder();
+
+ for ( Map.Entry<Object, Object> entry : properties.entrySet() )
+ {
+ output.append( (String) entry.getKey() ).append( '=' ).append( (String) entry.getValue() );
+ output.append( '\n' );
+ }
+
+ return output.toString();
+ }
+
private void loadResource( Properties properties, String resourceName )
throws IOException
{
IOUtils.closeQuietly( is );
}
}
+
+ public String getAllI18nResources( String locale )
+ throws ArchivaRestServiceException
+ {
+ try
+ {
+ String redbackProps = utilServices.getI18nResources( locale );
+ String archivaProps = getI18nResources( locale );
+ Properties properties = new Properties();
+ properties.load( new StringReader( redbackProps ) );
+ properties.load( new StringReader( archivaProps ) );
+ return fromProperties( properties );
+ }
+ catch ( RedbackServiceException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(), e.getHttpErrorCode() );
+ }
+ catch ( IOException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() );
+ }
+ }
}
$(function() {
// load i18n resources from rest call
- // first redback then archiva
- // -- redback
- // load default
- loadAndParseFile("restServices/redbackServices/utilServices/getBundleResources", {cache:false, mode: 'map',encoding:'utf-8'});
- // load browser locale
+
var browserLang = $.i18n.browserLang();
var requestLang = $.urlParam('request_lang');
if (requestLang) {
browserLang=requestLang;
}
$.log("use browserLang:"+browserLang);
- loadAndParseFile("restServices/redbackServices/utilServices/getBundleResources?locale="+browserLang, {cache:false, mode: 'map',encoding:'utf-8'});
// -- archiva
// load default
- loadAndParseFile("restServices/archivaServices/commonServices/getI18nResources", {cache:false, mode: 'map',encoding:'utf-8'});
+ loadAndParseFile("restServices/archivaServices/commonServices/getAllI18nResources", {cache:false, mode: 'map',encoding:'utf-8'});
// load browser locale
var browserLang = $.i18n.browserLang();
- loadAndParseFile("restServices/archivaServices/commonServices/getI18nResources?locale="+browserLang, {cache:false, mode: 'map',encoding:'utf-8'});
+ loadAndParseFile("restServices/archivaServices/commonServices/getAllI18nResources?locale="+browserLang, {cache:false, mode: 'map',encoding:'utf-8'});
});
\ No newline at end of file