mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
fix(i18n): Google controls, vessel units and counts follow the UI language
Screens that only open with provider keys showed a few gaps: - Google Street View's own controls (Map Data, Terms, Report a problem) and its addresses were always English: the Maps script now loads with the UI language. English adds no parameter, as before. - The selected-vessel HUD line kept KT and DEG after translated labels. - Layer counts used a decimal point (12.0K); other languages use their own separator (12,0K). - A collapsed rail title was cut with an ellipsis in Russian; tighter tracking fits it whole. English is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7db0abc396
commit
03207ca0fc
8 files changed
+47
-11
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { FOLLOW_MAP_STACK_ID } from '../../policy.js';
|
||||
import { createMapsLoader } from './mapsLoader.js';
|
||||
import { getLocale } from '../../../../i18n/index.js';
|
||||
import { createGoogleViewer } from './viewer.js';
|
||||
import {
|
||||
COLORS,
|
||||
@@ -48,7 +49,7 @@ function settleWithin(promise, { ms, signal, loader }) {
|
||||
*/
|
||||
export function createGoogleProvider({
|
||||
getApiKey,
|
||||
loader = createMapsLoader({ getApiKey }),
|
||||
loader = createMapsLoader({ getApiKey, getLanguage: getLocale }),
|
||||
}) {
|
||||
if (typeof getApiKey !== 'function')
|
||||
throw new TypeError('Google Street View needs getApiKey');
|
||||
|
||||
@@ -9,10 +9,13 @@ const READY_CALLBACK = '__gevGoogleMapsReady';
|
||||
const PAGE_LOAD = Symbol.for('gev.googleMapsLoad');
|
||||
|
||||
/**
|
||||
* @param {{getApiKey: () => string|null|undefined, document?: Document, global?: object}} options
|
||||
* @param {{getApiKey: () => string|null|undefined, getLanguage?: () => string|null|undefined, document?: Document, global?: object}} options
|
||||
* `getLanguage` names the UI language; Google's own controls (Terms,
|
||||
* Report a problem) follow it. English adds nothing, as before.
|
||||
*/
|
||||
export function createMapsLoader({
|
||||
getApiKey,
|
||||
getLanguage,
|
||||
document = globalThis.document,
|
||||
global = globalThis,
|
||||
}) {
|
||||
@@ -53,12 +56,15 @@ export function createMapsLoader({
|
||||
};
|
||||
const script = document.createElement('script');
|
||||
script.async = true;
|
||||
script.src = `${SCRIPT_ORIGIN}/maps/api/js?${new URLSearchParams({
|
||||
const params = new URLSearchParams({
|
||||
key,
|
||||
v: 'weekly',
|
||||
loading: 'async',
|
||||
callback: READY_CALLBACK,
|
||||
})}`;
|
||||
});
|
||||
const language = getLanguage?.();
|
||||
if (language && language !== 'en') params.set('language', language);
|
||||
script.src = `${SCRIPT_ORIGIN}/maps/api/js?${params}`;
|
||||
script.onerror = () => {
|
||||
if (global[PAGE_LOAD] === loading) delete global[PAGE_LOAD];
|
||||
script.remove();
|
||||
|
||||
@@ -142,3 +142,19 @@ test('a retried load still reports a refusal once, and the page handler once', a
|
||||
assert.deepEqual(heard, ['a']);
|
||||
assert.equal(before, 1);
|
||||
});
|
||||
|
||||
test('Google controls follow the UI language; English adds no parameter', async () => {
|
||||
const language = (locale) => {
|
||||
const page = fakePage();
|
||||
const loader = createMapsLoader({
|
||||
getApiKey: () => 'k-1',
|
||||
getLanguage: () => locale,
|
||||
...page,
|
||||
});
|
||||
void loader.importLibrary('streetView').catch(() => {});
|
||||
return new URL(page.scripts[0].src).searchParams.get('language');
|
||||
};
|
||||
assert.equal(language('es'), 'es');
|
||||
assert.equal(language('ru'), 'ru');
|
||||
assert.equal(language('en'), null);
|
||||
});
|
||||
Reference in new issue
Block a user