Search in sources :

Example 1 with LocalizedString

use of org.opentripplanner.util.LocalizedString in project OpenTripPlanner by opentripplanner.

the class StreetVertex method getIntersectionName.

/**
 * Creates intersection name out of all outgoing names
 *
 * This can be:
 *  - name of the street if it is only 1
 *  - unnamedStreed (localized in requested language) if it doesn't have a name
 *  - corner of 0 and 1 (localized corner of zero and first street in the corner)
 *
 * @param locale Wanted locale
 * @return already localized street names and non-localized corner of x and unnamedStreet
 */
public I18NString getIntersectionName(Locale locale) {
    I18NString calculatedName = null;
    // generate names for corners when no name was given
    Set<String> uniqueNameSet = new HashSet<String>();
    for (Edge e : getOutgoing()) {
        if (e instanceof StreetEdge) {
            uniqueNameSet.add(e.getName(locale));
        }
    }
    List<String> uniqueNames = new ArrayList<String>(uniqueNameSet);
    if (uniqueNames.size() > 1) {
        calculatedName = new LocalizedString("corner", new String[] { uniqueNames.get(0), uniqueNames.get(1) });
    } else if (uniqueNames.size() == 1) {
        calculatedName = new NonLocalizedString(uniqueNames.get(0));
    } else {
        calculatedName = new LocalizedString("unnamedStreet", (String[]) null);
    }
    return calculatedName;
}
Also used : I18NString(org.opentripplanner.util.I18NString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) I18NString(org.opentripplanner.util.I18NString) LocalizedString(org.opentripplanner.util.LocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) LocalizedString(org.opentripplanner.util.LocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 2 with LocalizedString

use of org.opentripplanner.util.LocalizedString in project OpenTripPlanner by opentripplanner.

the class NoteProperties method generateNote.

public T2<Alert, NoteMatcher> generateNote(OSMWithTags way) {
    Alert note = new Alert();
    // TODO: this could probably be made without patternMatch for {} since all notes (at least currently) have {note} as notePattern
    if (patternMatcher.matcher(notePattern).matches()) {
        // This gets language -> translation of notePattern and all tags (which can have translations name:en for example)
        Map<String, String> noteText = TemplateLibrary.generateI18N(notePattern, way);
        note.alertHeaderText = TranslatedString.getI18NString(noteText);
    } else {
        note.alertHeaderText = new LocalizedString(notePattern, way);
    }
    return new T2<>(note, noteMatcher);
}
Also used : Alert(org.opentripplanner.routing.alertpatch.Alert) TranslatedString(org.opentripplanner.util.TranslatedString) LocalizedString(org.opentripplanner.util.LocalizedString) LocalizedString(org.opentripplanner.util.LocalizedString) T2(org.opentripplanner.common.model.T2)

Example 3 with LocalizedString

use of org.opentripplanner.util.LocalizedString in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testLocalizedString.

@Test
public void testLocalizedString() {
    LocalizedString localizedString = new LocalizedString("corner", new String[] { "first", "second" });
    assertEquals("corner of first and second", localizedString.toString());
    assertEquals("Kreuzung first mit second", localizedString.toString(new Locale("de")));
}
Also used : LocalizedString(org.opentripplanner.util.LocalizedString) Test(org.junit.Test)

Aggregations

LocalizedString (org.opentripplanner.util.LocalizedString)3 Test (org.junit.Test)1 T2 (org.opentripplanner.common.model.T2)1 Alert (org.opentripplanner.routing.alertpatch.Alert)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 I18NString (org.opentripplanner.util.I18NString)1 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)1 TranslatedString (org.opentripplanner.util.TranslatedString)1