1 package org.unicode.cldr.util; 2 3 /** 4 * Generate URLs to parts of CLDR and the SurveyTool. You can change the urls used with for example, 5 * -DCLDR_SURVEY_BASE=http://st.unicode.org/smoketest 6 * 7 * @author srl 8 */ 9 public abstract class CLDRURLS { 10 public static final String CLDR_SCHEMA_BASE = "https://schemas.unicode.org/cldr"; 11 public static final String CLDR_CURVER_BASE = CLDR_SCHEMA_BASE + "/" + CLDRFile.GEN_VERSION; 12 /** Base URL for the CLDR repository */ 13 public static final String CLDR_REPO_BASE = "https://github.com/unicode-org/cldr/"; 14 15 public static final String CLDR_REPO_MAIN = CLDR_REPO_BASE + "blob/main/"; 16 public static final String CLDR_STAGING_REPO_MAIN = 17 "https://github.com/unicode-org/cldr-staging/blob/main/"; 18 19 public static final String DEFAULT_COMMIT_BASE = CLDR_REPO_BASE + "commit/"; 20 /** Hostname for the Survey Tool */ 21 public static final String DEFAULT_HOST = "st.unicode.org"; 22 23 public static final String DEFAULT_PATH = "/cldr-apps"; 24 public static final String DEFAULT_BASE = "https://" + DEFAULT_HOST + DEFAULT_PATH; 25 /** URL for filing a new ticket */ 26 public static final String CLDR_NEWTICKET_URL = 27 "https://cldr.unicode.org/index/bug-reports#TOC-Filing-a-Ticket"; 28 29 public static final String CLDR_REPO_ROOT = "https://github.com/unicode-org/cldr"; 30 public static final String CLDR_HOMEPAGE = "https://cldr.unicode.org"; 31 public static final String UNICODE_CONSORTIUM = "The Unicode Consortium"; 32 public static final String CLDR_UPDATINGDTD_URL = CLDR_HOMEPAGE + "/development/updating-dtds"; 33 /** Our license, in SPDX format */ 34 public static final String UNICODE_SPDX = "Unicode-3.0"; 35 /** 36 * See: 37 * https://spdx.github.io/spdx-spec/appendix-V-using-SPDX-short-identifiers-in-source-files/ 38 */ 39 public static final String UNICODE_SPDX_HEADER = "SPDX-License-Identifier: " + UNICODE_SPDX; 40 /** 41 * Override this property if you want to change the absolute URL to the SurveyTool base from 42 * DEFAULT_BASE 43 */ 44 public static final String CLDR_SURVEY_BASE = "CLDR_SURVEY_BASE"; 45 /** 46 * Override this property if you want to change the relative URL to the SurveyTool base from 47 * DEFAULT_PATH (within SurveyTool only) 48 */ 49 public static final String CLDR_SURVEY_PATH = "CLDR_SURVEY_PATH"; 50 51 public static final String TOOLSURL = "http://cldr.unicode.org/tools/"; 52 53 /** 54 * "special" pages 55 * 56 * @author srl 57 */ 58 public enum Special { 59 /** The 'main' view */ 60 Survey(""), 61 /** The list of locales */ 62 Locales, 63 /** The vetting viewer (i.e. Dashboard) */ 64 Vetting("dashboard"), 65 /** Forums. use "id" for the numeric post id */ 66 Forum; 67 Special(String s)68 Special(String s) { 69 this.id = s; 70 } 71 72 /** Convenience - just lowercases */ Special()73 Special() { 74 this.id = this.name().toLowerCase(); 75 } 76 77 private final String id; 78 } 79 80 protected static String VPATH = "/v#"; 81 /** Constant for an unknown git revision. Use the same in the builders. */ 82 public static final String UNKNOWN_REVISION = "(unknown)"; 83 84 public static final String GENERAL_HELP_URL = "https://cldr.unicode.org/translation/"; 85 public static final String ADMIN_HELP_URL = 86 "https://cldr.unicode.org/index/survey-tool/survey-tool-administration"; 87 public static final String CAPITALIZATION_URL = 88 "https://cldr.unicode.org/translation/translation-guide-general/capitalization"; 89 public static final String CHARACTERS_HELP = "https://cldr.unicode.org/translation/characters"; 90 public static final String CHARACTER_LABELS = 91 "https://cldr.unicode.org/translation/characters/character-labels"; 92 public static final String CHARTS_URL = "https://cldr.unicode.org/index/charts#TOC-Summary"; 93 public static final String COMPOUND_UNITS_HELP = 94 "https://cldr.unicode.org/translation/units/unit-names-and-patterns#h.7kdholgw8hpx"; 95 public static final String COUNTRY_NAMES = 96 "https://cldr.unicode.org/translation/displaynames/countryregion-territory-names"; 97 public static final String CURRENCY_NAMES = 98 "https://cldr.unicode.org/translation/currency-names-and-symbols"; 99 public static final String DATE_TIME_HELP = 100 "https://cldr.unicode.org/translation/date-time/date-time-names#h.ewzjebmpoi4k"; 101 public static final String DATE_TIME_NAMES = 102 "https://cldr.unicode.org/translation/date-time/date-time-names"; 103 public static final String DATE_TIME_NAMES_CYCLIC = 104 "https://cldr.unicode.org/translation/date-time/date-time-names#h.h0vy2eyzcj0n"; 105 public static final String DATE_TIME_NAMES_FIELD = 106 "https://cldr.unicode.org/translation/date-time/date-time-names#h.8wfk3599ck9x"; 107 public static final String DATE_TIME_NAMES_MONTH = 108 "https://cldr.unicode.org/translation/date-time/date-time-names#h.fww3pfyk0uwn"; 109 public static final String DATE_TIME_NAMES_RELATIVE = 110 "https://cldr.unicode.org/translation/date-time/date-time-names#h.aevw0tiix80v"; 111 public static final String DATE_TIME_PATTERNS = 112 "https://cldr.unicode.org/translation/date-time/date-time-patterns"; 113 public static final String DATE_TIME_PATTERNS_URL = 114 "https://cldr.unicode.org/translation/date-time/date-time-patterns"; 115 public static final String ERRORS_URL = 116 "https://cldr.unicode.org/translation/error-and-warning-codes"; 117 public static final String EXEMPLAR_CHARACTERS = 118 "https://cldr.unicode.org/translation/core-data/exemplars"; 119 public static final String GRAMMATICAL_INFLECTION = 120 "https://cldr.unicode.org/translation/grammatical-inflection"; 121 public static final String KEY_NAMES = 122 "https://cldr.unicode.org/translation/displaynames/countryregion-territory-names#h.x27jspwj91af"; 123 public static final String LANGUAGE_NAMES = 124 "https://cldr.unicode.org/translation/displaynames/languagelocale-names"; 125 public static final String LISTS_HELP = 126 "https://cldr.unicode.org/translation/miscellaneous-displaying-lists"; 127 public static final String LOCALE_PATTERN = 128 "https://cldr.unicode.org/translation/displaynames/languagelocale-name-patterns"; 129 public static final String NUMBERING_SYSTEMS = 130 "https://cldr.unicode.org/translation/core-data/numbering-systems"; 131 public static final String NUMBERS_HELP = 132 "https://cldr.unicode.org/translation/currency-names-and-symbols"; 133 public static final String NUMBERS_PLURAL = 134 "https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns#h.mnb2fmj0pt72"; 135 public static final String NUMBERS_SHORT = 136 "https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns#h.eradhhuxzqqz"; 137 public static final String NUMBER_PATTERNS = 138 "https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns#h.j899g3kk2p1z"; 139 public static final String PARSE_LENIENT = 140 "https://cldr.unicode.org/translation/core-data/characters#h.j3x0cwalqgqt"; 141 public static final String PERSON_NAME_FORMATS = 142 "https://cldr.unicode.org/translation/miscellaneous-person-name-formats"; 143 public static final String PLURALS_HELP = 144 "https://cldr.unicode.org/translation/getting-started/plurals"; 145 public static final String PLURALS_HELP_MINIMAL = 146 "https://cldr.unicode.org/translation/getting-started/plurals#h.pnla5cp3nl4l"; 147 public static final String SCRIPT_NAMES = 148 "https://cldr.unicode.org/translation/displaynames/script-names"; 149 public static final String SHORT_CHARACTER_NAMES = 150 "https://cldr.unicode.org/translation/characters/short-names-and-keywords#h.4a8wthj27m74"; 151 public static final String TRANSFORMS_HELP = "https://cldr.unicode.org/translation/transforms"; 152 public static final String TYPOGRAPHIC_NAMES = 153 "https://cldr.unicode.org/translation/characters/typographic-names"; 154 public static final String TZ_CITY_NAMES = 155 "https://cldr.unicode.org/translation/time-zones-and-city-names"; 156 public static final String UNITS_HELP = "https://cldr.unicode.org/translation/units"; 157 /* 158 * TODO: UNITS_MISC_HELP, formerly "https://cldr.unicode.org/translation/units-1/misc", 159 * now temporarily (?) the same as UNITS_HELP until a distinct URL is identified 160 * Reference: https://unicode-org.atlassian.net/browse/CLDR-15080 161 */ 162 public static final String UNITS_MISC_HELP = UNITS_HELP; 163 164 public static final String PRIORITY_SUMMARY_HELP_URL = 165 "https://cldr.unicode.org/translation/getting-started/vetting-view#TOC-Priority-Items"; 166 167 public static final String UPDATING_CURRENCY_CODES = 168 "https://cldr.unicode.org/development/updating-codes/update-currency-codes"; 169 170 public static final String CLDR_ARCHIVE = 171 "https://cldr.unicode.org/development/creating-the-archive"; 172 173 /** 174 * Get the relative base URL for the SurveyTool. This may be "/cldr-apps", for example. 175 * 176 * @return example, "/cldr-apps" 177 */ base()178 public abstract String base(); 179 180 /** 181 * please use CLDRLocale instead 182 * 183 * @param locale 184 * @param xpath 185 * @return 186 */ forXpath(String locale, String xpath)187 public String forXpath(String locale, String xpath) { 188 return forXpath(CLDRLocale.getInstance(locale), xpath); 189 } 190 191 /** 192 * Get a link to a specific xpath and locale. 193 * 194 * @param locale locale to view 195 * @param xpath the xpath to view 196 */ forXpath(CLDRLocale locale, String xpath)197 public final String forXpath(CLDRLocale locale, String xpath) { 198 assertIsXpath(xpath); 199 final String hexid = (xpath == null) ? null : StringId.getHexId(xpath); 200 return forXpathHexId(locale, hexid); 201 } 202 203 /** 204 * please use CLDRLocale instead 205 * 206 * @param locale 207 * @param hexid 208 * @return 209 */ forXpathHexId(String locale, String hexid)210 public final String forXpathHexId(String locale, String hexid) { 211 return forXpathHexId(CLDRLocale.getInstance(locale), hexid); 212 } 213 214 /** 215 * Get a link to a specific xpath hex ID and locale. 216 * 217 * @param locale 218 * @param hexid 219 * @return 220 */ forXpathHexId(CLDRLocale locale, String hexid)221 public final String forXpathHexId(CLDRLocale locale, String hexid) { 222 assertIsHexId(hexid); 223 return forSpecial(Special.Survey, locale, (String) null, hexid); 224 } 225 226 /** 227 * please use CLDRLocale instead 228 * 229 * @param locale 230 * @param hexid 231 * @return 232 */ forXpathHexId(String locale, PathHeader.PageId page, String hexid)233 public final String forXpathHexId(String locale, PathHeader.PageId page, String hexid) { 234 return forXpathHexId(CLDRLocale.getInstance(locale), page, hexid); 235 } 236 237 /** 238 * Get a link to a specific xpath hex ID and locale. 239 * 240 * @param locale 241 * @param hexid 242 * @return 243 */ forXpathHexId(CLDRLocale locale, PathHeader.PageId page, String hexid)244 public final String forXpathHexId(CLDRLocale locale, PathHeader.PageId page, String hexid) { 245 assertIsHexId(hexid); 246 return forSpecial(Special.Survey, locale, page, hexid); 247 } 248 249 /** 250 * please use CLDRLocale instead 251 * 252 * @param locale 253 * @param page 254 * @return 255 */ forPage(String locale, PathHeader.PageId page)256 public final String forPage(String locale, PathHeader.PageId page) { 257 return forPage(CLDRLocale.getInstance(locale), page); 258 } 259 forPage(CLDRLocale locale, PathHeader.PageId page)260 public final String forPage(CLDRLocale locale, PathHeader.PageId page) { 261 return forSpecial(Special.Survey, locale, page.name(), null); 262 } 263 264 /** 265 * Get a link to a specific locale in the SurveyTool. 266 * 267 * @param locale 268 * @return 269 */ forLocale(CLDRLocale locale)270 public final String forLocale(CLDRLocale locale) { 271 return forXpath(locale, null); 272 } 273 forSpecial( Special special, CLDRLocale locale, PathHeader.PageId page, String hexid)274 public final String forSpecial( 275 Special special, CLDRLocale locale, PathHeader.PageId page, String hexid) { 276 return forSpecial(special, locale, page.name(), hexid); 277 } 278 forSpecial(Special special)279 public final String forSpecial(Special special) { 280 return forSpecial(special, (CLDRLocale) null, (String) null, null); 281 } 282 forSpecial(Special special, CLDRLocale locale)283 public final String forSpecial(Special special, CLDRLocale locale) { 284 return forSpecial(special, locale, (String) null, null); 285 } 286 287 /** 288 * Get a link from all of the parts. 289 * 290 * @param special 291 * @param locale 292 * @param page 293 * @param xpath 294 * @return 295 */ forSpecial(Special special, CLDRLocale locale, String page, String hexid)296 public String forSpecial(Special special, CLDRLocale locale, String page, String hexid) { 297 StringBuilder sb = new StringBuilder(base()); 298 sb.append(VPATH); 299 if (special != null) { 300 sb.append(special.id); 301 } 302 sb.append('/'); 303 if (locale != null) { 304 sb.append(locale.getBaseName()); 305 } 306 sb.append('/'); 307 if (page != null) { 308 sb.append(page); 309 } 310 sb.append('/'); 311 if (hexid != null) { 312 sb.append(hexid); 313 } 314 return sb.toString(); 315 } 316 317 /** 318 * @param hexid 319 * @throws IllegalArgumentException 320 */ assertIsHexId(String hexid)321 public final void assertIsHexId(String hexid) throws IllegalArgumentException { 322 if (hexid != null && hexid.startsWith("/")) { 323 throw new IllegalArgumentException( 324 "This function takes a hex StringID: perhaps you meant to use forXpath() instead."); 325 } 326 } 327 328 /** 329 * @param xpath 330 * @throws IllegalArgumentException 331 */ assertIsXpath(String xpath)332 public final void assertIsXpath(String xpath) throws IllegalArgumentException { 333 if (xpath != null && !xpath.startsWith("/")) { 334 throw new IllegalArgumentException( 335 "This function takes an XPath: perhaps you meant to use forXpathHexId() instead."); 336 } 337 } 338 339 /** 340 * please use CLDRLocale instead 341 * 342 * @param vetting 343 * @param localeID 344 * @return 345 */ forSpecial(Special special, String localeID)346 public final String forSpecial(Special special, String localeID) { 347 return forSpecial(special, CLDRLocale.getInstance(localeID)); 348 } 349 forPathHeader(String locale, PathHeader pathHeader)350 public final String forPathHeader(String locale, PathHeader pathHeader) { 351 return forPathHeader(CLDRLocale.getInstance(locale), pathHeader); 352 } 353 354 /** 355 * This is the preferred function for jumping to an item relatively. It will reduce blinkage. 356 * 357 * @param locale 358 * @param pathHeader 359 * @return 360 */ forPathHeader(CLDRLocale locale, PathHeader pathHeader)361 public final String forPathHeader(CLDRLocale locale, PathHeader pathHeader) { 362 return forSpecial( 363 Special.Survey, 364 locale, 365 pathHeader.getPageId(), 366 StringId.getHexId(pathHeader.getOriginalPath())); 367 } 368 369 /** 370 * For a given hash, return as a link 371 * 372 * @param hash 373 * @return 374 */ gitHashToLink(String hash)375 public static String gitHashToLink(String hash) { 376 if (!isKnownHash(hash)) 377 return "<span class=\"githashLink\">" + hash + "</span>"; // Not linkifiable 378 return "<a class=\"githashLink\" href=\"" 379 + CldrUtility.getProperty("CLDR_COMMIT_BASE", DEFAULT_COMMIT_BASE) 380 + hash 381 + "\">" 382 + hash.substring(0, 8) 383 + "</a>"; 384 } 385 386 /** 387 * Is this a 'known' git hash? Or unknown? 388 * 389 * @param hash 390 * @return true if known, false if (unknown) 391 */ isKnownHash(String hash)392 public static boolean isKnownHash(String hash) { 393 return !hash.equals(UNKNOWN_REVISION); 394 } 395 396 /** 397 * Convert a URL into an HTML link to itself 398 * 399 * @param url 400 * @return 401 */ toHTML(String url)402 public static final String toHTML(String url) { 403 return "<a href=\"" + url + "\">" + url + "</a>"; 404 } 405 406 /** 407 * Provide the styles for inclusion into the ST <head> element. 408 * 409 * @return 410 */ getVettingViewerHeaderStyles()411 public static String getVettingViewerHeaderStyles() { 412 return "<style>\n" 413 + ".hide {display:none}\n" 414 + ".vve {}\n" 415 + ".vvn {}\n" 416 + ".vvp {}\n" 417 + ".vvl {}\n" 418 + ".vvm {}\n" 419 + ".vvu {}\n" 420 + ".vvw {}\n" 421 + ".vvd {}\n" 422 + ".vvo {}\n" 423 + "</style>"; 424 } 425 } 426