Skip to content

Commit

Permalink
Reverted changes in obsolete hipparchus-migration module.
Browse files Browse the repository at this point in the history
  • Loading branch information
maisonobe committed Jul 30, 2024
1 parent 190b66b commit a68a267
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
package org.hipparchus.migration;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.hipparchus.exception.Localizable;
import org.hipparchus.exception.UTF8Control;

/**
* Enumeration for localized messages formats used in exceptions messages.
Expand Down Expand Up @@ -310,8 +313,28 @@ public String getSourceString() {
/** {@inheritDoc} */
@Override
public String getLocalizedString(final Locale locale) {
return getLocalizedString("assets/" + LocalizedMigrationFormats.class.getName().replaceAll("\\.", "/"),
name(), locale);
try {
final String path = LocalizedMigrationFormats.class.getName().replaceAll("\\.", "/");
ResourceBundle bundle =
ResourceBundle.getBundle("assets/" + path, locale, new UTF8Control());
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
final String translated = bundle.getString(name());
if ((translated != null) &&
(translated.length() > 0) &&
(!translated.toLowerCase(locale).contains("missing translation"))) {
// the value of the resource is the translated format
return translated;
}
}

} catch (MissingResourceException mre) { // NOPMD
// do nothing here
}

// either the locale is not supported or the resource is unknown
// don't translate and fall back to using the source format
return sourceFormat;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@


import org.hipparchus.exception.LocalizedFormatsAbstractTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import java.util.Locale;

@Deprecated
public class LocalizedMigrationFormatsTest extends LocalizedFormatsAbstractTest {
Expand All @@ -42,9 +38,4 @@ protected int getExpectedNumber() {
return 82;
}

@Test
public void testUnsupportedLocale() {
Assertions.assertEquals("Cardan angles singularity",
LocalizedMigrationFormats.CARDAN_ANGLES_SINGULARITY.getLocalizedString(Locale.TRADITIONAL_CHINESE));
}
}

0 comments on commit a68a267

Please sign in to comment.