service.py

changeset 72
65408ed066b3
parent 71
d2e19670b772
child 73
c56b0ef96514
--- a/service.py	Thu Oct 26 16:54:29 2017 +0300
+++ b/service.py	Thu Oct 26 18:02:27 2017 +0300
@@ -42,9 +42,12 @@
 			try:
 				return self.languages[language][section][name]
 			except KeyError:
-				pass
+				try:
+					return profile['tr:' + language + ':' + section][name]
+				except KeyError:
+					pass
 		else:
-			return name[0:1].upper() + name[1:]
+			return name[:1].upper() + name[1:]
 
 tr = Translator()
 for file in listdir('tr'):
@@ -66,7 +69,7 @@
 	trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance
 	sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = long)
 	if sign:
-		sign_representation = ' - '.join(tr(place, 'paikat') for place in sign if place not in suffix_regions)
+		sign_representation = ' - '.join(tr(place, 'places') for place in sign if place not in suffix_regions)
 		sign_representation += ''.join(' ' + tr(place, 'suffix-places') for place in sign if place in suffix_regions)
 		return sign_representation
 	else:
@@ -78,8 +81,8 @@
 	sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = True)
 	if sign:
 		return {
-			'destination': tr(sign[-1], 'paikat'),
-			'via': [tr(place, 'paikat') for place in sign[:-1]],
+			'destination': tr(sign[-1], 'places'),
+			'via': [tr(place, 'places') for place in sign[:-1]],
 		}
 	else:
 		return {
@@ -149,9 +152,9 @@
 	return render_template(
 		'stop.html',
 		schedule = schedule,
-		name = bus_stop.code + ' ' + tr(bus_stop.name, 'bus-stops'),
+		name = bus_stop.code + ' ' + tr(bus_stop.name, 'bus-stops', 'places'),
 		link_to_map = bus_stop.location.link_to_map,
-		region = bus_stop.region,
+		region = hasattr(bus_stop, 'region') and bus_stop.region or None,
 		location = bus_stop.location,
 		cluster = bus_stop.cluster.url_name if len(bus_stop.cluster.stops) > 1 else None,
 		tr = tr,
@@ -315,7 +318,7 @@
 			'night': is_night_time(schedule_entry['time']),
 			'stop_id': schedule_entry['stop'].stop.reference,
 			'stop_code': schedule_entry['stop'].stop.code, 
-			'stop_name': tr(schedule_entry['stop'].stop.name, 'bus-stops'),
+			'stop_name': tr(schedule_entry['stop'].stop.name, 'bus-stops', 'places'),
 			'imminent': imminent(schedule_entry),
 		})
 	stops_in_cluster = sorted(
@@ -329,7 +332,7 @@
 	return render_template(
 		'cluster.html',
 		schedule = schedule,
-		name = tr(cluster.name, 'paikat', 'pysäkkiryhmät', 'bus-stops'),
+		name = tr(cluster.name, 'places', 'place-clusters', 'bus-stops'),
 		link_to_map = cluster.center.link_to_map,
 		location = cluster.center,
 		stops_in_cluster = stops_in_cluster,
@@ -354,10 +357,10 @@
 		if profile['regions']['use-regions']:
 			if halt.stop.region != region and not (region and not halt.stop.region):
 				if len(schedule) and not schedule[-1]['name']:
-					schedule[-1]['name'] = tr(halt.stop.region or '', 'paikat')
+					schedule[-1]['name'] = tr(halt.stop.region or '', 'places')
 				else:
 					schedule.append({
-						'name': tr(halt.stop.region or '', 'paikat'),
+						'name': tr(halt.stop.region or '', 'places'),
 						'time': formatted_time,
 						'stops': [],
 						'index': len(schedule),
@@ -365,7 +368,7 @@
 				region = halt.stop.region
 		else:
 			schedule.append({
-				'name': tr(halt.stop.name or '', 'bus-stops'),
+				'name': tr(halt.stop.name or '', 'bus-stops', 'places'),
 				'time': formatted_time,
 				'stops': [],
 				'index': len(schedule),
@@ -374,7 +377,7 @@
 			'time': formatted_time,
 			'id': halt.stop.reference,
 			'code': halt.stop.code,
-			'name': tr(halt.stop.name, 'bus-stops'),
+			'name': tr(halt.stop.name, 'bus-stops', 'places'),
 		})
 	sign = trip.concise_schedule()
 	try:
@@ -385,7 +388,7 @@
 		schedule = schedule,
 		trip_reference = trip_reference,
 		route = trip.route.reference,
-		description = ' - '.join(tr(place, 'paikat') for place in sign),
+		description = ' - '.join(tr(place, 'places') for place in sign),
 		night = is_night_time(datetime.combine(today(), time()) + trip.schedule[-1].arrival_time),
 		tr = tr,
 		length = trip.length / 1000,

mercurial