Skip to content

Commit

Permalink
[JN-1397] fix atcp key ordering problem (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlbark authored Oct 3, 2024
1 parent 3e0e99a commit 6ce3079
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,15 @@ private Map<String, String> getQuestionTxt(QuestionDef pepperQuestionDef) {
*/
public static Map<String, String> getVariableTranslationsTxt(String templateText, Collection<TemplateVariable> templateVariables) {
Map<String, String> textMap = new HashMap<>();

List<TemplateVariable> templateVariableCopy = new ArrayList<>(templateVariables);

// sort variable names by length to ensure that situations like, e.g., $diagnosis_center and $diagnosis_center_country
// are handled in the correct order
templateVariableCopy.sort(Comparator.comparingInt(var -> -1 * var.getName().length()));

// for each variable, get the translations and replace the variable name with the translation text in the appropriate language
for (TemplateVariable var : templateVariables) {
for (TemplateVariable var : templateVariableCopy) {
for (Translation translation : var.getTranslations()) {
String languageText = textMap.getOrDefault(translation.getLanguageCode(), StringUtils.trim(templateText));
languageText = languageText.replace("$" + var.getName(), translation.getText());
Expand Down

0 comments on commit 6ce3079

Please sign in to comment.