Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
cfea3723
Unverified
Commit
cfea3723
authored
May 29, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove setting the locale from using the active locale
parent
7d0fb9cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
useActiveLocale.ts
src/hooks/useActiveLocale.ts
+10
-6
i18n.tsx
src/i18n.tsx
+2
-1
No files found.
src/hooks/useActiveLocale.ts
View file @
cfea3723
import
{
DEFAULT_LOCALE
,
SupportedLocale
,
SUPPORTED_LOCALES
}
from
'
constants/locales
'
import
{
DEFAULT_LOCALE
,
SupportedLocale
,
SUPPORTED_LOCALES
}
from
'
constants/locales
'
import
{
useEffect
,
useMemo
}
from
'
react
'
import
{
useEffect
,
useMemo
}
from
'
react
'
import
{
useUserLocaleManager
}
from
'
state/user/hooks
'
import
{
useUserLocale
,
useUserLocale
Manager
}
from
'
state/user/hooks
'
import
useParsedQueryString
from
'
./useParsedQueryString
'
import
useParsedQueryString
from
'
./useParsedQueryString
'
/**
/**
...
@@ -29,19 +29,23 @@ function navigatorLocale(): SupportedLocale | undefined {
...
@@ -29,19 +29,23 @@ function navigatorLocale(): SupportedLocale | undefined {
return
parseLocale
(
language
)
return
parseLocale
(
language
)
}
}
/**
export
function
useSetLocaleFromUrl
()
{
* Returns the currently active locale, from a combination of user agent, query string, and user settings stored in redux
*/
export
function
useActiveLocale
():
SupportedLocale
{
const
parsed
=
useParsedQueryString
()
const
parsed
=
useParsedQueryString
()
const
[
userLocale
,
setUserLocale
]
=
useUserLocaleManager
()
const
[
userLocale
,
setUserLocale
]
=
useUserLocaleManager
()
useEffect
(()
=>
{
useEffect
(()
=>
{
const
urlLocale
=
typeof
parsed
.
lng
===
'
string
'
?
parseLocale
(
parsed
.
lng
)
:
undefined
const
urlLocale
=
typeof
parsed
.
lng
===
'
string
'
?
parseLocale
(
parsed
.
lng
)
:
undefined
if
(
urlLocale
)
{
if
(
urlLocale
&&
urlLocale
!==
userLocale
)
{
setUserLocale
(
urlLocale
)
setUserLocale
(
urlLocale
)
}
}
},
[
parsed
.
lng
,
setUserLocale
,
userLocale
])
},
[
parsed
.
lng
,
setUserLocale
,
userLocale
])
}
/**
* Returns the currently active locale, from a combination of user agent, query string, and user settings stored in redux
*/
export
function
useActiveLocale
():
SupportedLocale
{
const
userLocale
=
useUserLocale
()
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
return
userLocale
??
navigatorLocale
()
??
DEFAULT_LOCALE
return
userLocale
??
navigatorLocale
()
??
DEFAULT_LOCALE
...
...
src/i18n.tsx
View file @
cfea3723
...
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react'
...
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react'
import
{
i18n
}
from
'
@lingui/core
'
import
{
i18n
}
from
'
@lingui/core
'
import
{
I18nProvider
}
from
'
@lingui/react
'
import
{
I18nProvider
}
from
'
@lingui/react
'
import
{
ReactNode
}
from
'
react
'
import
{
ReactNode
}
from
'
react
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useActiveLocale
,
useSetLocaleFromUrl
}
from
'
hooks/useActiveLocale
'
import
{
SupportedLocale
}
from
'
constants/locales
'
import
{
SupportedLocale
}
from
'
constants/locales
'
export
async
function
dynamicActivate
(
locale
:
SupportedLocale
)
{
export
async
function
dynamicActivate
(
locale
:
SupportedLocale
)
{
...
@@ -13,6 +13,7 @@ export async function dynamicActivate(locale: SupportedLocale) {
...
@@ -13,6 +13,7 @@ export async function dynamicActivate(locale: SupportedLocale) {
}
}
export
function
LanguageProvider
({
children
}:
{
children
:
ReactNode
})
{
export
function
LanguageProvider
({
children
}:
{
children
:
ReactNode
})
{
useSetLocaleFromUrl
()
const
locale
=
useActiveLocale
()
const
locale
=
useActiveLocale
()
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment