Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

package org.openlmis.report.i18n;

import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -33,6 +35,13 @@ protected Properties getAllProperties(Locale locale) {
return propertiesHolder.getProperties();
}

@Override
@NonNull
protected MessageFormat createMessageFormat(@NonNull String msg, @NonNull Locale locale) {
String safe = msg.replaceAll("(?<!')'(?!')", "''");
return super.createMessageFormat(safe, locale);
}

/**
* Get all messages for given locale.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.
*/

package org.openlmis.report.i18n;

import static org.junit.Assert.assertEquals;

import java.util.Locale;
import java.util.Properties;
import org.junit.Test;

public class ExposedMessageSourceImplTest {

@Test
public void apostropheWithPlaceholderIsRenderedCorrectly() {
ExposedMessageSourceImpl source = new ExposedMessageSourceImpl();
source.setDefaultEncoding("UTF-8");
Properties messages = new Properties();
messages.setProperty("test.apostrophe", "L'établissement {0}");
source.setCommonMessages(messages);

String result = source.getMessage("test.apostrophe",
new Object[] {"abc"}, Locale.FRENCH);

assertEquals("L'établissement abc", result);
}
}
Loading