From a4718a3b13b1e0cdbc0934e29a838de80f5bb9d0 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Mon, 10 Jun 2024 18:16:53 -0500 Subject: [PATCH 01/10] CLDR-16835 prepare for separate DDL phase - add CLDR_DDL_PHASE configuration var - add separate DDL phase, defaulting to CLDR_PHASE - pass phase through to client - add separate tc org parameter in the locales list --- tools/cldr-apps/js/src/esm/cldrStatus.mjs | 13 ++++++++++++ .../org/unicode/cldr/util/CLDRConfigImpl.java | 5 +++++ .../java/org/unicode/cldr/web/SurveyAjax.java | 2 ++ .../java/org/unicode/cldr/web/SurveyMain.java | 21 +++++++++++++++++++ .../org/unicode/cldr/util/CLDRConfig.java | 8 +++++++ 5 files changed, 49 insertions(+) diff --git a/tools/cldr-apps/js/src/esm/cldrStatus.mjs b/tools/cldr-apps/js/src/esm/cldrStatus.mjs index da6b0d94d29..bdc35ba282d 100644 --- a/tools/cldr-apps/js/src/esm/cldrStatus.mjs +++ b/tools/cldr-apps/js/src/esm/cldrStatus.mjs @@ -75,6 +75,9 @@ function updateAll(status) { if (status.phase) { setPhase(status.phase); } + if (status.ddlPhase) { + setDdlPhase(status.ddlPhase); + } if (status.specialHeader) { setSpecialHeader(status.specialHeader); } @@ -296,9 +299,17 @@ function getPhase() { return phase; } +let ddlPhase = ""; function setPhase(p) { phase = p; } +function getDdlPhase() { + return ddlPhase; +} + +function setDdlPhase(p) { + ddlPhase = p; +} /** * Is this a "beta" phase of Survey Tool? (Boolean) @@ -479,6 +490,7 @@ export { getNewVersion, getOrganizationName, getPermissions, + getDdlPhase, getPhase, getRunningStamp, getSessionId, @@ -507,6 +519,7 @@ export { setOrganizationName, setPermissions, setPhase, + setDdlPhase, setSessionId, setSessionMessage, setSpecialHeader, diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/util/CLDRConfigImpl.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/util/CLDRConfigImpl.java index ac19827e85c..3f4bd0949fb 100644 --- a/tools/cldr-apps/src/main/java/org/unicode/cldr/util/CLDRConfigImpl.java +++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/util/CLDRConfigImpl.java @@ -460,6 +460,11 @@ public CheckCLDR.Phase getPhase() { return SurveyMain.phase().getCPhase(); } + @Override + public CheckCLDR.Phase getDDLPhase() { + return SurveyMain.getDDLPhase().getCPhase(); + } + @Override public CLDRURLS internalGetUrls() { if (contextUrl == null) contextUrl = CLDRURLS.DEFAULT_PATH; diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java index 71a9bce2f18..50b647f5b36 100644 --- a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java +++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java @@ -1092,6 +1092,7 @@ private static JSONObject createJSONLocMap(SurveyMain sm) throws JSONException { // locales will have info about each locale, including name JSONObject locales = new JSONObject(); SupplementalDataInfo sdi = sm.getSupplementalDataInfo(); + final StandardCodes sc = StandardCodes.make(); Factory disk = sm.getDiskFactory(); @@ -1118,6 +1119,7 @@ private static JSONObject createJSONLocMap(SurveyMain sm) throws JSONException { locale.put("highestParent", loc.getHighestNonrootParent()); locale.put("dcParent", dcParent); locale.put("dcChild", dcChild); + locale.put("tc", SubmissionLocales.TC_ORG_LOCALES.contains(loc.getBaseName())); locale.put( "type", Factory.getSourceTreeType(disk.getSourceDirectoryForLocale(loc.getBaseName()))); diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyMain.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyMain.java index 3b162f5eafc..8c85cd52bf1 100644 --- a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyMain.java +++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyMain.java @@ -209,6 +209,7 @@ public String display() { // ===== Configuration state private static Phase currentPhase = Phase.VETTING; + private static Phase currentDdlPhase = Phase.VETTING; /** set by CLDR_PHASE property. * */ private static String oldVersion = "OLDVERSION"; @@ -2823,6 +2824,20 @@ private void doStartup() { + phaseString); } currentPhase = newPhase; + String ddlPhaseString = survprops.getProperty("CLDR_DDL_PHASE", null); + Phase ddlPhase = null; + try { + if (ddlPhaseString != null) { + ddlPhase = (Phase.valueOf(ddlPhaseString)); + } + } catch (IllegalArgumentException iae) { + logger.warning("Error trying to parse CLDR_DDL_PHASE: " + iae); + } + if (ddlPhase == null) { + ddlPhase = newPhase; + logger.warning("CLDR_DDL_PHASE matches main phase " + ddlPhase); + } + currentDdlPhase = ddlPhase; } logger.info("Phase: " + phase() + ", cPhase: " + phase().getCPhase()); progress.update("Setup props.."); @@ -3570,6 +3585,10 @@ public static Phase phase() { return currentPhase; } + public static Phase getDDLPhase() { + return currentDdlPhase; + } + public static String getOldVersion() { return oldVersion; } @@ -3642,6 +3661,7 @@ private class StatusForFrontEnd implements JSONString { private final int pages = SurveyMain.pages; private Object permissions = null; private final Phase phase = phase(); + private final Phase ddlPhase = getDDLPhase(); private String sessionId = null; private final String specialHeader = getSpecialHeaderText(); private final long surveyRunningStamp = SurveyMain.surveyRunningStamp.current(); @@ -3675,6 +3695,7 @@ private JSONObject toJSONObject() throws JSONException { .put("pages", pages) .put("permissions", permissions) .put("phase", phase) + .put("ddlPhase", ddlPhase) .put("sessionId", sessionId) .put("sessionMessage", sessionMessage) .put("specialHeader", specialHeader) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRConfig.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRConfig.java index 3e0f7d17596..9d813ce37b4 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRConfig.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRConfig.java @@ -400,6 +400,14 @@ public synchronized Phase getPhase() { return phase; } + /** + * @returns the phase for DDL (non-TC) locales. Defaults to same as main phase. + */ + public Phase getDDLPhase() { + // by default, same as main phase. + return getPhase(); + } + @Override public String getProperty(String key, String d) { String result = getProperty(key); From 8ece119b46290ccab2eb0604ec192676e48ddd37 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Mon, 10 Jun 2024 18:37:12 -0500 Subject: [PATCH 02/10] CLDR-16835 add SubmissionLocales.isTcLocale() - includes test - a TC locale includes those whose parents are TC locales. --- .../java/org/unicode/cldr/web/SurveyAjax.java | 2 +- .../unicode/cldr/test/SubmissionLocales.java | 14 +++++++++++++ .../cldr/test/TestSubmissionLocales.java | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java index 50b647f5b36..78b3bb218ba 100644 --- a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java +++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyAjax.java @@ -1119,7 +1119,7 @@ private static JSONObject createJSONLocMap(SurveyMain sm) throws JSONException { locale.put("highestParent", loc.getHighestNonrootParent()); locale.put("dcParent", dcParent); locale.put("dcChild", dcChild); - locale.put("tc", SubmissionLocales.TC_ORG_LOCALES.contains(loc.getBaseName())); + locale.put("tc", SubmissionLocales.isTcLocale(loc)); locale.put( "type", Factory.getSourceTreeType(disk.getSourceDirectoryForLocale(loc.getBaseName()))); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/SubmissionLocales.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/SubmissionLocales.java index a0ec4cc629b..471f25fb161 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/SubmissionLocales.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/SubmissionLocales.java @@ -12,6 +12,7 @@ import java.util.concurrent.ExecutionException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.unicode.cldr.util.CLDRLocale; import org.unicode.cldr.util.GrammarInfo; import org.unicode.cldr.util.Level; import org.unicode.cldr.util.Organization; @@ -248,4 +249,17 @@ public static boolean pathAllowedInLimitedSubmission(String path) { public static Set getReportsAvailableInLimited() { return LIMITED_SUBMISSION_REPORTS; } + + public static boolean isTcLocale(CLDRLocale loc) { + if (loc == CLDRLocale.ROOT + || SubmissionLocales.TC_ORG_LOCALES.contains(loc.getBaseName())) { + // root or explicitly listed locale is a TC locale + return true; + } else if (loc.isParentRoot()) { + // any sublocale of root not listed is not a tc locale + return false; + } else { + return isTcLocale(loc.getParent()); + } + } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/test/TestSubmissionLocales.java b/tools/cldr-code/src/test/java/org/unicode/cldr/test/TestSubmissionLocales.java index cd007c3cb2c..7880722db4d 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/test/TestSubmissionLocales.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/test/TestSubmissionLocales.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeFalse; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -10,6 +11,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; +import org.junit.jupiter.params.provider.CsvSource; +import org.unicode.cldr.util.CLDRLocale; public class TestSubmissionLocales { @ParameterizedTest @@ -69,4 +72,22 @@ void TestSubmissionLocale() { public static final boolean bool(final String s) { return Boolean.parseBoolean(s); } + + @ParameterizedTest + @CsvSource({ + // loc, isTc + "root, true", + "de, true", + "de_IT, true", + "csw, false", + "cho_US, false", + "zh, true", + "zh_Hant_MO, true", + }) + public void testIsTcLocale(final String loc, final String tf) { + final CLDRLocale l = CLDRLocale.getInstance(loc); + assertNotNull(l, loc); + final Boolean isCldr = Boolean.parseBoolean(tf); + assertEquals(isCldr, SubmissionLocales.isTcLocale(l)); + } } From ef44a9d2caa891b2909fb243ece6e957af6a3c3d Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Mon, 10 Jun 2024 19:42:54 -0500 Subject: [PATCH 03/10] CLDR-16835 ddlLocale - add notifier for locMap change - add UI to show special phase for non-TC locales --- tools/cldr-apps/js/src/esm/cldrLoad.mjs | 28 ++++++++++++++++- tools/cldr-apps/js/src/esm/cldrStatus.mjs | 5 +++ tools/cldr-apps/js/src/views/MainHeader.vue | 34 ++++++++++++++------- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/tools/cldr-apps/js/src/esm/cldrLoad.mjs b/tools/cldr-apps/js/src/esm/cldrLoad.mjs index 25fcaf2df04..1cdde412622 100644 --- a/tools/cldr-apps/js/src/esm/cldrLoad.mjs +++ b/tools/cldr-apps/js/src/esm/cldrLoad.mjs @@ -1049,10 +1049,30 @@ function getLocaleDir(locale) { return localeDir; } +/** @returns true if locmap has been loaded from data */ +function localeMapReady() { + return !!locmap.locmap; +} + +/** event ID for localeMap changes */ +const LOCALEMAP_EVENT = "localeMapReady"; + +/** + * Calls the callback when the localeMap is ready (with real data). + * Calls right away if the localeMap was already loaded. + */ +function onLocaleMapReady(callback) { + if (localeMapReady()) { + callback(); + } else { + cldrStatus.on(LOCALEMAP_EVENT, callback); + } +} + function setTheLocaleMap(lm) { locmap = lm; + cldrStatus.dispatchEvent(new Event(LOCALEMAP_EVENT)); } - /** * Convenience for calling getTheLocaleMap().getLocaleName(loc) * @param {String} loc @@ -1062,6 +1082,10 @@ function getLocaleName(loc) { return locmap.getLocaleName(loc); } +function getLocaleInfo(loc) { + return locmap.getLocaleInfo(loc); +} + /** * Get the window location hash * @@ -1145,6 +1169,7 @@ export { flipToOtherDiv, getHash, getLocaleDir, + getLocaleInfo, getLocaleName, getTheLocaleMap, handleCoverageChanged, @@ -1152,6 +1177,7 @@ export { linkToLocale, localeSpecialNote, myLoad, + onLocaleMapReady, parseHashAndUpdate, reloadV, replaceHash, diff --git a/tools/cldr-apps/js/src/esm/cldrStatus.mjs b/tools/cldr-apps/js/src/esm/cldrStatus.mjs index bdc35ba282d..98b1d0a9812 100644 --- a/tools/cldr-apps/js/src/esm/cldrStatus.mjs +++ b/tools/cldr-apps/js/src/esm/cldrStatus.mjs @@ -49,6 +49,10 @@ function on(type, callback) { getStatusTarget().addEventListener(type, callback); } +/** + * Fire off an event manually + * @param type the type to dispatch + */ function dispatchEvent(type) { return getStatusTarget().dispatchEvent(type); } @@ -477,6 +481,7 @@ function setAutoImportBusy(busy) { } export { + dispatchEvent, getAutoImportBusy, getContextPath, getCurrentId, diff --git a/tools/cldr-apps/js/src/views/MainHeader.vue b/tools/cldr-apps/js/src/views/MainHeader.vue index 3a8d4a7532c..6d1fca9269a 100644 --- a/tools/cldr-apps/js/src/views/MainHeader.vue +++ b/tools/cldr-apps/js/src/views/MainHeader.vue @@ -1,7 +1,8 @@