Skip to content

Commit 0ba3b76

Browse files
authored
Merge pull request #64 from wiziple/versions/0.2.8
Versions/0.2.8
2 parents b5d3844 + 0b4603d commit 0ba3b76

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

examples/gatsby-starter-default-intl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"gatsby": "2.13.39",
99
"gatsby-image": "^2.2.6",
10-
"gatsby-plugin-intl": "^0.2.7",
10+
"gatsby-plugin-intl": "^0.2.8",
1111
"gatsby-plugin-manifest": "^2.2.4",
1212
"gatsby-plugin-offline": "^2.2.4",
1313
"gatsby-plugin-react-helmet": "^3.1.2",

examples/gatsby-starter-default-intl/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,10 +4956,10 @@ gatsby-page-utils@^0.0.5:
49564956
micromatch "^3.1.10"
49574957
slash "^1.0.0"
49584958

4959-
gatsby-plugin-intl@^0.2.7:
4960-
version "0.2.7"
4961-
resolved "https://registry.yarnpkg.com/gatsby-plugin-intl/-/gatsby-plugin-intl-0.2.7.tgz#69e49cd09c3ed29f2d78b1e2c0d7ea6e197cf154"
4962-
integrity sha512-vbX6bM58gAidX+bDk1EczfQdrHgqEEhGrDDOymR+943HSZWKpnzAZwOaZAsFt2UjI2zvVYDdkzC5MmQDPlmabA==
4959+
gatsby-plugin-intl@^0.2.8:
4960+
version "0.2.8"
4961+
resolved "https://registry.yarnpkg.com/gatsby-plugin-intl/-/gatsby-plugin-intl-0.2.8.tgz#d6393c77475e28c64a048416ff4bb389a0410292"
4962+
integrity sha512-m2fK8hKk0b0u7mRbz0DSik6qWvtYiKVm/wtabHOrl/g0vuytqWqqdRcaBAowUhhM5k9R8y/NrcsbNu9GiDJnKA==
49634963
dependencies:
49644964
"@babel/runtime" "^7.4.5"
49654965
browser-lang "^0.1.0"

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gatsby-plugin-intl",
33
"description": "Gatsby plugin to add react-intl onto a site",
4-
"version": "0.2.7",
4+
"version": "0.2.8",
55
"author": "Daewoong Moon <wiziple@gmail.com>",
66
"bugs": {
77
"url": "https://github.com/wiziple/gatsby-plugin-intl"

src/gatsby-node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ exports.onCreatePage = async ({ page, actions }, pluginOptions) => {
8484

8585
languages.forEach(language => {
8686
const localePage = generatePage(true, language)
87-
if (localePage.path.includes(`/404/`)) {
87+
const regexp = new RegExp("/404/?$")
88+
if (regexp.test(localePage.path)) {
8889
localePage.matchPath = `/${language}/*`
8990
}
9091
createPage(localePage)

src/link.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ export const changeLocale = (language, to) => {
5555
}
5656
const { routed } = window.___gatsbyIntl
5757

58+
const removePrefix = pathname => {
59+
const base =
60+
typeof __BASE_PATH__ !== `undefined` ? __BASE_PATH__ : __PATH_PREFIX__
61+
if (base && pathname.indexOf(base) === 0) {
62+
pathname = pathname.slice(base.length)
63+
}
64+
return pathname
65+
}
66+
5867
const removeLocalePart = pathname => {
5968
if (!routed) {
6069
return pathname
@@ -63,7 +72,8 @@ export const changeLocale = (language, to) => {
6372
return pathname.substring(i)
6473
}
6574

66-
const pathname = to || removeLocalePart(window.location.pathname)
75+
const pathname =
76+
to || removeLocalePart(removePrefix(window.location.pathname))
6777
// TODO: check slash
6878
const link = `/${language}${pathname}${window.location.search}`
6979
localStorage.setItem("gatsby-intl-language", language)

src/wrap-page.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default ({ element, props }) => {
4343

4444
const { pageContext, location } = props
4545
const { intl } = pageContext
46-
const { language, languages, redirect, routed } = intl
46+
const { language, languages, redirect, routed, originalPath } = intl
4747

4848
if (typeof window !== "undefined") {
4949
window.___gatsbyIntl = intl
@@ -52,7 +52,7 @@ export default ({ element, props }) => {
5252
const isRedirect = redirect && !routed
5353

5454
if (isRedirect) {
55-
const { pathname, search } = location
55+
const { search } = location
5656

5757
// Skip build, Browsers only
5858
if (typeof window !== "undefined") {
@@ -68,7 +68,7 @@ export default ({ element, props }) => {
6868
}
6969

7070
const queryParams = search || ""
71-
const newUrl = withPrefix(`/${detected}${pathname}${queryParams}`)
71+
const newUrl = withPrefix(`/${detected}${originalPath}${queryParams}`)
7272
window.localStorage.setItem("gatsby-intl-language", detected)
7373
window.location.replace(newUrl)
7474
}

0 commit comments

Comments
 (0)