Skip to content

Commit 84625ea

Browse files
committed
Merge branch 'master' of github.com:spullara/mustache.java
2 parents dc87817 + e8f5dd6 commit 84625ea

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎compiler/src/main/java/com/github/mustachejava/functions/TranslateBundleFunction.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Usage in template:
2323
* ... {{#trans}}TranslatedLabel1{{/trans}} ...
2424
*
25+
* ... {{#trans}}TranslatedLabel2 param1=newparam1 param2=newparma2{{/trans}}
2526
* @author gw0 [http://gw.tnode.com/] <gw.2012@tnode.com>
2627
*/
2728
public class TranslateBundleFunction implements TemplateFunction {
@@ -41,10 +42,18 @@ public TranslateBundleFunction(String bundle, Locale locale) {
4142
/** Return translation from the localized ResourceBundle. */
4243
@Override
4344
public String apply(String input) {
44-
if(res.containsKey(input)) {
45-
return res.getString(input); // return translation
46-
} else {
45+
String[] inputWithParams = input.split(" ");
46+
String key = inputWithParams[0];
47+
if(!res.containsKey(key)) {
4748
return input; // return untranslated label
4849
}
50+
String translatedValue = res.getString(key);
51+
for (int i = 1; i < inputWithParams.length; i++) {
52+
String[] splitParam = inputWithParams[i].split("=");
53+
String oldTag = splitParam[0];
54+
String newTag = splitParam[1];
55+
translatedValue = translatedValue.replace("{{" + oldTag + "}}", "{{" + newTag + "}}");
56+
}
57+
return translatedValue;
4958
}
5059
}

0 commit comments

Comments
 (0)