#3753 Item label/description: Fall back to non-empty language - attempt to read labels by language or the first one in the list (#3759)

This commit is contained in:
Seán Mac Gillicuddy 2020-05-21 00:54:09 +01:00 committed by GitHub
parent de3377c0fe
commit 384afa6c44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View file

@ -75,7 +75,7 @@ class DepictsClient @Inject constructor(
}
fun getEntities(ids: String): Single<Entities> {
return depictsInterface.getEntities(ids, Locale.getDefault().language)
return depictsInterface.getEntities(ids)
}
fun toDepictions(sparqlResponse: Observable<SparqlResponse>): Observable<List<DepictedItem>> {

View file

@ -24,5 +24,5 @@ public interface DepictsInterface {
Single<DepictSearchResponse> searchForDepicts(@Query("search") String query, @Query("limit") String limit, @Query("language") String language, @Query("uselang") String uselang, @Query("continue") String offset);
@GET("/w/api.php?format=json&action=wbgetentities")
Single<Entities> getEntities(@Query("ids")String ids, @Query("languages")String language);
Single<Entities> getEntities(@Query("ids") String ids);
}

View file

@ -9,6 +9,7 @@ import fr.free.nrw.commons.wikidata.WikidataProperties.*
import org.wikipedia.wikidata.DataValue
import org.wikipedia.wikidata.Entities
import org.wikipedia.wikidata.Statement_partial
import java.util.*
/**
* Model class for Depicted Item in Upload and Explore
@ -25,8 +26,8 @@ data class DepictedItem constructor(
constructor(entity: Entities.Entity) : this(
entity,
entity.labels().values.firstOrNull()?.value() ?: "",
entity.descriptions().values.firstOrNull()?.value() ?: ""
entity.labels().byLanguageOrFirstOrEmpty(),
entity.descriptions().byLanguageOrFirstOrEmpty()
)
constructor(entity: Entities.Entity, place: Place) : this(
@ -73,3 +74,5 @@ private val List<Statement_partial>?.primaryImageValue: DataValue.ValueString?
operator fun Entities.Entity.get(property: WikidataProperties) =
statements?.get(property.propertyName)
private fun Map<String, Entities.Label>.byLanguageOrFirstOrEmpty() =
let { it[Locale.getDefault().language] ?: it.values.firstOrNull() }?.value() ?: ""