Skip to content

Commit

Permalink
fix: use URL for partial locale lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff committed Sep 12, 2024
1 parent 1960627 commit 9e017d8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 56 deletions.
6 changes: 2 additions & 4 deletions components/global/Header/LanguageSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import PropTypes from "prop-types";
import { useEffect, useState } from "react";
import { useRouter, useSearchParams, usePathname } from "next/navigation";
import { useTranslation } from "react-i18next";
import { getCookie } from "cookies-next";
import { cookieName, fallbackLng } from "@/lib/i18n/settings";
import { fallbackLng } from "@/lib/i18n/settings";
import * as Styled from "./styles";

const filterSearchParams = (searchParams) => {
Expand All @@ -25,9 +24,8 @@ export default function LanguageSelect({ id }) {
const searchParams = useSearchParams();
const {
t,
i18n: { changeLanguage },
i18n: { changeLanguage, resolvedLanguage: locale },
} = useTranslation();
const locale = getCookie(cookieName) || fallbackLng;

const isDefaultLocale = fallbackLng.includes(locale);

Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ i18n
detection: {
excludeCacheFor: languages,
lookupCookie: cookieName,
order: ["cookie", "navigator"],
lookupQuerystring: "locale",
order: ["path", "querystring", "cookie", "navigator", "htmlTag"],
},
preload: runsOnServerSide ? languages : [],
});
Expand Down
22 changes: 11 additions & 11 deletions lib/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { getOptions } from "./settings";
export const loadResources = resourcesToBackend(
(language, namespace, callback) => {
switch (namespace) {
// case "epo-react-lib":
// import(
// `@rubin-epo/epo-react-lib/localeStrings/${language}/${namespace}.json`
// )
// .then(({ default: resources }) => {
// callback(null, resources);
// })
// .catch((error) => {
// callback(error, null);
// });
// break;
case "epo-react-lib":
import(
`@rubin-epo/epo-react-lib/localeStrings/${language}/${namespace}.json`
)
.then(({ default: resources }) => {
callback(null, resources);
})
.catch((error) => {
callback(error, null);
});
break;
default:
import(`./localeStrings/${language}/${namespace}.json`)
.then(({ default: resources }) => {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"add": "^2.0.6",
"classnames": "^2.3.1",
"convert": "^4.13.0",
"cookies-next": "^4.2.1",
"feed": "^4.2.2",
"focus-trap": "^7.0.0",
"focus-visible": "^5.1.0",
Expand All @@ -74,12 +73,13 @@
"graphql-request": "^5.0.0",
"hoist-non-react-statics": "^3.3.2",
"i18next": "^22.0.4",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-resources-to-backend": "^1.2.1",
"json-to-scss": "^1.6.2",
"jwt-decode": "^3.1.2",
"next": "^14.2.3",
"next-build-id": "^3.0.0",
"next-intl": "^3.15.3",
"next-intl": "^3.19.1",
"npm-run-all": "^4.1.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down Expand Up @@ -117,7 +117,6 @@
"eslint-plugin-storybook": "^0.6.11",
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^8.0.3",
"i18next-browser-languagedetector": "^8.0.0",
"jsconfig-paths-jest-mapper": "^1.0.0",
"lint-staged": "^13.0.3",
"local-cors-proxy": "^1.1.0",
Expand Down
50 changes: 13 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@
"@formatjs/intl-localematcher" "0.5.4"
tslib "^2.4.0"

"@formatjs/fast-memoize@2.2.0":
"@formatjs/fast-memoize@2.2.0", "@formatjs/fast-memoize@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.0.tgz#33bd616d2e486c3e8ef4e68c99648c196887802b"
integrity sha512-hnk/nY8FyrL5YxwP9e4r9dqeM6cAbo8PeU9UjyXojZMNvVad2Z06FAVHyR3Ecw6fza+0GH7vdJgiKIVXTMbSBA==
Expand All @@ -1846,20 +1846,13 @@
"@formatjs/ecma402-abstract" "2.0.0"
tslib "^2.4.0"

"@formatjs/intl-localematcher@0.5.4":
"@formatjs/intl-localematcher@0.5.4", "@formatjs/intl-localematcher@^0.5.4":
version "0.5.4"
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.4.tgz#caa71f2e40d93e37d58be35cfffe57865f2b366f"
integrity sha512-zTwEpWOzZ2CiKcB93BLngUX59hQkuZjT2+SAQEscSm52peDW/getsawMcWF1rGRpMCX6D7nSJA3CzJ8gn13N/g==
dependencies:
tslib "^2.4.0"

"@formatjs/intl-localematcher@^0.2.32":
version "0.2.32"
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.2.32.tgz#00d4d307cd7d514b298e15a11a369b86c8933ec1"
integrity sha512-k/MEBstff4sttohyEpXxCmC3MqbUn9VvHGlZ8fauLzkbwXmVrEeyzS+4uhrvAk9DWU9/7otYWxyDox4nT/KVLQ==
dependencies:
tslib "^2.4.0"

"@graphql-typed-document-node/core@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052"
Expand Down Expand Up @@ -3340,11 +3333,6 @@
dependencies:
"@types/node" "*"

"@types/cookie@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5"
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==

"@types/detect-port@^1.3.0":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/detect-port/-/detect-port-1.3.2.tgz#8c06a975e472803b931ee73740aeebd0a2eb27ae"
Expand Down Expand Up @@ -5000,19 +4988,6 @@ cookie@0.5.0:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b"
integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==

cookie@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051"
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==

cookies-next@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/cookies-next/-/cookies-next-4.2.1.tgz#a0c2942afee16f1ffc2bc05a003c7c0cf32deda5"
integrity sha512-qsjtZ8TLlxCSX2JphMQNhkm3V3zIMQ05WrLkBKBwu50npBbBfiZWIdmSMzBGcdGKfMK19E0PIitTfRFAdMGHXg==
dependencies:
"@types/cookie" "^0.6.0"
cookie "^0.6.0"

core-js-compat@^3.25.1:
version "3.27.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.27.1.tgz#b5695eb25c602d72b1d30cbfba3cb7e5e4cf0a67"
Expand Down Expand Up @@ -8556,14 +8531,14 @@ next-build-id@^3.0.0:
resolved "https://registry.yarnpkg.com/next-build-id/-/next-build-id-3.0.0.tgz#bfb7a1e2df03882688758f0a4a67e6e837043f42"
integrity sha512-B3JCsL/9Z/wkmo3EySukQHCgx89Aw0i4LPi2MEhCboQBJ6wpkYTIu1z6hOYKuw/S1Wy8ZRqCEq0dVY/ST6jGqg==

next-intl@^3.15.3:
version "3.15.3"
resolved "https://registry.yarnpkg.com/next-intl/-/next-intl-3.15.3.tgz#c964a4f123d214517c2424514cdd19d16a317f73"
integrity sha512-jNc2xYzwv0Q4EQKvuHye9dXaDaneiP/ZCQC+AccyOQD6N9d/FZiSWT4wfVVD4B0IXC1Hhzj1QussUu+k3ynnTg==
next-intl@^3.19.1:
version "3.19.1"
resolved "https://registry.yarnpkg.com/next-intl/-/next-intl-3.19.1.tgz#b78cabb7940d7ac9048935eb5f71d529f197121b"
integrity sha512-KlJSomzbB5dNkWBIiSIRaoy5zqwLgHNV5Zw0ULhkHjNnPN7aLFFv2G+VOQKle630sNH2JiKc9nsmi6PM1GdkhA==
dependencies:
"@formatjs/intl-localematcher" "^0.2.32"
"@formatjs/intl-localematcher" "^0.5.4"
negotiator "^0.6.3"
use-intl "^3.15.3"
use-intl "^3.19.1"

next@^14.2.3:
version "14.2.3"
Expand Down Expand Up @@ -11561,11 +11536,12 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

use-intl@^3.15.3:
version "3.15.3"
resolved "https://registry.yarnpkg.com/use-intl/-/use-intl-3.15.3.tgz#b6610f9e01a0188596c894ecea43b7896905a7fa"
integrity sha512-cHSeFy2cy4u6tT8A7KAcDbs+Hz6lytXClVSsOI1leD6OOrpakNxsmyLa8SMrttOAUQto5kV1f4LVhiX/lpkO3g==
use-intl@^3.19.1:
version "3.19.1"
resolved "https://registry.yarnpkg.com/use-intl/-/use-intl-3.19.1.tgz#2d3b69e72d908215fd8e3d454289c7dfe36c6e8c"
integrity sha512-FUblDZJ/iuXusroBxvzVwXmgjHIef2YHJ0ASRmkMV8whlcRr6QJozBZUR/xB4I0+MMbWDD4GPugUK+MxE2coJA==
dependencies:
"@formatjs/fast-memoize" "^2.2.0"
intl-messageformat "^10.5.14"

use-resize-observer@^9.0.2:
Expand Down

0 comments on commit 9e017d8

Please sign in to comment.