MATH-1467: Avoid raising exception when the locale's language is "English".
The change also avoids raising an exception when a translation is missing.
This commit is contained in:
parent
efb0230063
commit
34bd170774
|
@ -395,13 +395,17 @@ public enum LocalizedFormats implements Localizable {
|
|||
public String getLocalizedString(final Locale locale) {
|
||||
try {
|
||||
final String path = LocalizedFormats.class.getName().replaceAll("\\.", "/");
|
||||
ResourceBundle bundle =
|
||||
ResourceBundle.getBundle("assets/" + path, locale);
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle("assets/" + path, locale);
|
||||
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
|
||||
// the value of the resource is the translated format
|
||||
return bundle.getString(toString());
|
||||
final String key = toString();
|
||||
if (bundle.containsKey(key)) {
|
||||
// the value of the resource is the translated format
|
||||
return bundle.getString(key);
|
||||
} else {
|
||||
// Use default.
|
||||
return sourceFormat;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (MissingResourceException mre) { // NOPMD
|
||||
// do nothing here
|
||||
}
|
||||
|
@ -409,7 +413,5 @@ public enum LocalizedFormats implements Localizable {
|
|||
// either the locale is not supported or the resource is unknown
|
||||
// don't translate and fall back to using the source format
|
||||
return sourceFormat;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Empty file: Its purpose is to avoid raising a "MissingResourceException"
|
||||
# whenever the "Locale" language is "English" as the default messages are
|
||||
# in English (see "LocalizedFormats" in package "o.a.c.m.exception.util").
|
Loading…
Reference in New Issue