Blame SOURCES/TestTranslations.java

a1cada
/* TestTranslations -- Ensure translations are available for new timezones
a1cada
   Copyright (C) 2022 Red Hat, Inc.
a1cada
a1cada
This program is free software: you can redistribute it and/or modify
a1cada
it under the terms of the GNU Affero General Public License as
a1cada
published by the Free Software Foundation, either version 3 of the
a1cada
License, or (at your option) any later version.
a1cada
a1cada
This program is distributed in the hope that it will be useful,
a1cada
but WITHOUT ANY WARRANTY; without even the implied warranty of
a1cada
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a1cada
GNU Affero General Public License for more details.
a1cada
a1cada
You should have received a copy of the GNU Affero General Public License
a1cada
along with this program.  If not, see <http://www.gnu.org/licenses/>.
a1cada
*/
a1cada
50778c
import java.text.DateFormatSymbols;
50778c
50778c
import java.time.ZoneId;
50778c
import java.time.format.TextStyle;
50778c
a1cada
import java.util.Arrays;
50778c
import java.util.Collections;
50778c
import java.util.HashMap;
50778c
import java.util.Map;
a1cada
import java.util.Locale;
50778c
import java.util.Objects;
50778c
import java.util.TimeZone;
a1cada
a1cada
public class TestTranslations {
50778c
50778c
    private static Map<Locale,String[]> KYIV;
50778c
50778c
    static {
50778c
        Map<Locale,String[]> map = new HashMap<Locale,String[]>();
50778c
        map.put(Locale.US, new String[] { "Eastern European Standard Time", "GMT+02:00", "EET",
50778c
                                          "Eastern European Summer Time", "GMT+03:00", "EEST",
50778c
                                          "Eastern European Time", "GMT+02:00", "EET"});
50778c
        map.put(Locale.FRANCE, new String[] { "heure normale d\u2019Europe de l\u2019Est", "UTC+02:00", "EET",
50778c
                                              "heure d\u2019\u00e9t\u00e9 d\u2019Europe de l\u2019Est", "UTC+03:00", "EEST",
50778c
                                              "heure d\u2019Europe de l\u2019Est", "UTC+02:00", "EET"});
50778c
        map.put(Locale.GERMANY, new String[] { "Osteurop\u00e4ische Normalzeit", "OEZ", "OEZ",
50778c
                                               "Osteurop\u00e4ische Sommerzeit", "OESZ", "OESZ",
50778c
                                               "Osteurop\u00e4ische Zeit", "OEZ", "OEZ"});
50778c
        KYIV = Collections.unmodifiableMap(map);
50778c
    }
50778c
50778c
a1cada
    public static void main(String[] args) {
50778c
        if (args.length < 1) {
50778c
            System.err.println("Test must be started with the name of the locale provider.");
50778c
            System.exit(1);
50778c
        }
50778c
50778c
        String localeProvider = args[0];
50778c
        System.out.println("Checking sanity of full zone string set...");
50778c
        boolean invalid = Arrays.stream(Locale.getAvailableLocales())
50778c
            .peek(l -> System.out.println("Locale: " + l))
50778c
            .map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
50778c
            .flatMap(zs -> Arrays.stream(zs))
50778c
            .flatMap(names -> Arrays.stream(names))
50778c
            .filter(name -> Objects.isNull(name) || name.isEmpty())
50778c
            .findAny()
50778c
            .isPresent();
50778c
        if (invalid) {
50778c
            System.err.println("Zone string for a locale returned null or empty string");
50778c
            System.exit(2);
50778c
        }
50778c
50778c
        for (Locale l : KYIV.keySet()) {
50778c
            String[] expected = KYIV.get(l);
50778c
            for (String id : new String[] { "Europe/Kiev", "Europe/Kyiv", "Europe/Uzhgorod", "Europe/Zaporozhye" }) {
50778c
                String expectedShortStd = null;
50778c
                String expectedShortDST = null;
50778c
                String expectedShortGen = null;
50778c
50778c
                System.out.printf("Checking locale %s for %s...\n", l, id);
50778c
50778c
                if ("JRE".equals(localeProvider)) {
50778c
                    expectedShortStd = expected[2];
50778c
                    expectedShortDST = expected[5];
50778c
                    expectedShortGen = expected[8];
50778c
                } else if ("CLDR".equals(localeProvider)) {
50778c
                    expectedShortStd = expected[1];
50778c
                    expectedShortDST = expected[4];
50778c
                    expectedShortGen = expected[7];
50778c
                } else {
50778c
                    System.err.printf("Invalid locale provider %s\n", localeProvider);
50778c
                    System.exit(3);
50778c
                }
50778c
                System.out.printf("Locale Provider is %s, using short values %s, %s and %s\n",
50778c
                                  localeProvider, expectedShortStd, expectedShortDST, expectedShortGen);
50778c
50778c
                String longStd = TimeZone.getTimeZone(id).getDisplayName(false, TimeZone.LONG, l);
50778c
                String shortStd = TimeZone.getTimeZone(id).getDisplayName(false, TimeZone.SHORT, l);
50778c
                String longDST = TimeZone.getTimeZone(id).getDisplayName(true, TimeZone.LONG, l);
50778c
                String shortDST = TimeZone.getTimeZone(id).getDisplayName(true, TimeZone.SHORT, l);
50778c
                String longGen = ZoneId.of(id).getDisplayName(TextStyle.FULL, l);
50778c
                String shortGen = ZoneId.of(id).getDisplayName(TextStyle.SHORT, l);
50778c
50778c
                if (!expected[0].equals(longStd)) {
50778c
                    System.err.printf("Long standard display name for %s in %s was %s, expected %s\n",
50778c
                                      id, l, longStd, expected[0]);
50778c
                    System.exit(4);
50778c
                }
50778c
50778c
                if (!expectedShortStd.equals(shortStd)) {
50778c
                    System.err.printf("Short standard display name for %s in %s was %s, expected %s\n",
50778c
                                      id, l, shortStd, expectedShortStd);
50778c
                    System.exit(5);
50778c
                }
50778c
50778c
                if (!expected[3].equals(longDST)) {
50778c
                    System.err.printf("Long DST display name for %s in %s was %s, expected %s\n",
50778c
                                      id, l, longDST, expected[3]);
50778c
                    System.exit(6);
50778c
                }
50778c
50778c
                if (!expectedShortDST.equals(shortDST)) {
50778c
                    System.err.printf("Short DST display name for %s in %s was %s, expected %s\n",
50778c
                                      id, l, shortDST, expectedShortDST);
50778c
                    System.exit(7);
50778c
                }
50778c
50778c
                if (!expected[6].equals(longGen)) {
50778c
                    System.err.printf("Long standard display name for %s in %s was %s, expected %s\n",
50778c
                                      id, l, longGen, expected[6]);
50778c
                    System.exit(8);
50778c
                }
50778c
50778c
                if (!expectedShortGen.equals(shortGen)) {
50778c
                    System.err.printf("Short generic display name for %s in %s was %s, expected %s\n",
50778c
                                      id, l, shortGen, expectedShortGen);
50778c
                    System.exit(9);
50778c
                }
a1cada
            }
a1cada
        }
a1cada
    }
a1cada
}