-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i18n for REST APIs and error messages (#68)
* Localized strings in REST controller * Support for localization in ErrorService * Add parameters to the ApiMessage and use locale-aware Formatter * Allow redefining of numbered messages so applications can redefine numbers and text for the SDK commons messages * Using localized numbered message on the server * Instructions for other EBCDIC codepages (such as IBM-870) in STDOUT * Accent stripping logging encoder
- Loading branch information
Showing
32 changed files
with
878 additions
and
142 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...api-commons-spring/src/main/java/org/zowe/commons/AccentStrippingPatternLayerEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
package org.zowe.commons; | ||
|
||
import java.text.Normalizer; | ||
|
||
import ch.qos.logback.classic.encoder.PatternLayoutEncoder; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.Layout; | ||
import lombok.Setter; | ||
|
||
public class AccentStrippingPatternLayerEncoder extends PatternLayoutEncoder { | ||
private static final String STRIP_ACCENTS_PROPERTY_NAME = "org.zowe.commons.logging.stripAccents"; | ||
|
||
@Setter | ||
private boolean stripAccents = "true".equalsIgnoreCase(System.getProperty(STRIP_ACCENTS_PROPERTY_NAME)); | ||
|
||
@Override | ||
public byte[] encode(ILoggingEvent event) { | ||
String txt = layout.doLayout(event); | ||
if (stripAccents) { | ||
return stripAccents(txt).getBytes(); | ||
} | ||
else { | ||
return super.encode(event); | ||
} | ||
} | ||
|
||
private String stripAccents(String input) { | ||
return input == null ? null | ||
: Normalizer.normalize(input, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); | ||
} | ||
|
||
void overrideLayout(Layout layout) { | ||
this.layout = layout; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.