Skip to content

Commit

Permalink
CLDR-17535 General cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati committed Aug 16, 2024
1 parent ea0f7ab commit 6010495
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 199 deletions.
10 changes: 5 additions & 5 deletions common/supplemental/supplementalData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ XXX Code for transations where no currency is involved
<language type="lv" scripts="Latn" territories="LV"/>
<language type="lwl" scripts="Thai"/>
<language type="lzh" scripts="Hans" alt="secondary"/>
<language type="lzz" scripts="Geor Latn"/>
<language type="lzz" scripts="Latn Geor"/>
<language type="mad" scripts="Latn"/>
<language type="mad" territories="ID" alt="secondary"/>
<language type="maf" scripts="Latn"/>
Expand Down Expand Up @@ -2068,7 +2068,7 @@ XXX Code for transations where no currency is involved
<language type="pl" scripts="Latn" territories="PL"/>
<language type="pl" territories="GB UA" alt="secondary"/>
<language type="pms" scripts="Latn"/>
<language type="pnt" scripts="Cyrl Grek Latn"/>
<language type="pnt" scripts="Grek Cyrl Latn"/>
<language type="pon" scripts="Latn"/>
<language type="pon" territories="FM" alt="secondary"/>
<language type="pqm" scripts="Latn"/>
Expand Down Expand Up @@ -2266,10 +2266,10 @@ XXX Code for transations where no currency is involved
<language type="tk" scripts="Arab Cyrl Latn" territories="TM"/>
<language type="tk" territories="AF IR" alt="secondary"/>
<language type="tkl" scripts="Latn" territories="TK"/>
<language type="tkr" scripts="Cyrl Latn"/>
<language type="tkr" scripts="Latn Cyrl"/>
<language type="tkt" scripts="Deva"/>
<language type="tli" scripts="Latn"/>
<language type="tly" scripts="Arab Cyrl Latn"/>
<language type="tly" scripts="Latn Arab Cyrl"/>
<language type="tly" territories="AZ" alt="secondary"/>
<language type="tmh" scripts="Latn"/>
<language type="tmh" territories="NE" alt="secondary"/>
Expand Down Expand Up @@ -2298,7 +2298,7 @@ XXX Code for transations where no currency is involved
<language type="ttj" scripts="Latn"/>
<language type="tts" scripts="Thai"/>
<language type="tts" territories="TH" alt="secondary"/>
<language type="ttt" scripts="Cyrl Latn"/>
<language type="ttt" scripts="Latn Cyrl"/>
<language type="ttt" scripts="Arab" alt="secondary"/>
<language type="tum" scripts="Latn"/>
<language type="tum" territories="MW" alt="secondary"/>
Expand Down

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions tools/cldr-code/src/main/java/org/unicode/cldr/tool/LSRSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.unicode.cldr.tool;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Comparators;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableSortedSet;
import java.util.Comparator;
import java.util.Objects;
import java.util.Set;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRFile;
import org.unicode.cldr.util.CLDRLocale;

public class LSRSource implements Comparable<LSRSource> {
private static final Joiner JOIN_SPACE = Joiner.on(' ');
private static final Splitter SPLIT_SPACE = Splitter.on(' ').omitEmptyStrings();
private final CLDRLocale cldrLocale;
private final Set<String> sources;

LSRSource(String lang, String script, String region, String sources) {
cldrLocale = CLDRLocale.getInstance(lang, script, region);
this.sources = ImmutableSortedSet.copyOf(SPLIT_SPACE.splitToList(sources));
}

public String getLanguage() {
return cldrLocale.getLanguage();
}

public String getScript() {
return cldrLocale.getScript();
}

public String getRegion() {
return cldrLocale.getRegion();
}

public Set<String> getSources() {
return sources;
}

public String getLsrString() {
return cldrLocale.toString();
}

@Override
public int compareTo(LSRSource other) {
return ComparisonChain.start()
.compare(cldrLocale, other.cldrLocale)
.compare(
sources,
other.sources,
Comparators.lexicographical(Comparator.<String>naturalOrder()))
.result();
}

@Override
public int hashCode() {
return Objects.hash(cldrLocale, sources);
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (!(obj instanceof LSRSource)) return false;

LSRSource other = (LSRSource) obj;
return Objects.equals(cldrLocale, other.cldrLocale)
&& Objects.equals(sources, other.sources);
}

@Override
public String toString() {
return cldrLocale.toString() + " // " + getSources();
}

public String line(String source) {
final CLDRFile english = CLDRConfig.getInstance().getEnglish();

// <likelySubtag from="aa" to="aa_Latn_ET"/>
// <!--{ Afar; ?; ? } => { Afar; Latin; Ethiopia }-->
final String target = cldrLocale.toString();
final String result =
"<likelySubtag from=\""
+ source
+ "\" to=\""
+ target
+ (getSources().isEmpty() ? "" : "\" origin=\"" + getSourceString())
+ "\"/>"
+ "\t<!-- "
+ english.getName(source)
+ " ➡︎ "
+ english.getName(target)
+ " -->";
return result;
}

public String getSourceString() {
return JOIN_SPACE.join(getSources());
}

public CLDRLocale getCldrLocale() {
return cldrLocale;
}

// public static String combineLSR(String lang, String script, String region) {
// return (lang.isEmpty() ? "und" : lang)
// + (script.isEmpty() ? "" : "_" + script)
// + (region.isEmpty() ? "" : "_" + region);
// }
}
Loading

0 comments on commit 6010495

Please sign in to comment.