Add EN/Chinese language toggle for extract and transit names
Chinese strings live in web/data/extract-translations.zh-CN.json, keyed by stable marker ID; the bottom-right control switches live-rendered markers and tooltips and persists the choice in localStorage. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
f7cd4fde04
commit
cf8f822e74
4 files changed
+247
-5
No files matched your search
@@ -230,6 +230,12 @@ The **Markers** slider (top right; bottom left on phones) scales marker icons
|
||||
and labels from 0.5× to 2× — it is one CSS transform per marker, persisted in
|
||||
`localStorage`; click the value to reset to 1×.
|
||||
|
||||
The bottom-right **EN / 中文** control switches every published extract and
|
||||
transit name between English and Simplified Chinese. Chinese strings live in
|
||||
`web/data/extract-translations.zh-CN.json`, keyed by stable marker ID, and the
|
||||
selected language persists in the browser. Other marker categories and editor
|
||||
UI remain English until their localization data is added.
|
||||
|
||||
Visible labels are laid out against the current viewport, nearby marker icons
|
||||
and the open control panel. Crowded labels move to the nearest free position;
|
||||
when that position is no longer adjacent, a leader line connects the label to
|
||||
|
||||
+59
-5
@@ -140,7 +140,7 @@ function readHash() {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const [world, markerConfig, capabilities] = await Promise.all([
|
||||
const [world, markerConfig, capabilities, extractTranslationData] = await Promise.all([
|
||||
fetch('data/world.json', { cache: 'no-cache' }).then((r) => {
|
||||
if (!r.ok) throw new Error(`world.json: ${r.status}`);
|
||||
return r.json();
|
||||
@@ -151,12 +151,30 @@ async function main() {
|
||||
fetch('data/capabilities.json', { cache: 'no-store' })
|
||||
.then((r) => (r.ok ? r.json() : { editable: false }))
|
||||
.catch(() => ({ editable: false })),
|
||||
fetch('data/extract-translations.zh-CN.json', { cache: 'no-cache' })
|
||||
.then((r) => (r.ok ? r.json() : { markers: {} }))
|
||||
.catch(() => ({ markers: {} })),
|
||||
]);
|
||||
if (!world.maps.length) throw new Error('world.json contains no maps');
|
||||
const mapEditingEnabled = capabilities.mapEditing === true;
|
||||
const markerEditingEnabled = capabilities.markerEditing === true;
|
||||
const markerPersistence = capabilities.markerPersistence === 'server' ? 'server' : 'local';
|
||||
const exportingEnabled = capabilities.exporting === true;
|
||||
const extractTranslations = extractTranslationData?.markers ?? {};
|
||||
let language = localStorage.getItem('tarkov-language') === 'zh-CN' ? 'zh-CN' : 'en';
|
||||
let languageButton = null;
|
||||
let refreshLocalizedMarkers = () => {};
|
||||
const renderLanguageControl = () => {
|
||||
document.documentElement.lang = language === 'zh-CN' ? 'zh-CN' : 'en';
|
||||
if (!languageButton) return;
|
||||
languageButton.dataset.language = language;
|
||||
languageButton.innerHTML = language === 'zh-CN'
|
||||
? '<span>EN</span><span aria-hidden="true">/</span><strong>中文</strong>'
|
||||
: '<strong>EN</strong><span aria-hidden="true">/</span><span>中文</span>';
|
||||
languageButton.setAttribute(
|
||||
'aria-label', language === 'zh-CN' ? 'Switch extract names to English' : '切换撤离点名称为中文',
|
||||
);
|
||||
};
|
||||
|
||||
const ZMAX = world.maxZoom;
|
||||
const base = world.maps.find((m) => m.base) ?? world.maps[0];
|
||||
@@ -197,6 +215,25 @@ async function main() {
|
||||
anchor.addEventListener('dragstart', (event) => event.preventDefault());
|
||||
}
|
||||
|
||||
const LanguageControl = L.Control.extend({
|
||||
options: { position: 'bottomright' },
|
||||
onAdd() {
|
||||
const container = L.DomUtil.create('div', 'leaflet-bar leaflet-control-language');
|
||||
languageButton = L.DomUtil.create('button', '', container);
|
||||
languageButton.type = 'button';
|
||||
L.DomEvent.disableClickPropagation(container);
|
||||
L.DomEvent.on(languageButton, 'click', () => {
|
||||
language = language === 'zh-CN' ? 'en' : 'zh-CN';
|
||||
localStorage.setItem('tarkov-language', language);
|
||||
renderLanguageControl();
|
||||
refreshLocalizedMarkers();
|
||||
});
|
||||
renderLanguageControl();
|
||||
return container;
|
||||
},
|
||||
});
|
||||
new LanguageControl().addTo(map);
|
||||
|
||||
const boost = DENSITY_BOOST;
|
||||
|
||||
/* Stacking. Placements are approximate, so map rectangles overlap even when
|
||||
@@ -470,6 +507,11 @@ async function main() {
|
||||
const extractCategories = new Set([
|
||||
'extract-pmc', 'extract-scav', 'extract-neutral', 'extract-hidden', 'transit',
|
||||
]);
|
||||
const localizedMarkerLabel = (record, settings = categoryConfig(record.category)) => (
|
||||
language === 'zh-CN' && extractCategories.has(record.category)
|
||||
? extractTranslations[record.id] || record.label || settings.label
|
||||
: record.label || settings.label || record.category.replaceAll('-', ' ')
|
||||
);
|
||||
const markerVisibilityVersion = Number(markerConfig.visibilityVersion) || 1;
|
||||
const categoryStorageKey = (category) => (
|
||||
`tarkov-marker-v${markerVisibilityVersion}-category-${category}`
|
||||
@@ -651,7 +693,7 @@ async function main() {
|
||||
const size = safeSize(settings.size);
|
||||
const color = safeColor(settings.color);
|
||||
const textColor = safeColor(settings.textColor || '#f5f7f8');
|
||||
const label = record.label || settings.label || record.category.replaceAll('-', ' ');
|
||||
const label = localizedMarkerLabel(record, settings);
|
||||
const text = settings.displayText
|
||||
? `<span class="poi-label">${escapeHTML(label)}</span>` : '';
|
||||
return L.divIcon({
|
||||
@@ -663,18 +705,21 @@ async function main() {
|
||||
+ `<span class="poi-dot">${escapeHTML(settings.symbol ?? '•')}</span>${text}</span>`,
|
||||
});
|
||||
};
|
||||
const markerTooltipHTML = (record) => {
|
||||
const settings = categoryConfig(record.category);
|
||||
return `<strong>${escapeHTML(localizedMarkerLabel(record, settings))}</strong>`
|
||||
+ `<span>${escapeHTML(settings.label ?? record.category)} · ${escapeHTML(record.mapName)}</span>`;
|
||||
};
|
||||
const createMarker = (record) => {
|
||||
const settings = categoryConfig(record.category);
|
||||
const size = safeSize(settings.size);
|
||||
const label = record.label || settings.label || record.category.replaceAll('-', ' ');
|
||||
const leafletMarker = L.marker([record.worldY, record.worldX], {
|
||||
icon: createMarkerIcon(record), pane: 'semantic-markers', interactive: true,
|
||||
keyboard: false, draggable: markerEditingEnabled,
|
||||
zIndexOffset: extractCategories.has(record.category) ? 5000 : 0,
|
||||
});
|
||||
leafletMarker.bindTooltip(
|
||||
`<strong>${escapeHTML(label)}</strong>`
|
||||
+ `<span>${escapeHTML(settings.label ?? record.category)} · ${escapeHTML(record.mapName)}</span>`,
|
||||
markerTooltipHTML(record),
|
||||
{ direction: 'top', offset: [0, -(size * markerScale) / 2], className: 'poi-tooltip' },
|
||||
);
|
||||
leafletMarker.on('click', (event) => {
|
||||
@@ -699,6 +744,15 @@ async function main() {
|
||||
let focusedMarkerIds = [];
|
||||
let markerRefreshFrame = null;
|
||||
const renderedMarkers = new Map();
|
||||
refreshLocalizedMarkers = () => {
|
||||
for (const [id, leafletMarker] of renderedMarkers) {
|
||||
const record = markerRecords.get(id);
|
||||
if (!record) continue;
|
||||
leafletMarker.setIcon(createMarkerIcon(record));
|
||||
leafletMarker.setTooltipContent(markerTooltipHTML(record));
|
||||
}
|
||||
scheduleMarkerLabelLayout();
|
||||
};
|
||||
let markerLabelLayoutFrame = null;
|
||||
|
||||
// Marker/label size multiplier (the slider, top right). Applied as a CSS
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
{
|
||||
"language": "zh-CN",
|
||||
"source": "Tarkov Extracts.md",
|
||||
"markers": {
|
||||
"customs-cb6d3a8c0e20": "走私者的船",
|
||||
"customs-a79111915293": "走私者的地堡(ZB-1012)",
|
||||
"customs-24bcffb797af": "地下室锅炉房(合作撤离)",
|
||||
"customs-e58572932cd1": "十字路口",
|
||||
"customs-5e818d53cf72": "RUAF路障",
|
||||
"customs-974c30721c45": "宿舍载具撤离点",
|
||||
"customs-45645fbc9a13": "铁路通道(信号弹)",
|
||||
"customs-f1d7ba416c1b": "ZB-013",
|
||||
"customs-6b4027570254": "行政区大门",
|
||||
"customs-daf50bee7b38": "工厂远角",
|
||||
"customs-c1bb6a3d059d": "工厂棚屋",
|
||||
"customs-f11ad4b62061": "军事基地检查站",
|
||||
"customs-1fc844d6bf70": "老路大门",
|
||||
"customs-72601281e471": "石间小道",
|
||||
"customs-89a4ec29801d": "通往军事基地的铁路",
|
||||
"customs-1759720e23e5": "通往港口的铁路",
|
||||
"customs-ca0ece4b64a2": "通往塔科夫的铁路",
|
||||
"customs-170876e48cfd": "Scav检查站",
|
||||
"customs-39b950d47e30": "狙击手路障",
|
||||
"customs-c53ab9f6870b": "拖车停车场工人棚屋",
|
||||
"customs-30abdbf9fcc0": "17号仓库",
|
||||
"customs-1e7f22e59724": "4号仓库",
|
||||
"customs-d9217df987d4": "前往工厂",
|
||||
"customs-de8d60eb3e38": "前往立交桥",
|
||||
"customs-9f7c39f76080": "前往储备站",
|
||||
"customs-bcc687bd5d10": "前往海岸线",
|
||||
|
||||
"factory-76a0d09fdeb9": "走私者小道",
|
||||
"factory-44d6b9feb851": "地下室",
|
||||
"factory-0da9b29af46c": "庭院大门",
|
||||
"factory-ea2d17496842": "0号门",
|
||||
"factory-c0ab06ab14fa": "3号门",
|
||||
"factory-bc21dda44298": "医疗帐篷大门",
|
||||
"factory-5ae9bee65c8a": "监控地堡大门",
|
||||
"factory-b53e2ab073f5": "办公室窗户",
|
||||
"factory-fb6b76cde606": "前往海关",
|
||||
"factory-7065703fa1b6": "前往实验室",
|
||||
"factory-2830071855ae": "前往森林",
|
||||
|
||||
"ground-zero-d09a5c127856": "Scav检查站(合作撤离)",
|
||||
"ground-zero-51367f29c31a": "Emercom检查站",
|
||||
"ground-zero-f2a5ba104f9f": "Mira大道",
|
||||
"ground-zero-0465c74f6394": "Nakatani地下室楼梯",
|
||||
"ground-zero-514f769e0370": "警方封锁线(载具撤离点)",
|
||||
|
||||
"interchange-ec64cc0b63df": "走私者隧道",
|
||||
"interchange-d33516fd4e01": "Emercom检查点",
|
||||
"interchange-6fcf872c03b4": "铁路撤离点",
|
||||
"interchange-722b6ea7192c": "Scav营地(合作撤离点)",
|
||||
"interchange-b2a866b0966a": "围栏缺口",
|
||||
"interchange-0a6b957c51e8": "河畔之路(信号弹)",
|
||||
"interchange-0f3fea51d3e0": "发电站载具撤离点",
|
||||
"interchange-57bda78bab29": "安全屋撤离点",
|
||||
"interchange-e1414a8d9ff8": "前往海关",
|
||||
"interchange-08846ebf8dd3": "前往塔科夫街区",
|
||||
|
||||
"labyrinth-9e598d81edb9": "阿里阿德涅之线",
|
||||
"labyrinth-34bac18ea070": "向上通路",
|
||||
|
||||
"lighthouse-5c45ba80961f": "湖边小径",
|
||||
"lighthouse-3e26943bc70f": "装甲列车",
|
||||
"lighthouse-c01649a1b232": "通往海岸线的路",
|
||||
"lighthouse-1dbc2b60eb8a": "隧道(合作撤离点)",
|
||||
"lighthouse-21b971e3df9a": "山间小路",
|
||||
"lighthouse-2beab5ec57a9": "北部检查点",
|
||||
"lighthouse-8a66e9466467": "通往军事基地的载具撤离点",
|
||||
"lighthouse-0b05f091922e": "南部大路",
|
||||
"lighthouse-5e50efd6c093": "浮动码头下方的藏身处",
|
||||
"lighthouse-f5b5e1c54e40": "厂区大门",
|
||||
"lighthouse-4d943d2cc9c8": "洞穴Scav藏身处",
|
||||
"lighthouse-dc42df91c82e": "南部大路塌方处",
|
||||
"lighthouse-482123395a57": "前往储备站",
|
||||
"lighthouse-7c85b5739ab8": "前往海岸线",
|
||||
"lighthouse-5e60d5ddfb70": "前往森林",
|
||||
|
||||
"reserve-e58d239cf4b2": "前往森林的路",
|
||||
"reserve-773006408d0c": "装甲列车",
|
||||
"reserve-a66c1d393995": "地堡密闭门",
|
||||
"reserve-954e2a583a7f": "Scav之地(合作撤离点)",
|
||||
"reserve-8e0c9d8b065b": "峭壁斜坡",
|
||||
"reserve-9382c4d894c8": "下水道检修孔",
|
||||
"reserve-cd5925657f72": "检查点围墙",
|
||||
"reserve-5c1fd13270a2": "仓库密闭门",
|
||||
"reserve-79cd5266a8b8": "仓库密闭门(地下)",
|
||||
"reserve-402e826c5832": "加热管道",
|
||||
"reserve-c9352592a1fa": "山边缺口围墙",
|
||||
"reserve-1a462000b86e": "前往海关",
|
||||
"reserve-0ebad53ef82e": "前往灯塔",
|
||||
"reserve-b3f1d35145a4": "前往森林",
|
||||
|
||||
"shoreline-c3089518d1dd": "山间堡垒",
|
||||
"shoreline-a3c17245eee4": "通往海关的路",
|
||||
"shoreline-6f76e135336b": "走私者的通道(合作撤离点)",
|
||||
"shoreline-f44f46b61235": "攀岩者之路",
|
||||
"shoreline-ff01eff0579a": "通往灯塔的路",
|
||||
"shoreline-d03681eee2d9": "码头的船",
|
||||
"shoreline-30941f5a317b": "铁路桥",
|
||||
"shoreline-847ce228271a": "通往北方的路(载具撤离点)",
|
||||
"shoreline-5bb69133a035": "隧道",
|
||||
"shoreline-60f461c30e67": "行政楼地下室",
|
||||
"shoreline-bf3be957952a": "健身房东楼入口",
|
||||
"shoreline-c21430099b1f": "灯塔",
|
||||
"shoreline-d5ce69e49c13": "被毁的道路",
|
||||
"shoreline-9f5bc9b3fde6": "前往灯塔",
|
||||
"shoreline-1df8b14f6ca1": "前往终点站",
|
||||
|
||||
"streets-107e8f3c7917": "走私者地下室入口",
|
||||
"streets-8f6b3189d1eb": "Cardinal公寓停车场",
|
||||
"streets-c2a8871a4f71": "倒塌的吊车",
|
||||
"streets-67120af18af3": "院子",
|
||||
"streets-aa33091b7d37": "坠机现场",
|
||||
"streets-2de21914bb02": "受损的房屋",
|
||||
"streets-de0be16f5b15": "展览馆检查站",
|
||||
"streets-fbcc04d3e1dd": "Klimov交易中心",
|
||||
"streets-384542b2949e": "Klimov大街(信号弹)",
|
||||
"streets-a6db78df746a": "Kamchatskaya大街拱门",
|
||||
"streets-78b776f04a9b": "Pinewood地下室(合作撤离点)",
|
||||
"streets-bb7134e27d24": "Primorsky大道出租车载具撤离点",
|
||||
"streets-fe80ca29e4a1": "污水河",
|
||||
"streets-ec26e778195c": "升降梯",
|
||||
"streets-635f594ced85": "墓穴入口",
|
||||
"streets-ee7c84277162": "下水道",
|
||||
"streets-28b6c33cf24f": "通风管道",
|
||||
"streets-9bc3498cbe79": "前往中心区",
|
||||
"streets-4b5c76743a86": "前往立交桥",
|
||||
"streets-0cfaa09371be": "前往实验室",
|
||||
|
||||
"woods-bb081bd8b443": "山下地堡",
|
||||
"woods-ec9dc392416c": "友谊之桥(合作撤离)",
|
||||
"woods-0920f7bd8c7d": "郊区",
|
||||
"woods-91db5851c7bb": "输电通道(信号弹)",
|
||||
"woods-2f5e97c569cb": "RUAF大门/RUAF路障",
|
||||
"woods-3e9ae639717e": "UN路障",
|
||||
"woods-a108ebc563ba": "ZB-014",
|
||||
"woods-114f4539667f": "大桥载具撤离点",
|
||||
"woods-5283b06ce8b6": "北部UN路障",
|
||||
"woods-ee7736b8b4cd": "ZB-016",
|
||||
"woods-bf27f1c148d1": "亡者之所",
|
||||
"woods-ccaba6861c87": "东部岩石",
|
||||
"woods-454e7c107de0": "山间仓库",
|
||||
"woods-65659120fbbf": "旧火车站",
|
||||
"woods-28fc587c7374": "Scav地堡",
|
||||
"woods-03d165032f34": "Scav小屋",
|
||||
"woods-333e300a1d08": "那艘船",
|
||||
"woods-d321453e9a15": "前往海关",
|
||||
"woods-b30c9e01a334": "前往工厂",
|
||||
"woods-ee6313364863": "前往灯塔",
|
||||
"woods-5d991cb51cdd": "前往储备站"
|
||||
}
|
||||
}
|
||||
@@ -610,6 +610,34 @@ html, body {
|
||||
border-radius: 8px;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.leaflet-bottom.leaflet-right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
.leaflet-bottom.leaflet-right .leaflet-control { float: none; }
|
||||
|
||||
.leaflet-control-language { order: 1; }
|
||||
.leaflet-control-zoom { order: 2; }
|
||||
.leaflet-control-attribution { order: 3; }
|
||||
|
||||
.leaflet-control-language button {
|
||||
min-width: 88px;
|
||||
height: 32px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: var(--panel);
|
||||
color: var(--muted);
|
||||
font: 12px/30px system-ui, "Microsoft YaHei UI", sans-serif;
|
||||
cursor: pointer;
|
||||
}
|
||||
.leaflet-control-language button:hover { background: #2a303a; color: var(--text); }
|
||||
.leaflet-control-language button strong { color: var(--accent); font-weight: 750; }
|
||||
.leaflet-control-language button span + span,
|
||||
.leaflet-control-language button span + strong,
|
||||
.leaflet-control-language button strong + span { margin-left: 5px; }
|
||||
.leaflet-control-zoom a,
|
||||
.leaflet-touch .leaflet-control-zoom a {
|
||||
width: 42px;
|
||||
|
||||
Reference in new issue
Block a user