This commit is contained in:
David Nguyen
2025-02-11 02:04:00 +11:00
parent d24f67d922
commit 548d92c2fc
22 changed files with 1260 additions and 1152 deletions

View File

@ -1,18 +1,21 @@
/// <reference types="@documenso/tsconfig/process-env.d.ts" />
declare global {
interface Window {
__ENV__?: Record<string, string | undefined>;
}
}
type EnvironmentVariable = keyof NodeJS.ProcessEnv;
export const env = (variable: EnvironmentVariable | (string & object)): string | undefined => {
// console.log({
// ['typeof window']: typeof window,
// ['process.env']: process.env,
// ['window.__ENV__']: typeof window !== 'undefined' && window.__ENV__,
// });
// This may need ot be import.meta.env.SSR depending on vite.
if (typeof window !== 'undefined' && typeof window.__ENV__ === 'object') {
return window.__ENV__[variable];
}
return process.env[variable];
return process?.env?.[variable];
};
// Todo: Test
export const createPublicEnv = () =>
Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('NEXT_PUBLIC_')));

View File

@ -3,13 +3,11 @@ import { i18n } from '@lingui/core';
import type { I18nLocaleData, SupportedLanguageCodes } from '../constants/i18n';
import { APP_I18N_OPTIONS } from '../constants/i18n';
import { env } from './env';
export async function dynamicActivate(locale: string) {
// const extension = import.meta.env.PROD env('NODE_ENV') === 'development' ? 'po' : 'js';
// eslint-disable-next-line turbo/no-undeclared-env-vars
const extension = import.meta.env.PROD ? 'js' : 'po';
const extension = env('NODE_ENV') === 'development' ? 'po' : 'mjs';
// Todo: Use extension (currently breaks).
const { messages } = await import(`../translations/${locale}/web.${extension}`);
i18n.loadAndActivate({ locale, messages });