You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Localization.getLocales() returns an empty array []. This is not in accordance to the documentation.
As a result, the next line causes an error when testing Expo web.
On expo-modules-core/src/Platform.ts, Platform defines the isDOMAvailable property:
isDOMAvailable,
/**
* Denotes if the current environment can attach event listeners
* to the window. This will return false in native React
* runtimes and Node.js.
*/
It reads the defaults from environment/browser.ts:
// In standard node environments there is no DOM API
export const isDOMAvailable = false;
export const canUseEventListeners = false;
export const canUseViewport = false;
This is causing the inconsistent behavior on web, which is not in accordance to the documentation.
create file core/i18n/languageDetectorWeb.ts with this code:
import LanguageDetector from 'i18next-browser-languagedetector';
export const languageDetectorWeb = new LanguageDetector();
changed core/i18n/init.ts to read:
...
import { languageDetectorWeb } from './languageDetectorWeb'; //added new language detector just for the web
...
return i18n
.use(Platform.OS === 'web' ? languageDetectorWeb : languageDetector) // use one or the other language detector depending on platform
...
Not sure if it's the ideal solution, as I am working around something that's plainly not working as the documentation says.
But since I created the app using create-expo-stack, I figured you may want to implement this to have a more feature-complete solution out-of-the-box.
The text was updated successfully, but these errors were encountered:
will inspect the issue here as I happen to be considering another tool for internationalization but I would not expect a fix in the coming couple weeks as I have other things that are of higher priority atm
Hello there!
I digged a bit into the code.
When starting up a fresh project using:
npx create-expo-stack@latest poster --tamagui --expo-router --supabase --i18next
On
languageDetector.ts
, these lines returns an error when testing or trying to build for productionExpo web
:Localization.getLocales()
returns an empty array[]
. This is not in accordance to the documentation.As a result, the next line causes an error when testing Expo web.
https://docs.expo.dev/versions/latest/sdk/localization/#localizationgetlocales
List of user's locales, returned as an array of objects of type Locale. Guaranteed to contain at least 1 element.
Digging deeper:
In the module
expo-localization/ExpoLocalization.ts
,getLocales()
start with:getNavigatorLocales()
is defined on the same file:On
expo-modules-core/src/Platform.ts
,Platform
defines theisDOMAvailable
property:It reads the defaults from
environment/browser.ts
:This is causing the inconsistent behavior on
web
, which is not in accordance to the documentation.I worked around it with the following steps:
i18next-browser-languagedetector
(official i18n package)core/i18n/languageDetectorWeb.ts
with this code:Not sure if it's the ideal solution, as I am working around something that's plainly not working as the documentation says.
But since I created the app using create-expo-stack, I figured you may want to implement this to have a more feature-complete solution out-of-the-box.
The text was updated successfully, but these errors were encountered: