Skip to content

Commit

Permalink
CLDR-16101 make subtype lookup configurable, fix ui
Browse files Browse the repository at this point in the history
- config parameter CLDR_SUBTYPE_URL for configuring subtype map
- fix reloading page
  • Loading branch information
srl295 committed Apr 19, 2024
1 parent dde975c commit 25cdbc5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 7 additions & 2 deletions tools/cldr-apps/js/src/esm/cldrErrorSubtypes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as cldrAjax from "./cldrAjax.mjs";
import * as cldrLoad from "./cldrLoad.mjs";
import * as cldrStatus from "./cldrStatus.mjs";
import * as cldrSurvey from "./cldrSurvey.mjs";
import * as cldrDom from "./cldrDom.mjs";

const instructions =
"<p>\n" +
Expand Down Expand Up @@ -141,10 +142,14 @@ function reloadMapHandler(json) {
}
} else {
html += "<p>" + json.status + "</p>";
html += redirectSoon;
window.setTimeout(load, coupleSeconds);
}
html += redirectSoon;
el.innerHTML = html;
window.setTimeout(load, coupleSeconds);
if (json.err) {
const b = cldrDom.createLinkToFn('special_error_subtypes', load, 'button');
el.appendChild(b);
}
}

function setOnClicks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ private static void getRecheck(SurveyJSONWrapper r, String recheck)
throws MalformedURLException {
if (recheck.startsWith("MAP")) {
try {
SubtypeToURLMap map = SubtypeToURLMap.reload();
// load directly to make sure there are no errors
SubtypeToURLMap map = SubtypeToURLMap.makeDefaultInstance();
if (map == null) {
r.put("err", "FAILED. Check for errors.");
} else {
SubtypeToURLMap.setDefaultInstance(map);
r.put("status", "SUCCESS!");
}
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype;
import org.unicode.cldr.test.CheckCLDR.SubtypeToURLProvider;
import org.unicode.cldr.util.CLDRCacheDir;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRTool;

@CLDRTool(
Expand All @@ -53,7 +54,8 @@ public class SubtypeToURLMap implements SubtypeToURLProvider {
public static void main(String args[]) throws FileNotFoundException, IOException {
if (args.length == 0) {
System.err.println(
"Usage: SubtypeToURLMap (url or file path). The default map is " + DEFAULT_URL);
"Usage: SubtypeToURLMap (url or file path). The default map is "
+ getDefaultUrl());
return;
} else {
int problems = 0;
Expand Down Expand Up @@ -447,7 +449,7 @@ static SubtypeToURLMap make() {
}
}
try {
map = SubtypeToURLMap.getInstance(new URL(getDefaultUrl()));
map = makeDefaultInstance();
logger.info("Read new map from " + getDefaultUrl());
// now, write out the cache
writeToCache(map);
Expand Down Expand Up @@ -492,7 +494,7 @@ private static void writeToCache(SubtypeToURLMap map) {
* @return
*/
public static String getDefaultUrl() {
return DEFAULT_URL;
return CLDRConfig.getInstance().getProperty("CLDR_SUBTYPE_URL", DEFAULT_URL);
}
/**
* Get the default instance.
Expand All @@ -511,6 +513,17 @@ public static String forSubtype(Subtype subtype) {
public static SubtypeToURLMap reload() {
return (SubtypeToURLMapHelper.INSTANCE = SubtypeToURLMapHelper.make());
}

/** call this to propagate loading */
public static SubtypeToURLMap makeDefaultInstance()
throws IOException, URISyntaxException, MalformedURLException {
return SubtypeToURLMap.getInstance(new URL(getDefaultUrl()));
}

public static void setDefaultInstance(SubtypeToURLMap m) {
SubtypeToURLMapHelper.INSTANCE = m;
}

@Override
public String apply(Subtype t) {
return forSubtype(t);
Expand Down

0 comments on commit 25cdbc5

Please sign in to comment.