Skip to content

Commit 3e4e602

Browse files
committed
Add simple parsing for ICU MessageFormat placeholder
1 parent 42985c1 commit 3e4e602

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/TranslationUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ public static Set<String> getPlaceholderFromTranslation(@NotNull String text) {
402402
placeholder.add(matcher.group(1));
403403
}
404404

405+
// Simple parser for MessageFormat by the ICU project
406+
matcher = Pattern.compile("(\\{\\s*[^{]*\\s*})").matcher(text);
407+
while(matcher.find()){
408+
// Keep the whole placeholder for consistency with other formats, but also add just the placeholder name
409+
// as this is allowed with the ICU format.
410+
placeholder.add(matcher.group(1));
411+
placeholder.add(matcher.group(1).replace("{", "").replace("}", "").trim());
412+
}
413+
405414
return placeholder;
406415
}
407416

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/translation/dict/TranslationUtilTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ public void testGetPlaceholderFromTranslationForDrupalStyle2() {
188188
assertContainsElements(placeholder, "%title", "%url");
189189
}
190190

191+
public void testGetPlaceholderFromTranslationForIcuStyle() {
192+
Set<String> placeholder = TranslationUtil.getPlaceholderFromTranslation(
193+
"Updated URL for feed {title} to {url}."
194+
);
195+
196+
assertContainsElements(placeholder, "{title}", "{url}", "title", "url");
197+
}
198+
191199
public void testGetPlaceholderFromTranslationForKeyAndDomain() {
192200
Set<String> placeholder = TranslationUtil.getPlaceholderFromTranslation(
193201
getProject(), "my_foobar", "symfony"

0 commit comments

Comments
 (0)