Blame SOURCES/TestTranslations.java

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