Skip to content

Commit f82a47f

Browse files
committed
fix broken changeLanguage redirects
Signed-off-by: Dmitriy Nevzorov <[email protected]>
1 parent a616e8c commit f82a47f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
restore-keys: |
2727
${{ runner.os }}-yarn-
2828
29-
- run: yarn install --skip-integrity-check --non-interactive --no-progress
29+
- run: yarn install --frozen-lockfile --skip-integrity-check --non-interactive --no-progress
3030

3131
- run: npm publish --access public
3232
env:

src/useI18next.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const useI18next = (ns?: Namespace, options?: UseTranslationOptions) => {
1414

1515
const {routed, defaultLanguage} = context;
1616

17-
const getUrlLanguage = (language: string) => {
18-
return language !== defaultLanguage ? language : '';
17+
const getLanguagePath = (language: string) => {
18+
return language !== defaultLanguage ? `/${language}` : '';
1919
};
2020

2121
const removePrefix = (pathname: string) => {
@@ -33,15 +33,15 @@ export const useI18next = (ns?: Namespace, options?: UseTranslationOptions) => {
3333
};
3434

3535
const navigate = (to: string, options?: NavigateOptions<{}>) => {
36-
const urlLanguage = getUrlLanguage(context.language);
37-
const link = routed ? `/${urlLanguage}${to}` : `${to}`;
36+
const languagePath = getLanguagePath(context.language);
37+
const link = routed ? `${languagePath}${to}` : `${to}`;
3838
return gatsbyNavigate(link, options);
3939
};
4040

4141
const changeLanguage = (language: string, to?: string, options?: NavigateOptions<{}>) => {
42-
const urlLanguage = getUrlLanguage(language);
42+
const languagePath = getLanguagePath(language);
4343
const pathname = to || removeLocalePart(removePrefix(window.location.pathname));
44-
const link = `/${urlLanguage}${pathname}${window.location.search}`;
44+
const link = `${languagePath}${pathname}${window.location.search}`;
4545
localStorage.setItem(LANGUAGE_KEY, language);
4646
return gatsbyNavigate(link, options);
4747
};

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10478,7 +10478,7 @@ react-side-effect@^2.1.0:
1047810478
resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-2.1.0.tgz#1ce4a8b4445168c487ed24dab886421f74d380d3"
1047910479
integrity sha512-IgmcegOSi5SNX+2Snh1vqmF0Vg/CbkycU9XZbOHJlZ6kMzTmi3yc254oB1WCkgA7OQtIAoLmcSFuHTc/tlcqXg==
1048010480

10481-
react@^16.8.0:
10481+
react@^16.12.0, react@^16.8.0:
1048210482
version "16.13.1"
1048310483
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
1048410484
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==

0 commit comments

Comments
 (0)