Skip to content

Prepare field to receive i18n contributions #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const withNextra = require("nextra")({
});

module.exports = withNextra({
i18n: {
locales: ["en-US"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create i18n config file to use here and on theme

defaultLocale: "en-US",
},
redirects: () => {
return [
{
Expand Down
13 changes: 13 additions & 0 deletions pages/_middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextResponse } from "next/server";
import { locales } from "nextra/locales";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you don't use

import { withLocales } from 'nextra/locales'


export const middleware = (req) => {
const { nextUrl } = req;

// Playground component breaks when browsing to it.
// Since it's not a language dynamic page, we ignore
// the locales middleware and run with Next default one.
if (nextUrl.pathname === "/playground") return NextResponse.next();

return locales(req);
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions pages/playground/meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"index": {
"title": "Try SWC",
"type": "page",
"theme": {
"layout": "raw"
}
Expand Down
84 changes: 59 additions & 25 deletions theme.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { useRouter } from "next/router";

const TITLE_WITH_TRANSLATIONS = {
"en-US": "Rust-based platform for the Web",
};

const FEEDBACK_LINK_WITH_TRANSLATIONS = {
"en-US": "Question? Give us feedback →",
};

const Vercel = ({ height = 20 }) => (
<svg height={height} viewBox="0 0 283 64" fill="none">
<path
Expand All @@ -14,17 +24,30 @@ export default {
search: true,
unstable_flexsearch: true,
floatTOC: true,
logo: () => (
<>
<img src="/logo.png" width="50px" loading="lazy" />
<span className="mx-2 font-extrabold hidden md:inline select-none">
SWC
</span>
<span className="text-gray-600 font-normal hidden lg:!inline whitespace-no-wrap">
Speedy Web Compiler
</span>
</>
),
feedbackLink: () => {
const { locale } = useRouter();
return (
FEEDBACK_LINK_WITH_TRANSLATIONS[locale] ||
FEEDBACK_LINK_WITH_TRANSLATIONS["en-US"]
);
},
logo: () => {
const { locale } = useRouter();
return (
<>
<img src="/logo.png" width="50px" loading="lazy" />
<span className="mx-2 font-extrabold hidden md:inline select-none">
SWC
</span>
<span
className="text-gray-600 font-normal hidden lg:!inline whitespace-no-wrap"
title={`${TITLE_WITH_TRANSLATIONS[locale] || ""}`}
>
Speedy Web Compiler
</span>
</>
);
},
head: ({ title, meta }) => {
return (
<>
Expand Down Expand Up @@ -100,18 +123,29 @@ export default {
</>
);
},
footerEditLink: "Edit this page on GitHub",
footerText: () => (
<a
href="https://vercel.com/?utm_source=swc"
target="_blank"
rel="noopener"
className="inline-flex items-center no-underline text-current font-semibold"
>
<span className="mr-1">Powered by</span>
<span>
<Vercel />
</span>
</a>
),
footerEditLink: ({ locale }) => {
switch (locale) {
default:
return "Edit this page on GitHub →";
}
},
footerText: ({ locale }) => {
switch (locale) {
default:
return (
<a
href="https://vercel.com/?utm_source=swc"
target="_blank"
rel="noopener"
className="inline-flex items-center no-underline text-current font-semibold"
>
<span className="mr-1">Powered by</span>
<span>
<Vercel />
</span>
</a>
);
}
},
i18n: [{ locale: "en-US", text: "English" }],
};