π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove storage dependency
Manav Rathif620ace655ad
diff --git a/apps/accounts/src/pages/_app.tsx b/apps/accounts/src/pages/_app.tsxindex bf0d57b617..9e359537f2 100644--- a/apps/accounts/src/pages/_app.tsx+++ b/apps/accounts/src/pages/_app.tsx@@ -13,6 +13,7 @@ import { useLocalState } from '@ente/shared/hooks/useLocalState';import { setupI18n } from '@ente/shared/i18n';import HTTPService from '@ente/shared/network/HTTPService';import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';+import { getUserLocaleString } from '@ente/shared/storage/localStorage/helpers';import { getTheme } from '@ente/shared/themes';import { THEME_COLOR } from '@ente/shared/themes/constants';import createEmotionCache from '@ente/shared/themes/createEmotionCache';@@ -63,7 +64,7 @@ export default function App(props: EnteAppProps) {const [themeColor] = useLocalState(LS_KEYS.THEME, THEME_COLOR.DARK);useEffect(() => {- setupI18n().finally(() => setIsI18nReady(true));+ setupI18n(getUserLocaleString()).finally(() => setIsI18nReady(true));}, []);const setupPackageName = () => {diff --git a/apps/auth/src/pages/_app.tsx b/apps/auth/src/pages/_app.tsxindex 2594dfa1fb..210c12328d 100644--- a/apps/auth/src/pages/_app.tsx+++ b/apps/auth/src/pages/_app.tsx@@ -37,6 +37,7 @@ import { useLocalState } from '@ente/shared/hooks/useLocalState';import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';import { getTheme } from '@ente/shared/themes';import '../../public/css/global.css';+import { getUserLocaleString } from '@ente/shared/storage/localStorage/helpers';type AppContextType = {showNavBar: (show: boolean) => void;@@ -80,7 +81,7 @@ export default function App(props: EnteAppProps) {useEffect(() => {//setup i18n- setupI18n().finally(() => setIsI18nReady(true));+ setupI18n(getUserLocaleString()).finally(() => setIsI18nReady(true));// set client package name in headersHTTPService.setHeaders({'X-Client-Package': CLIENT_PACKAGE_NAMES.get(APPS.AUTH),diff --git a/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx b/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsxindex 16d2316ac7..4e656a833e 100644--- a/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx+++ b/apps/photos/src/components/Sidebar/Preferences/LanguageSelector.tsx@@ -4,6 +4,7 @@ import { t } from 'i18next';import { useRouter } from 'next/router';import { Language, getBestPossibleUserLocale } from '@ente/shared/i18n';import { LS_KEYS } from '@ente/shared/storage/localStorage';+import { getUserLocaleString } from '@ente/shared/storage/localStorage/helpers';const getLocaleDisplayName = (l: Language) => {switch (l) {@@ -30,7 +31,7 @@ const getLanguageOptions = (): DropdownOption<Language>[] => {export const LanguageSelector = () => {const [userLocale, setUserLocale] = useLocalState(LS_KEYS.LOCALE,- getBestPossibleUserLocale()+ getBestPossibleUserLocale(getUserLocaleString()));const router = useRouter();diff --git a/apps/photos/src/pages/_app.tsx b/apps/photos/src/pages/_app.tsxindex 0b2e795cae..2e31bc0cc8 100644--- a/apps/photos/src/pages/_app.tsx+++ b/apps/photos/src/pages/_app.tsx@@ -66,6 +66,7 @@ import { REDIRECTS } from 'constants/redirects';import {getLocalMapEnabled,getToken,+ getUserLocaleString,setLocalMapEnabled,} from '@ente/shared/storage/localStorage/helpers';import { isExportInProgress } from 'utils/export';@@ -162,7 +163,7 @@ export default function App(props: EnteAppProps) {useEffect(() => {//setup i18n- setupI18n().finally(() => setIsI18nReady(true));+ setupI18n(getUserLocaleString()).finally(() => setIsI18nReady(true));// set client package name in headersHTTPService.setHeaders({'X-Client-Package': CLIENT_PACKAGE_NAMES.get(APPS.PHOTOS),diff --git a/packages/shared/i18n/index.ts b/packages/shared/i18n/index.tsindex 23c1884937..c59c1bca66 100644--- a/packages/shared/i18n/index.ts+++ b/packages/shared/i18n/index.ts@@ -2,9 +2,7 @@ import i18n from 'i18next';import { initReactI18next } from 'react-i18next';import Backend from 'i18next-http-backend';import { isDevBuild } from '@/utils/env';-import { getUserLocales } from 'get-user-locale';-import { getUserLocale } from '@ente/shared/storage/localStorage/helpers';/*** Load translations.@@ -19,7 +17,8 @@ import { getUserLocale } from '@ente/shared/storage/localStorage/helpers';** - react-i18next, which adds React specific APIs*/-export const setupI18n = async () => {+export const setupI18n = async (savedLocaleString?: string) => {+ const lng = getBestPossibleUserLocale(savedLocaleString);// https://www.i18next.com/overview/apiawait i18n// i18next-http-backend: Asynchronously loads translations over HTTP@@ -34,7 +33,7 @@ export const setupI18n = async () => {debug: isDevBuild,returnEmptyString: false,fallbackLng: 'en',- lng: getBestPossibleUserLocale(),+ lng: lng,interpolation: {escapeValue: false, // not needed for react as it escapes by default},@@ -116,11 +115,21 @@ export enum Language {es = 'es',}-export function getBestPossibleUserLocale(): Language {- const locale = getUserLocale();- if (locale) {- return locale;+export function getBestPossibleUserLocale(savedLocaleString: string): Language {+ const locale = savedLocaleString;+ switch (locale) {+ case 'en':+ return Language.en;+ case 'fr':+ return Language.fr;+ case 'zh':+ return Language.zh;+ case 'nl':+ return Language.nl;+ case 'es':+ return Language.es;}+const userLocales = getUserLocales();for (const lc of userLocales) {if (lc.startsWith('en')) {diff --git a/packages/shared/storage/localStorage/helpers.ts b/packages/shared/storage/localStorage/helpers.tsindex 92613f35db..d9c48865b2 100644--- a/packages/shared/storage/localStorage/helpers.ts+++ b/packages/shared/storage/localStorage/helpers.ts@@ -1,5 +1,4 @@import { LS_KEYS, getData, setData } from '.';-import { Language } from '@ente/shared/i18n';export const getToken = (): string => {const token = getData(LS_KEYS.USER)?.token;@@ -30,7 +29,7 @@ export function setLivePhotoInfoShownCount(count: boolean) {setData(LS_KEYS.LIVE_PHOTO_INFO_SHOWN_COUNT, { count });}-export function getUserLocale(): Language {+export function getUserLocaleString(): string {return getData(LS_KEYS.LOCALE)?.value;}