Expose i18n globals in SignalContext across all windows
This commit is contained in:
parent
55394e17c0
commit
4455328312
13 changed files with 38 additions and 27 deletions
|
@ -29,14 +29,16 @@ global.window = {
|
||||||
warn: (...args) => console.warn(...args),
|
warn: (...args) => console.warn(...args),
|
||||||
error: (...args) => console.error(...args),
|
error: (...args) => console.error(...args),
|
||||||
},
|
},
|
||||||
|
getResolvedMessagesLocale: () => 'en',
|
||||||
|
getResolvedMessagesLocaleDirection: () => 'ltr',
|
||||||
|
getHourCyclePreference: () => HourCyclePreference.UnknownPreference,
|
||||||
|
getPreferredSystemLocales: () => ['en'],
|
||||||
},
|
},
|
||||||
i18n: key => `i18n(${key})`,
|
i18n: key => `i18n(${key})`,
|
||||||
storage: {
|
storage: {
|
||||||
get: key => storageMap.get(key),
|
get: key => storageMap.get(key),
|
||||||
put: async (key, value) => storageMap.set(key, value),
|
put: async (key, value) => storageMap.set(key, value),
|
||||||
},
|
},
|
||||||
getPreferredSystemLocales: () => ['en'],
|
|
||||||
getHourCyclePreference: () => HourCyclePreference.UnknownPreference,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// For ducks/network.getEmptyState()
|
// For ducks/network.getEmptyState()
|
||||||
|
|
|
@ -573,12 +573,12 @@ export async function startApp(): Promise<void> {
|
||||||
|
|
||||||
document.documentElement.setAttribute(
|
document.documentElement.setAttribute(
|
||||||
'lang',
|
'lang',
|
||||||
window.getResolvedMessagesLocale().split(/[-_]/)[0]
|
window.SignalContext.getResolvedMessagesLocale().split(/[-_]/)[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
document.documentElement.setAttribute(
|
document.documentElement.setAttribute(
|
||||||
'dir',
|
'dir',
|
||||||
window.getResolvedMessagesLocaleDirection()
|
window.SignalContext.getResolvedMessagesLocaleDirection()
|
||||||
);
|
);
|
||||||
|
|
||||||
KeyChangeListener.init(window.textsecure.storage.protocol);
|
KeyChangeListener.init(window.textsecure.storage.protocol);
|
||||||
|
|
|
@ -36,7 +36,7 @@ export function ChatSessionRefreshedNotification(
|
||||||
|
|
||||||
const baseUrl =
|
const baseUrl =
|
||||||
'https://support.signal.org/hc/LOCALE/requests/new?desktop&chat_refreshed';
|
'https://support.signal.org/hc/LOCALE/requests/new?desktop&chat_refreshed';
|
||||||
const locale = window.getResolvedMessagesLocale();
|
const locale = window.SignalContext.getResolvedMessagesLocale();
|
||||||
const supportLocale = mapToSupportLocale(locale);
|
const supportLocale = mapToSupportLocale(locale);
|
||||||
const url = baseUrl.replace('LOCALE', supportLocale);
|
const url = baseUrl.replace('LOCALE', supportLocale);
|
||||||
|
|
||||||
|
|
|
@ -2806,8 +2806,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
'getProfile: expected updatesUrl to be a defined string'
|
'getProfile: expected updatesUrl to be a defined string'
|
||||||
);
|
);
|
||||||
const userLanguages = getUserLanguages(
|
const userLanguages = getUserLanguages(
|
||||||
window.getPreferredSystemLocales(),
|
window.SignalContext.getPreferredSystemLocales(),
|
||||||
window.getResolvedMessagesLocale()
|
window.SignalContext.getResolvedMessagesLocale()
|
||||||
);
|
);
|
||||||
const { messaging } = window.textsecure;
|
const { messaging } = window.textsecure;
|
||||||
if (!messaging) {
|
if (!messaging) {
|
||||||
|
|
|
@ -224,8 +224,8 @@ async function doGetProfile(c: ConversationModel): Promise<void> {
|
||||||
);
|
);
|
||||||
|
|
||||||
const userLanguages = getUserLanguages(
|
const userLanguages = getUserLanguages(
|
||||||
window.getPreferredSystemLocales(),
|
window.SignalContext.getPreferredSystemLocales(),
|
||||||
window.getResolvedMessagesLocale()
|
window.SignalContext.getResolvedMessagesLocale()
|
||||||
);
|
);
|
||||||
|
|
||||||
let profile;
|
let profile;
|
||||||
|
|
|
@ -16,8 +16,14 @@ describe('formatTimestamp', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sandbox = sinon.createSandbox();
|
sandbox = sinon.createSandbox();
|
||||||
localesStub = sandbox.stub(window, 'getPreferredSystemLocales');
|
localesStub = sandbox.stub(
|
||||||
hourCycleStub = sandbox.stub(window, 'getHourCyclePreference');
|
window.SignalContext,
|
||||||
|
'getPreferredSystemLocales'
|
||||||
|
);
|
||||||
|
hourCycleStub = sandbox.stub(
|
||||||
|
window.SignalContext,
|
||||||
|
'getHourCyclePreference'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { assertDev } from './assert';
|
||||||
function getOptionsWithPreferences(
|
function getOptionsWithPreferences(
|
||||||
options: Intl.DateTimeFormatOptions
|
options: Intl.DateTimeFormatOptions
|
||||||
): Intl.DateTimeFormatOptions {
|
): Intl.DateTimeFormatOptions {
|
||||||
const hourCyclePreference = window.getHourCyclePreference();
|
const hourCyclePreference = window.SignalContext.getHourCyclePreference();
|
||||||
if (options.hour12 != null) {
|
if (options.hour12 != null) {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ const formatterCache = new Map<string, Intl.DateTimeFormat>();
|
||||||
export function getDateTimeFormatter(
|
export function getDateTimeFormatter(
|
||||||
options: Intl.DateTimeFormatOptions
|
options: Intl.DateTimeFormatOptions
|
||||||
): Intl.DateTimeFormat {
|
): Intl.DateTimeFormat {
|
||||||
const locales = window.getPreferredSystemLocales();
|
const locales = window.SignalContext.getPreferredSystemLocales();
|
||||||
const optionsWithPreferences = getOptionsWithPreferences(options);
|
const optionsWithPreferences = getOptionsWithPreferences(options);
|
||||||
const cacheKey = getCacheKey(locales, optionsWithPreferences);
|
const cacheKey = getCacheKey(locales, optionsWithPreferences);
|
||||||
const cachedFormatter = formatterCache.get(cacheKey);
|
const cachedFormatter = formatterCache.get(cacheKey);
|
||||||
|
|
|
@ -15,6 +15,7 @@ const logicalArrows: Record<
|
||||||
};
|
};
|
||||||
|
|
||||||
export function arrow(logicalDirection: LogicalDirection): HorizontalArrowKey {
|
export function arrow(logicalDirection: LogicalDirection): HorizontalArrowKey {
|
||||||
const localeDirection = window.getResolvedMessagesLocaleDirection();
|
const localeDirection =
|
||||||
|
window.SignalContext.getResolvedMessagesLocaleDirection();
|
||||||
return logicalArrows[logicalDirection][localeDirection];
|
return logicalArrows[logicalDirection][localeDirection];
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,10 +121,10 @@ export function setupI18n(
|
||||||
localizer.getLocale = () => locale;
|
localizer.getLocale = () => locale;
|
||||||
localizer.getLocaleMessages = () => messages;
|
localizer.getLocaleMessages = () => messages;
|
||||||
localizer.getLocaleDirection = () => {
|
localizer.getLocaleDirection = () => {
|
||||||
return window.getResolvedMessagesLocaleDirection();
|
return window.SignalContext.getResolvedMessagesLocaleDirection();
|
||||||
};
|
};
|
||||||
localizer.getHourCyclePreference = () => {
|
localizer.getHourCyclePreference = () => {
|
||||||
return window.getHourCyclePreference();
|
return window.SignalContext.getHourCyclePreference();
|
||||||
};
|
};
|
||||||
|
|
||||||
return localizer;
|
return localizer;
|
||||||
|
|
6
ts/window.d.ts
vendored
6
ts/window.d.ts
vendored
|
@ -56,9 +56,7 @@ import type * as Message2 from './types/Message2';
|
||||||
import type { initializeMigrations } from './signal';
|
import type { initializeMigrations } from './signal';
|
||||||
import type { RetryPlaceholders } from './util/retryPlaceholders';
|
import type { RetryPlaceholders } from './util/retryPlaceholders';
|
||||||
import type { PropsPreloadType as PreferencesPropsType } from './components/Preferences';
|
import type { PropsPreloadType as PreferencesPropsType } from './components/Preferences';
|
||||||
import type { LocaleDirection } from '../app/locale';
|
|
||||||
import type { WindowsNotificationData } from './services/notifications';
|
import type { WindowsNotificationData } from './services/notifications';
|
||||||
import type { HourCyclePreference } from './types/I18N';
|
|
||||||
|
|
||||||
export { Long } from 'long';
|
export { Long } from 'long';
|
||||||
|
|
||||||
|
@ -199,10 +197,6 @@ declare global {
|
||||||
getEnvironment: typeof getEnvironment;
|
getEnvironment: typeof getEnvironment;
|
||||||
getHostName: () => string;
|
getHostName: () => string;
|
||||||
getInteractionMode: () => 'mouse' | 'keyboard';
|
getInteractionMode: () => 'mouse' | 'keyboard';
|
||||||
getResolvedMessagesLocaleDirection: () => LocaleDirection;
|
|
||||||
getHourCyclePreference: () => HourCyclePreference;
|
|
||||||
getResolvedMessagesLocale: () => string;
|
|
||||||
getPreferredSystemLocales: () => Array<string>;
|
|
||||||
getServerPublicParams: () => string;
|
getServerPublicParams: () => string;
|
||||||
getSfuUrl: () => string;
|
getSfuUrl: () => string;
|
||||||
getSocketStatus: () => SocketStatus;
|
getSocketStatus: () => SocketStatus;
|
||||||
|
|
|
@ -22,6 +22,8 @@ import { i18n } from '../context/i18n';
|
||||||
import { strictAssert } from '../util/assert';
|
import { strictAssert } from '../util/assert';
|
||||||
import { initialize as initializeLogging } from '../logging/set_up_renderer_logging';
|
import { initialize as initializeLogging } from '../logging/set_up_renderer_logging';
|
||||||
import { MinimalSignalContext } from './minimalContext';
|
import { MinimalSignalContext } from './minimalContext';
|
||||||
|
import type { LocaleDirection } from '../../app/locale';
|
||||||
|
import type { HourCyclePreference } from '../types/I18N';
|
||||||
|
|
||||||
strictAssert(Boolean(window.SignalContext), 'context must be defined');
|
strictAssert(Boolean(window.SignalContext), 'context must be defined');
|
||||||
|
|
||||||
|
@ -41,6 +43,10 @@ export type MinimalSignalContextType = {
|
||||||
getEnvironment: () => string;
|
getEnvironment: () => string;
|
||||||
getI18nLocale: LocalizerType['getLocale'];
|
getI18nLocale: LocalizerType['getLocale'];
|
||||||
getI18nLocaleMessages: LocalizerType['getLocaleMessages'];
|
getI18nLocaleMessages: LocalizerType['getLocaleMessages'];
|
||||||
|
getResolvedMessagesLocaleDirection: () => LocaleDirection;
|
||||||
|
getHourCyclePreference: () => HourCyclePreference;
|
||||||
|
getResolvedMessagesLocale: () => string;
|
||||||
|
getPreferredSystemLocales: () => Array<string>;
|
||||||
getMainWindowStats: () => Promise<MainWindowStatsType>;
|
getMainWindowStats: () => Promise<MainWindowStatsType>;
|
||||||
getMenuOptions: () => Promise<MenuOptionsType>;
|
getMenuOptions: () => Promise<MenuOptionsType>;
|
||||||
getNodeVersion: () => string;
|
getNodeVersion: () => string;
|
||||||
|
|
|
@ -45,11 +45,6 @@ window.RETRY_DELAY = false;
|
||||||
|
|
||||||
window.platform = process.platform;
|
window.platform = process.platform;
|
||||||
window.getTitle = () => title;
|
window.getTitle = () => title;
|
||||||
window.getResolvedMessagesLocale = () => config.resolvedTranslationsLocale;
|
|
||||||
window.getResolvedMessagesLocaleDirection = () =>
|
|
||||||
config.resolvedTranslationsLocaleDirection;
|
|
||||||
window.getHourCyclePreference = () => config.hourCyclePreference;
|
|
||||||
window.getPreferredSystemLocales = () => config.preferredSystemLocales;
|
|
||||||
window.getEnvironment = getEnvironment;
|
window.getEnvironment = getEnvironment;
|
||||||
window.getAppInstance = () => config.appInstance;
|
window.getAppInstance = () => config.appInstance;
|
||||||
window.getVersion = () => config.version;
|
window.getVersion = () => config.version;
|
||||||
|
|
|
@ -42,6 +42,13 @@ export const MinimalSignalContext: MinimalSignalContextType = {
|
||||||
},
|
},
|
||||||
getI18nLocale: () => config.resolvedTranslationsLocale,
|
getI18nLocale: () => config.resolvedTranslationsLocale,
|
||||||
getI18nLocaleMessages: () => localeMessages,
|
getI18nLocaleMessages: () => localeMessages,
|
||||||
|
|
||||||
|
getResolvedMessagesLocale: () => config.resolvedTranslationsLocale,
|
||||||
|
getResolvedMessagesLocaleDirection: () =>
|
||||||
|
config.resolvedTranslationsLocaleDirection,
|
||||||
|
getHourCyclePreference: () => config.hourCyclePreference,
|
||||||
|
getPreferredSystemLocales: () => config.preferredSystemLocales,
|
||||||
|
|
||||||
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
||||||
OS: {
|
OS: {
|
||||||
getClassName: () => ipcRenderer.sendSync('OS.getClassName'),
|
getClassName: () => ipcRenderer.sendSync('OS.getClassName'),
|
||||||
|
|
Loading…
Reference in a new issue