Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔖 [PR] New default label options and translations #1065

Merged
Show file tree
Hide file tree
Changes from 5 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
35 changes: 35 additions & 0 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,41 @@
"no-travel-hint": "To see more, change the filters above or go record some travel!"
},

"multilabel":{
"walk": "Walk",
"e-bike": "E-bike",
"bike": "Regular Bike",
shankari marked this conversation as resolved.
Show resolved Hide resolved
"bikeshare": "Bikeshare",
"scootershare": "Scooter share",
"drove_alone": "Gas Car Drove Alone",
"shared_ride": "Gas Car Shared Ride",
"e_car_drove_alone": "E-Car Drove Alone",
"e_car_shared_ride": "E-Car Shared Ride",
"moped": "Moped",
"taxi": "Taxi / Uber / Lyft",
"bus": "Bus",
"train": "Train",
"free_shuttle": "Free Shuttle",
"air": "Air",
"not_a_trip": "Not a trip",
"no_travel": "No travel",
"home": "Home",
"work": "To Work",
"at_work": "At Work",
"school": "School",
"transit_transfer": "Transit transfer",
"shopping": "Shopping",
"meal": "Meal",
"pick_drop_person": "Pick-up / Drop off Person",
"pick_drop_item": "Pick-up / Drop off Item",
"personal_med": "Personal / Medical",
"access_recreation": "Access Recreation",
"exercise": "Recreation / Exercise",
"entertainment": "Entertainment / Social",
"religious": "Religious",
"other": "Other"
},

