From a1d9847976cbaf8a25225f0b284281fa8fc0c161 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Thu, 29 Oct 2026 14:47:58 +0400 Subject: [PATCH] i18n(ja): address code review findings Japanese has no letter case, so the HUD summary keeps units as the catalog writes them (13 km), matching the cockpit and the ja HUD CSS. The ja '{value} KM', '{value} KM/H' and '{value} KM/S' strings are now lower-case like zh-CN. Co-Authored-By: Claude Opus 5.5 --- src/hudLocalityFormat.js | 7 +++++-- src/i18n/ja-hud-units.test.mjs | 22 ++++++++++++++++++++++ src/i18n/locales/ja.json | 6 +++--- src/i18n/same-as-english.json | 3 --- src/i18n/zh-CN-display.test.mjs | 3 +++ 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 src/i18n/ja-hud-units.test.mjs diff --git a/src/hudLocalityFormat.js b/src/hudLocalityFormat.js index 697075a82..b9b8c3ea0 100644 --- a/src/hudLocalityFormat.js +++ b/src/hudLocalityFormat.js @@ -8,7 +8,10 @@ import { formatNumber, getLocale, t } from './i18n/index.js'; import { unitLabel } from './ui/unitLabels.js'; import { localizePlaceName } from './ui/placeNames.js'; -/** An upper-case HUD quantity such as `13KM` / `13КМ`, in the active language. */ +/** + * An upper-case HUD quantity such as `13KM` / `13КМ`, in the active language. + * Chinese and Japanese have no case and keep the catalog's `13 km`. + */ export function hudQuantity(value, unit, digits = 0) { const number = formatNumber(value, { useGrouping: false, @@ -16,7 +19,7 @@ export function hudQuantity(value, unit, digits = 0) { maximumFractionDigits: digits, }); const label = unitLabel(unit); - if (getLocale().startsWith('zh-')) + if (/^(zh|ja)(-|$)/.test(getLocale())) return label ? `${number} ${label}` : number; return `${number}${label.toUpperCase()}`; } diff --git a/src/i18n/ja-hud-units.test.mjs b/src/i18n/ja-hud-units.test.mjs new file mode 100644 index 000000000..73568d0ce --- /dev/null +++ b/src/i18n/ja-hud-units.test.mjs @@ -0,0 +1,22 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { setLocale } from './index.js'; +import { hudQuantity, LOCALIZED_LOCALITY } from '../hudLocalityFormat.js'; +import { formatCockpitDistance } from '../ui/cockpitPresentation.js'; + +// revmain-opus-ja-i1-1: ja has no case, so HUD units keep the catalog case +// (km), as the cockpit already does and docs/translations/ja.md requires. +test('Japanese HUD units keep their case, like the cockpit', () => { + try { + setLocale('ja'); + assert.equal(formatCockpitDistance(14000), '14 km'); + assert.equal(hudQuantity(13, 'km'), '13 km'); + assert.equal(hudQuantity(1.5, 'km', 1), '1.5 km'); + assert.equal( + LOCALIZED_LOCALITY.near({ poi: 'Shibuya', city: 'Tokyo', distKm: 13 }), + 'SHIBUYA(東京)付近 13 km', + ); + } finally { + setLocale('en'); + } +}); diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index 02e49d22a..b7c045555 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -803,8 +803,8 @@ "DATE UNAVAILABLE": "日付不明", "UNSPECIFIED OPERATOR": "運用者未指定", "Select {mission}": "{mission}を選択", - "{value} KM": "{value} KM", - "{value} KM/S": "{value} KM/S", + "{value} KM": "{value} km", + "{value} KM/S": "{value} km/s", "Selected Space Mission": "選択中の宇宙ミッション", "SELECTED SPACE MISSION": "選択中の宇宙ミッション", "Show all missions": "すべてのミッションを表示", @@ -1607,7 +1607,7 @@ "REGION UNAVAILABLE": "地域を取得できません", "NO RECENT LOCATION MATCHES": "この地域の最近のニュースなし", "{domain} · {age}": "{domain} · {age}", - "{value} KM/H": "{value} KM/H", + "{value} KM/H": "{value} km/h", "CLOUD {pct}%": "雲量 {pct}%", "CLOUD UNKNOWN": "雲量不明", "{source} · LOCATION QUERY": "{source} · 位置クエリ", diff --git a/src/i18n/same-as-english.json b/src/i18n/same-as-english.json index 9ee97a600..73443c29e 100644 --- a/src/i18n/same-as-english.json +++ b/src/i18n/same-as-english.json @@ -169,9 +169,6 @@ "{source} HTTP {status}", "{speed} kn", "{type} SPD: {speed} HDG: {heading}", - "{value} KM", - "{value} KM/H", - "{value} KM/S", "ΔE", "ΔN", "▲ {frp} MW" diff --git a/src/i18n/zh-CN-display.test.mjs b/src/i18n/zh-CN-display.test.mjs index b9e55058d..db85662c4 100644 --- a/src/i18n/zh-CN-display.test.mjs +++ b/src/i18n/zh-CN-display.test.mjs @@ -17,6 +17,9 @@ test('Chinese HUD and cockpit units keep their case without spacing coordinates' assert.equal(formatCockpitDistance(14000), '14\u00a0km'); assert.equal(LOCALIZED_LOCALITY.sector({ latDeg: 21.33, lonDeg: -77.5 }), '扇区 21.33N 77.50W'); + setLocale('ja'); + assert.equal(hudQuantity(13, 'km'), '13 km'); + assert.equal(hudQuantity(1.5, 'km', 1), '1.5 km'); setLocale('en'); assert.equal(hudQuantity(0, 'km'), '0KM'); assert.equal(hudQuantity(2069, 'km', 1), '2069.0KM');