Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/main/java/org/mtransit/parser/DefaultAgencyTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,30 @@ public void start(@NotNull String[] args) {
}

@NotNull
private final List<Locale> supportedLanguages = new ArrayList<>();
private final List<Locale> agencySupportedLanguages = new ArrayList<>();

@Nullable
private List<Locale> allLanguages = null;
Comment thread
mmathieum marked this conversation as resolved.

@Override
public void addSupportedLanguage(@Nullable String supportedLanguage) {
if (supportedLanguage == null) {
return;
}
if (supportedLanguage == null) return;
final Locale supportedLocale = Locale.forLanguageTag(supportedLanguage);
if (this.supportedLanguages.contains(supportedLocale)) {
return;
}
this.supportedLanguages.add(supportedLocale);
if (this.agencySupportedLanguages.contains(supportedLocale)) return;
this.agencySupportedLanguages.add(supportedLocale);
Comment thread
mmathieum marked this conversation as resolved.
}

@Nullable
@Override
public List<Locale> getSupportedLanguages() {
if (!this.supportedLanguages.isEmpty()) {
return this.supportedLanguages;
if (this.allLanguages != null) return this.allLanguages; // cached
if (this.agencySupportedLanguages.isEmpty()) return null; // no-op
if (Configs.getAgencyConfig() != null) {
this.allLanguages = Configs.getAgencyConfig().getAllLanguages(this.agencySupportedLanguages);
} else {
this.allLanguages = this.agencySupportedLanguages;
}
return null; // no-op
return this.allLanguages;
Comment thread
mmathieum marked this conversation as resolved.
Comment thread
mmathieum marked this conversation as resolved.
}

@SuppressWarnings("WeakerAccess")
Expand Down Expand Up @@ -1277,14 +1280,21 @@ public String getStopCode(@NotNull GStop gStop) {
final String prepend = getStopCodePrependIfMissing();
//noinspection DiscouragedApi
final String stopCode =
Configs.getRouteConfig().getUseStopIdForStopCode() ? gStop.getStopId() :
gStop.getStopCode();
cleanStopCode(
Configs.getRouteConfig().getUseStopIdForStopCode() ? gStop.getStopId() :
gStop.getStopCode()
);
Comment thread
mmathieum marked this conversation as resolved.
if (prepend != null && !stopCode.startsWith(prepend)) {
return prepend + stopCode;
}
Comment thread
mmathieum marked this conversation as resolved.
return stopCode;
}

@NotNull
private String cleanStopCode(@NotNull String stopCode) {
return Configs.getRouteConfig().cleanStopCode(getFirstLanguageNN(), stopCode);
Comment thread
mmathieum marked this conversation as resolved.
}

@Deprecated
@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.mtransit.parser.config.gtfs.data

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.util.Locale

@Serializable
data class AgencyConfig(
Expand All @@ -28,6 +29,8 @@ data class AgencyConfig(
val originalRouteTypeId: Int = targetRouteTypeId, // REQUIRED (default to target route type ID)
@SerialName("extended_target_route_type_id")
val extendedTargetRouteTypeId: Int? = null, // OPTIONAL
@SerialName("additional_languages")
val additionalLanguages: List<String> = emptyList(), // OPT-IN feature
// STRINGS
/**
* (Optional) Default string cleaner enabled/disabled (based on language/country/field)
Expand Down Expand Up @@ -58,4 +61,10 @@ data class AgencyConfig(
val serviceIdCleanMerged: Boolean = false, // OPT-IN feature
@SerialName("service_id_not_unique_allowed")
val serviceIdNotUniqueAllowed: Boolean = false, // OPT-IN feature
)
) {
fun getAllLanguages(supportedLanguages: List<Locale>): List<Locale>? {
if (supportedLanguages.isEmpty()) return null
if (additionalLanguages.isEmpty()) return supportedLanguages
return (supportedLanguages + additionalLanguages.map { Locale.forLanguageTag(it) }).distinct()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ data class RouteConfig(
val stopIdPreviousCharConfigs: List<IdCharToIdPartConfig> = emptyList(),
@SerialName("stop_original_id_to_stop_id_configs")
val stopOriginalIdToStopIdConfigs: List<StopOriginalIdToStopIdConfig> = emptyList(),
@SerialName("stop_code_cleaners")
val stopCodeCleaners: List<Cleaner> = emptyList(),
@SerialName("stop_code_prepend_if_missing")
val stopCodePrependIfMissing: String? = null, // optional
@SerialName("use_stop_id_hash_code")
Expand Down Expand Up @@ -290,6 +292,9 @@ data class RouteConfig(
fun cleanStopName(lang: Locale, stopName: String) =
cleanString(lang, stopName, this.stopNameCleaners)

fun cleanStopCode(lang: Locale, stopCode: String) =
cleanString(lang, stopCode, this.stopCodeCleaners)

fun cleanStopHeadsign(gRoute: GRoute, gTrip: GTrip, @Suppress("unused") gStopTime: GStopTime, stopHeadsign: String): String {
if (stopHeadsign.isEmpty()) return stopHeadsign
if (stopHeadsignRemoveTripHeadsign && stopHeadsign == gTrip.tripHeadsign) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mtransit/parser/gtfs/GReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static GSpec readGtfsZipFile(@NotNull String gtfsDir,
}
try {
final boolean skipDataCleanup = calendarsOnly || routeTripCalendarsOnly;
// AGENCY
// AGENCY // 1st (setup supported language)
if (!calendarsOnly) {
readFile(gtfsDir, GAgency.FILENAME, true, line ->
processAgency(agencyTools, gSpec, line)
Expand Down