mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-06 08:25:31 +00:00
restructured the duration formatting templates for easier translation
This commit is contained in:
@@ -0,0 +1 @@
|
||||
1 day
|
||||
@@ -0,0 +1 @@
|
||||
${days} days
|
||||
@@ -0,0 +1 @@
|
||||
1 hour
|
||||
@@ -0,0 +1 @@
|
||||
${hours} hours
|
||||
@@ -0,0 +1 @@
|
||||
1 minute
|
||||
@@ -0,0 +1 @@
|
||||
${minutes} minutes
|
||||
@@ -0,0 +1 @@
|
||||
1 second
|
||||
@@ -0,0 +1 @@
|
||||
${seconds} seconds
|
||||
@@ -41,36 +41,17 @@ public class DurationMethod implements TemplateMethodModelEx {
|
||||
Duration duration = (Duration) wrappedObject;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
// upgrading to java 9 makes this nicer
|
||||
// todo refactor to use a single template, instead of multiple ones
|
||||
HashMap<String, Object> parameters = new HashMap<>();
|
||||
long days = duration.toDays();
|
||||
if(days > 0) {
|
||||
stringBuilder.append(service.renderTemplate("day", getParam(days)));
|
||||
}
|
||||
parameters.put("days", days);
|
||||
long hours = duration.toHours() % 24;
|
||||
if(hours > 0) {
|
||||
stringBuilder.append(service.renderTemplate("hour", getParam(hours)));
|
||||
}
|
||||
parameters.put("hours", hours);
|
||||
long minutes = duration.toMinutes() % 60;
|
||||
if(minutes > 0) {
|
||||
stringBuilder.append(service.renderTemplate("minute", getParam(minutes)));
|
||||
}
|
||||
parameters.put("minutes", minutes);
|
||||
|
||||
long seconds = duration.get(ChronoUnit.SECONDS) % 60;
|
||||
if(seconds > 0) {
|
||||
stringBuilder.append(service.renderTemplate("second", getParam(seconds)));
|
||||
}
|
||||
parameters.put("seconds", seconds);
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the parameter passed to the template for rendering the single time unit template.
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private HashMap<String, Object> getParam(Long value) {
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("amount", value);
|
||||
return params;
|
||||
return service.renderTemplateWithMap("duration_formatting", parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<#if amount gt 1>${amount} days<#else>1 day</#if>
|
||||
@@ -0,0 +1 @@
|
||||
<#if days gt 1><#include "duration_days"><#elseif days = 1><#include "duration_day"></#if> <#if hours gt 1><#include "duration_hours"><#elseif hours = 1><#include "duration_hour"></#if> <#if minutes gt 1><#include "duration_minutes"><#elseif minutes = 1><#include "duration_minute"></#if> <#if seconds gt 1><#include "duration_seconds"><#elseif seconds = 1><#include "duration_second"></#if>
|
||||
@@ -1 +0,0 @@
|
||||
<#if amount gt 1>${amount} hours<#else>1 hour</#if>
|
||||
@@ -1 +0,0 @@
|
||||
<#if amount gt 1>${amount} minutes<#else>1 minute</#if>
|
||||
@@ -1 +0,0 @@
|
||||
<#if amount gt 1>${amount} seconds<#else>1 second</#if>
|
||||
Reference in New Issue
Block a user