Comments (11)
I did a pull request which fixes this issue.
from talkr.
@gshilin Sorry for the huge delay in my answer, I had a lot of work and completely forgot to tweak this undefined navigator issue in ssr. Thanks @lodmfjord for taking care of that! I'll push the patch on npm by monday (hopefully this evening)!
from talkr.
I've just implemented the fix. It should be available on npm very soon.
from talkr.
navigator
is not defined when is SSR mode. You use it to detect browser's language, but in this case it's impossible, so 'en' may be good enough instead of crash.
from talkr.
Hi Gshilin, thanks for using Talkr! Automatic language detection is an option. You can simply write
<Talkr languages={{ en, fr }} defaultLanguage="en">
<App />
</Talkr>
to let the lib use "en" by default. However, I'll definitely add a fix in the future to avoid any crash with automatic browser detection in case it is not supported.
from talkr.
This happens in
Line 23 in ed261f3
The solution I found is to simulate
navigator
:
if (typeof navigator === 'undefined') {
navigator = {
language: 'en-US',
};
}
But it's quite ugly :(
from talkr.
The correct version is 2.0.2 or superior. The 2.0.1 has an export bug. Npm hasn't updated the package yet, please wait for this version to be available before updating your own package.
from talkr.
Looked at it. Unfortunately it'll return
Uncaught ReferenceError: navigator is not defined
.
You have to use
typeof navigator !== 'undefined'
from talkr.
Why? The script checks if navigator
exists, so it should not crash if the latter is undefined. detectBrowserLanguage && navigator ? browserLanguage : defaultLanguage
.
from talkr.
from talkr.
The script checks if navigator
has truthful value, but if it doesn't exist if will crash
from talkr.
Related Issues (11)
- Feature: Autocomplete json file keys HOT 1
- Any chance of supporting arrays in translation files? HOT 1
- Hooks order HOT 3
- Translation helper for talkr HOT 3
- The hook should also expose the `tr` function for the current context. HOT 5
- warning as an option HOT 1
- detectBrowserLanguage is assigning not supported values HOT 1
- Missing translations warning HOT 5
- setLocale doesn't trigger change HOT 8
- React has detected a change in the order of Hooks HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from talkr.