-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
403 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
248 changes: 144 additions & 104 deletions
248
tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtags.java
Large diffs are not rendered by default.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
tools/cldr-code/src/main/java/org/unicode/cldr/tool/LSRSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
} |
Oops, something went wrong.