Skip to content

Commit a68a267

Browse files
committed
Reverted changes in obsolete hipparchus-migration module.
1 parent 190b66b commit a68a267

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

hipparchus-migration/src/main/java/org/hipparchus/migration/LocalizedMigrationFormats.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
package org.hipparchus.migration;
2323

2424
import java.util.Locale;
25+
import java.util.MissingResourceException;
26+
import java.util.ResourceBundle;
2527

2628
import org.hipparchus.exception.Localizable;
29+
import org.hipparchus.exception.UTF8Control;
2730

2831
/**
2932
* Enumeration for localized messages formats used in exceptions messages.
@@ -310,8 +313,28 @@ public String getSourceString() {
310313
/** {@inheritDoc} */
311314
@Override
312315
public String getLocalizedString(final Locale locale) {
313-
return getLocalizedString("assets/" + LocalizedMigrationFormats.class.getName().replaceAll("\\.", "/"),
314-
name(), locale);
316+
try {
317+
final String path = LocalizedMigrationFormats.class.getName().replaceAll("\\.", "/");
318+
ResourceBundle bundle =
319+
ResourceBundle.getBundle("assets/" + path, locale, new UTF8Control());
320+
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
321+
final String translated = bundle.getString(name());
322+
if ((translated != null) &&
323+
(translated.length() > 0) &&
324+
(!translated.toLowerCase(locale).contains("missing translation"))) {
325+
// the value of the resource is the translated format
326+
return translated;
327+
}
328+
}
329+
330+
} catch (MissingResourceException mre) { // NOPMD
331+
// do nothing here
332+
}
333+
334+
// either the locale is not supported or the resource is unknown
335+
// don't translate and fall back to using the source format
336+
return sourceFormat;
337+
315338
}
316339

317340
}

hipparchus-migration/src/test/java/org/hipparchus/migration/LocalizedMigrationFormatsTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525

2626
import org.hipparchus.exception.LocalizedFormatsAbstractTest;
27-
import org.junit.jupiter.api.Test;
28-
import org.junit.jupiter.api.Assertions;
29-
30-
import java.util.Locale;
3127

3228
@Deprecated
3329
public class LocalizedMigrationFormatsTest extends LocalizedFormatsAbstractTest {
@@ -42,9 +38,4 @@ protected int getExpectedNumber() {
4238
return 82;
4339
}
4440

45-
@Test
46-
public void testUnsupportedLocale() {
47-
Assertions.assertEquals("Cardan angles singularity",
48-
LocalizedMigrationFormats.CARDAN_ANGLES_SINGULARITY.getLocalizedString(Locale.TRADITIONAL_CHINESE));
49-
}
5041
}

0 commit comments

Comments
 (0)