"main-metrics":{
"summary": "My Summary",
"chart": "Chart",
Expand Down
37 changes: 16 additions & 21 deletions www/js/survey/multilabel/confirmHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,24 @@ export async function getLabelOptions(appConfigParam?) {

if (appConfig.label_options) {
const labelOptionsJson = await fetchUrlCached(appConfig.label_options);
logDebug("label_options found in config, using dynamic label options at " + appConfig.label_options);
labelOptions = JSON.parse(labelOptionsJson) as LabelOptions;
/* fill in the translations to the 'text' fields of the labelOptions,
according to the current language */
const lang = i18next.language;
for (const opt in labelOptions) {
labelOptions[opt]?.forEach?.((o, i) => {
const translationKey = o.value;
const translation = labelOptions.translations[lang][translationKey];
labelOptions[opt][i].text = translation;
});
}
} else {
// backwards compat: if dynamic config doesn't have label_options, use the old way
const i18nUtils = getAngularService("i18nUtils");
const optionFileName = await i18nUtils.geti18nFileName("json/", "trip_confirm_options", ".json");
try {
const optionJson = await fetch(optionFileName).then(r => r.json());
labelOptions = optionJson as LabelOptions;
} catch (e) {
logDebug("error "+JSON.stringify(e)+" while reading confirm options, reverting to defaults");
const optionJson = await fetch("json/trip_confirm_options.json.sample").then(r => r.json());
labelOptions = optionJson as LabelOptions;
}
const defaultLabelOptionsURL = 'json/label-options.json.sample';
logDebug("No label_options found in config, using default label options at " + defaultLabelOptionsURL);
const defaultLabelOptionsJson = await fetchUrlCached(defaultLabelOptionsURL);
labelOptions = JSON.parse(defaultLabelOptionsJson) as LabelOptions;
}
/* fill in the translations to the 'text' fields of the labelOptions,
according to the current language */
const lang = i18next.language;
for (const opt in labelOptions) {
labelOptions[opt]?.forEach?.((o, i) => {
const translationKey = o.value;
// If translation exists in labelOptions, use that. Otherwise, use the one in the i18next.
const translation = labelOptions.translations[lang][translationKey] || i18next.t(`multilabel.${translationKey}`);
shankari marked this conversation as resolved.
Show resolved Hide resolved
labelOptions[opt][i].text = translation;
});
}
return labelOptions;
}
Expand Down
124 changes: 124 additions & 0 deletions www/json/label-options.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"MODE": [
{"value":"walk", "baseMode":"WALKING", "met_equivalent":"WALKING", "kgCo2PerKm": 0},
{"value":"e-bike", "baseMode":"E_BIKE", "met": {"ALL": {"range": [0, -1], "mets": 4.9}}, "kgCo2PerKm": 0.00728},
{"value":"bike", "baseMode":"BICYCLING", "met_equivalent":"BICYCLING", "kgCo2PerKm": 0},
{"value":"bikeshare", "baseMode":"BICYCLING", "met_equivalent":"BICYCLING", "kgCo2PerKm": 0},
{"value":"scootershare", "baseMode":"E_SCOOTER", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.00894},
{"value":"drove_alone", "baseMode":"CAR", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.22031},
{"value":"shared_ride", "baseMode":"CAR", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.11015},
{"value":"e_car_drove_alone", "baseMode":"E_CAR", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.08216},
{"value":"e_car_shared_ride", "baseMode":"E_CAR", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.04108},
{"value":"moped", "baseMode":"MOPED", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.05555},
{"value":"taxi", "baseMode":"TAXI", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.30741},
{"value":"bus", "baseMode":"BUS", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.20727},
{"value":"train", "baseMode":"TRAIN", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.12256},
{"value":"free_shuttle", "baseMode":"BUS", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.20727},
{"value":"air", "baseMode":"AIR", "met_equivalent":"IN_VEHICLE", "kgCo2PerKm": 0.09975},
{"value":"not_a_trip", "baseMode":"UNKNOWN", "met_equivalent":"UNKNOWN", "kgCo2PerKm": 0},
{"value":"other", "baseMode":"OTHER", "met_equivalent":"UNKNOWN", "kgCo2PerKm": 0}
],
"PURPOSE": [
{"value":"home"},
{"value":"work"},
{"value":"at_work"},
{"value":"school"},
{"value":"transit_transfer"},
{"value":"shopping"},
{"value":"meal"},
{"value":"pick_drop_person"},
{"value":"pick_drop_item"},
{"value":"personal_med"},
{"value":"access_recreation"},
{"value":"exercise"},
{"value":"entertainment"},
{"value":"religious"},
{"value":"other"}
],
"REPLACED_MODE": [
{"value":"no_travel"},
{"value":"walk"},
{"value":"bike"},
{"value":"bikeshare"},
{"value":"scootershare"},
{"value":"drove_alone"},
{"value":"shared_ride"},
{"value":"e_car_drove_alone"},
{"value":"e_car_shared_ride"},
{"value":"taxi"},
{"value":"bus"},
{"value":"train"},
{"value":"free_shuttle"},
{"value":"other"}
],
"translations": {
"en": {
"walk": "Walk",
"e-bike": "E-bike",
shankari marked this conversation as resolved.
Show resolved Hide resolved
"bike": "Regular Bike",
"bikeshare": "Bikeshare",
"scootershare": "Scooter share",
"drove_alone": "Gas Car Drove Alone",
"shared_ride": "Gas Car Shared Ride",
"e_car_drove_alone": "E-Car Drove Alone",
"e_car_shared_ride": "E-Car Shared Ride",
"moped": "Moped",
"taxi": "Taxi / Uber / Lyft",
"bus": "Bus",
"train": "Train",
"free_shuttle": "Free Shuttle",
"air": "Air",
"not_a_trip": "Not a trip",
"no_travel": "No travel",
"home": "Home",
"work": "To Work",
"at_work": "At Work",
"school": "School",
"transit_transfer": "Transit transfer",
"shopping": "Shopping",
"meal": "Meal",
"pick_drop_person": "Pick-up / Drop off Person",
"pick_drop_item": "Pick-up / Drop off Item",
"personal_med": "Personal / Medical",
"access_recreation": "Access Recreation",
"exercise": "Recreation / Exercise",
"entertainment": "Entertainment / Social",
"religious": "Religious",
"other": "Other"
},
"es": {
"walk": "Caminando",
"e-bike": "e-bicicleta",
"bike": "Bicicleta",
"bikeshare": "Bicicleta compartida",
"scootershare": "Motoneta compartida",
"drove_alone": "Coche de Gas, Condujo solo",
"shared_ride": "Coche de Gas, Condujo con otros",
"e_car_drove_alone": "e-coche, Condujo solo",
"e_car_shared_ride": "e-coche, Condujo con ontras",
"moped": "Ciclomotor",
"taxi": "Taxi / Uber / Lyft",
"bus": "Autobús",
"train": "Tren",
"free_shuttle": "Colectivo gratuito",
"air": "Avión",
"not_a_trip": "No es un viaje",
"no_travel": "No viajar",
"home": "Inicio",
"work": "Trabajo",
"at_work": "En el trabajo",
"school": "Escuela",
"transit_transfer": "Transbordo",
"shopping": "Compras",
"meal": "Comida",
"pick_drop_person": "Recoger / Entregar Individuo",
"pick_drop_item": "Recoger / Entregar Objeto",
"personal_med": "Personal / Médico",
"access_recreation": "Acceder a Recreación",
"exercise": "Recreación / Ejercicio",
"entertainment": "Entretenimiento / Social",
"religious": "Religioso",
"other": "Otros"
}
}
}
52 changes: 0 additions & 52 deletions www/json/trip_confirm_options.json.sample

This file was deleted.