Compare commits

...
Author SHA1 Message Date
Claude bbeae37e39 fix: transliterate diacritical characters in place and airport names
Special characters (Š, Č, Ž, Đ, etc.) were rendering as garbled glyphs
in the UI because the display environment lacks font coverage for those
code points. Adds a shared transliterate() utility that decomposes
characters via NFD and strips combining diacritical marks, with a
supplemental map for characters that don't decompose cleanly (Đ, Ø, Ł,
ß, etc.). Applied at both Places API routes (search + details) and the
GeoJSON entity converter so all place/airport name sources are covered.

Fixes: [email protected] report – May 13-14 2026 Discord.
2026-05-26 05:39:17 +00:00
5 changed files with 37 additions and 6 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "worldwideview",
"version": "2.18.6",
"version": "2.18.7",
"private": true,
"type": "module",
"packageManager": "[email protected]",
+2 -1
View File
@@ -1,4 +1,5 @@
import { NextResponse } from "next/server";
import { transliterate } from "@/lib/utils/transliterate";
// Server-side cache: keyed by place_id, 24-hour TTL (place geometry is stable)
const cache = new Map<string, { data: unknown; expiresAt: number }>();
@@ -50,7 +51,7 @@ export async function GET(request: Request) {
const result = {
lat: location.lat,
lon: location.lng,
name: data.result.name,
name: transliterate(data.result.name ?? ""),
types: data.result.types || [],
viewport: data.result.geometry?.viewport || null,
};
+4 -3
View File
@@ -1,4 +1,5 @@
import { NextResponse } from "next/server";
import { transliterate } from "@/lib/utils/transliterate";
// Server-side cache: keyed by normalised input, 1-hour TTL
const cache = new Map<string, { data: unknown; expiresAt: number }>();
@@ -44,10 +45,10 @@ export async function GET(request: Request) {
}
const predictions = data.predictions.map((p: any) => ({
description: p.description,
description: transliterate(p.description ?? ""),
placeId: p.place_id,
mainText: p.structured_formatting?.main_text || p.description,
secondaryText: p.structured_formatting?.secondary_text || "",
mainText: transliterate(p.structured_formatting?.main_text || p.description),
secondaryText: transliterate(p.structured_formatting?.secondary_text || ""),
types: p.types,
}));
+28
View File
@@ -0,0 +1,28 @@
// Characters that don't decompose to a base ASCII letter via NFD normalization.
const SUPPLEMENTAL_MAP: Record<string, string> = {
"Đ": "D", "đ": "d", // Đ đ
"Ø": "O", "ø": "o", // Ø ø
"Ł": "L", "ł": "l", // Ł ł
"Ð": "D", "ð": "d", // Ð ð
"Þ": "Th", "þ": "th", // Þ þ
"ß": "ss", // ß
"Æ": "AE", "æ": "ae", // Æ æ
"Œ": "OE", "œ": "oe", // Œ œ
};
/**
* Replaces diacritical characters with their closest ASCII equivalents so that
* place and airport names remain readable even in environments where the font
* or encoding does not support the original glyphs (e.g. Š→S, Č→C, Ž→Z).
*/
export function transliterate(text: string): string {
return (
text
// Decompose characters like Š into base letter + combining mark (e.g. S + caron)
.normalize("NFD")
// Strip all Unicode combining diacritical marks (U+0300–U+036F)
.replace(/[̀-ͯ]/g, "")
// Replace any remaining non-ASCII characters using the supplemental map
.replace(/[^\x00-\x7F]/g, (ch) => SUPPLEMENTAL_MAP[ch] ?? ch)
);
}
+2 -1
View File
@@ -6,6 +6,7 @@
import type { GeoEntity } from "@/core/plugins/PluginTypes";
import type { GeoJsonFeature, GeoJsonGeometry } from "@/types/geojson";
import { transliterate } from "@/lib/utils/transliterate";
/** Extract a representative [lat, lon, alt?] from any geometry. */
function representativePoint(
@@ -50,7 +51,7 @@ export function featuresToEntities(
longitude: point.lon,
altitude: point.alt,
timestamp: new Date(),
label: (feature.properties.name as string) ?? undefined,
label: feature.properties.name ? transliterate(feature.properties.name as string) : undefined,
properties: {
...feature.properties,
_layerId: layerId,