kopia lustrzana https://github.com/onthegomap/planetiler
Switch ordering of translation providers (#403)
rodzic
2dc4bc660c
commit
926bc9210b
|
@ -506,7 +506,7 @@ public class Planetiler {
|
||||||
Wikidata.fetch(osmInputFile(), wikidataNamesFile, config(), profile(), stats());
|
Wikidata.fetch(osmInputFile(), wikidataNamesFile, config(), profile(), stats());
|
||||||
}
|
}
|
||||||
if (useWikidata) {
|
if (useWikidata) {
|
||||||
translations().addTranslationProvider(Wikidata.load(wikidataNamesFile));
|
translations().addFallbackTranslationProvider(Wikidata.load(wikidataNamesFile));
|
||||||
}
|
}
|
||||||
if (onlyDownloadSources || onlyFetchWikidata) {
|
if (onlyDownloadSources || onlyFetchWikidata) {
|
||||||
return; // exit only if just fetching wikidata or downloading sources
|
return; // exit only if just fetching wikidata or downloading sources
|
||||||
|
|
|
@ -45,14 +45,25 @@ public class Translations {
|
||||||
* @param languages the set of 2-letter language codes to limit output translations to
|
* @param languages the set of 2-letter language codes to limit output translations to
|
||||||
*/
|
*/
|
||||||
public static Translations defaultProvider(List<String> languages) {
|
public static Translations defaultProvider(List<String> languages) {
|
||||||
return nullProvider(languages).addTranslationProvider(new OsmTranslationProvider());
|
return nullProvider(languages).addFallbackTranslationProvider(new OsmTranslationProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mutates this translation instance to add {@code provider} which will be used before all other providers.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public Translations addTranslationProvider(TranslationProvider provider) {
|
||||||
|
providers.add(0, provider);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutates this translation instance to add {@code provider} which will be used only if all existing providers fail to
|
* Mutates this translation instance to add {@code provider} which will be used only if all existing providers fail to
|
||||||
* produce a translation for a given language.
|
* produce a translation for a given language.
|
||||||
*/
|
*/
|
||||||
public Translations addTranslationProvider(TranslationProvider provider) {
|
public Translations addFallbackTranslationProvider(TranslationProvider provider) {
|
||||||
providers.add(provider);
|
providers.add(provider);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +86,7 @@ public class Translations {
|
||||||
for (var entry : translations.entrySet()) {
|
for (var entry : translations.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
if (languageSet.contains(key)) {
|
if (languageSet.contains(key)) {
|
||||||
output.put(key.startsWith("name:") ? key : "name:" + key, entry.getValue());
|
output.putIfAbsent(key.startsWith("name:") ? key : "name:" + key, entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,14 @@ class TranslationsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTwoProviders() {
|
void testTwoProvidersPrefersFirst() {
|
||||||
var translations = Translations.defaultProvider(List.of("en", "es", "de"))
|
var translations = Translations.defaultProvider(List.of("en", "es", "de"))
|
||||||
.addTranslationProvider(elem -> Map.of("name:de", "de2", "name:en", "en2"));
|
.addFallbackTranslationProvider(elem -> Map.of("name:de", "de2", "name:en", "en2"));
|
||||||
assertEquals(Map.of("name:en", "en2", "name:es", "es1", "name:de", "de2"),
|
assertEquals(Map.of("name:en", "en1", "name:es", "es1", "name:de", "de2"),
|
||||||
translations.getTranslations(Map.of("name:en", "en1", "name:es", "es1")));
|
translations.getTranslations(Map.of("name:en", "en1", "name:es", "es1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTransliterate() {
|
void testTransliterate() {
|
||||||
assertEquals("rì běn", Translations.transliterate("日本"));
|
assertEquals("rì běn", Translations.transliterate("日本"));
|
||||||
|
|
Ładowanie…
Reference in New Issue