【发布时间】:2021-04-23 14:23:28
【问题描述】:
我正在开发一个使用 Tailwind CSS 进行样式设置的 Next.js 项目。我被困在next.config 文件中。
我几乎已经尝试了一切来使这段代码工作,但不能。
const withPlugins = require("next-compose-plugins");
const withImages = require("next-images");
const withSass = require("@zeit/next-sass");
const withCSS = require("@zeit/next-css");
const withFonts = require("next-fonts");
const webpack = require("webpack");
const path = require("path");
module.exports = withFonts(
withCSS(
withImages(
withSass({
webpack(config, options) {
config.module.rules.push({
test: /\.(eot|ttf|woff|woff2)$/,
use: {
loader: "url-loader",
},
});
config.resolve.modules.push(path.resolve("./"));
return config;
},
})
)
)
);
module.exports = {
i18n: {
locales: ['en', 'fr'],
defaultLocale: 'en',
},
}
我想知道如何将这两件事结合起来。
这是我正在使用的index.js 的代码。
import { useRouter } from 'next/router';
import fr from '../locales/fr';
import en from '../locales/en';
function sth () {
const router = useRouter();
const { locale } = router;
const t = locale === 'en' || 'undefined' ? en : fr;
console.log(locale);
return t;
}
export default function Index() {
const t = sth();
return (
<>
<IndexNavbar fixed />
<section className="header relative pt-16 items-center flex h-screen max-h-860-px">
<div className="container mx-auto items-center flex flex-wrap">
<div className="w-full md:w-8/12 lg:w-6/12 xl:w-6/12 px-4">
<div className="pt-32 sm:pt-0">
<h2 className="font-semibold text-4xl text-gray-700">
{t.homeMainTitle}
</h2>
</div>
</div>
</div>
</section>
</>
);}
sth() 函数的内容在Index() 内部,但无论如何都不起作用。
【问题讨论】:
标签: internationalization next.js tailwind-css i18next