- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将多语言添加到 this gatsbyjs template使用 gatsby-plugin-intl .
字段级翻译:由可翻译标记的每个字段都将有一个翻译,并且所有翻译都有一个内容项。
多树翻译:每个翻译都有自己的内容项,翻译保存在不同的文件夹中。pages
中的页面文件夹使用字段级翻译并按应有的方式完全工作。 content
中的页面文件夹使用使用 Markdown 文件的多树翻译,但不能完全按预期/应该工作。他们的路由已关闭。
基本上我想让这些页面遵循这个路由:
/en/mypage/
应该给英文版/ko/mypage/
应该给韩文版/en/mypage/en/
和 /ko/mypage/en/
给英文版/en/mypage/ko/
和 /ko/mypage/ko/
给韩文版amsterdamfurniturelab.nl/en/bear-desk/en
变成
amsterdamfurniturelab.nl/nl/bear-desk/en
但不显示 nl 翻译。
最佳答案
gatsby-plugin-intl
仅支持字段级翻译,通过 Context 传递 JSON 翻译键。
来自 the plugin's README :
you don't have to create separate pages such as
pages/en/index.js
orpages/ko/index.js
[...] the plugin will create static pages for every language
/bear-desk/
页面,您将获得:
"/en/bear-desk/" <-- EN locale
"/nl/bear-desk/" <-- NL locale
"/bear-desk/" <-- default: either redirects or renders the default locale based on plugin settings
在您提供的 repo 中,您同时使用了
gatsby-plugin-intl
和使用两个单独页面的“手动”翻译。
/bear-desk/en/
和
/bear-desk/nl/
插件将其视为两个不同的页面,您实际上为每个 slug 生成 6 个页面:
For your /bear-desk/en/ page (no JSON translations found, all will be in EN)
"/en/bear-desk/en/"
"/nl/bear-desk/en/"
"/bear-desk/en/"
For your /bear-desk/nl/ page (no JSON translations found, all will be in NL)
"/en/bear-desk/nl/"
"/nl/bear-desk/nl/"
"/bear-desk/nl/"
如果你想改变这种行为,你可以使用 Gatsby 的
createPage
手动创建页面。
gatsby-node.js
中的 API并确保您在正确的 URL 上创建正确的页面。
onCreatePage
中创建正确的 URL。接口(interface):
/*
here's what we want to do:
- for /nl/<slug>/nl/ create both /<slug>/ and /nl/<slug>/
- for /en/<slug>/en/ create /en/<slug>/
- for the rest of pages including <slug>, delete
*/
// note: optimally you would grab slugs from the fs or via graphql
const slugs = ["bear-desk", "cnc-explained"]
exports.onCreatePage = async ({
page,
actions: { createPage, deletePage },
}) => {
slugs.forEach(slug => {
if (page.path === `/nl/${slug}/nl/`) {
// create page in the default language (NL) at /slug
const defaultPage = { ...page, path: `/${slug}/` }
createPage(defaultPage)
console.log(`Created default page in NL at ${defaultPage.path}`)
// create a page for /nl/slug
const nlPage = { ...page, path: `/nl/${slug}/` }
createPage(nlPage)
console.log(`Created NL page at ${nlPage.path}`)
// delete the page with duplicate locale
deletePage(page)
console.log(`Deleted ${page.path}`)
}
else if (page.path === `/en/${slug}/en/`) {
// create a page for /en/slug
const enPage = { ...page, path: `/en/${slug}/` }
createPage(enPage)
console.log(`Created EN page at ${enPage.path}`)
// delete the page with duplicate locale
deletePage(page)
console.log(`Deleted ${page.path}`)
}
else if (page.path.includes(slug)) {
// delete all other pages with that slug
deletePage(page)
console.log(`Deleted ${page.path}`)
}
})
}
你会得到你想要的路线:
"/en/<slug>/" <-- EN locale
"/nl/<slug>/" <-- NL locale
"/<slug>/" <-- default (NL locale in your case)
虽然这会在正确的路径上创建正确的页面,但有一个主要限制:
gatsby-plugin-intl
不知道。这意味着您需要手动实现语言切换和链接到正确的语言环境。
关于javascript - 使用 gatsby-plugin-intl 调整 slug/路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60691650/
我添加了模块 Ember 国际在我的应用程序中,因为 Ember -i18n 已弃用。 所以 yarn 运行良好,更新 package.json 和 yarn.lock(我摆脱了 package.lo
我检查了这个来源 https://formatjs.io/docs/react-intl#runtime-requirements , 并尝试添加此代码 import { NumberFormat }
我正在尝试使用 react-intl 进行语言翻译。当我使用这个时,它运行完美。但是当我将以下代码与 intl.formatMessage() 一起使用时,它不起作用并抛出一些错误。我不知道这有什么问
我正在使用 React-intl 来实现 UI Util 库的国际化。该库有一个名为 i18n 的文件夹,其中我放置了不同区域设置的 json 文件。如果该库的用户想要添加对其他区域设置的支持,他/她
我正在使用 React-intl 来实现 UI Util 库的国际化。该库有一个名为 i18n 的文件夹,其中我放置了不同区域设置的 json 文件。如果该库的用户想要添加对其他区域设置的支持,他/她
嗨,我最近尝试使用日期选择器进行 flutter ,但我没有找到任何文档或教程,所以我打开 flutter 画廊项目并尝试复制代码。按照我导入“package:intl/intl.dart”库的代码。
我在一个大型 React 项目中使用 React Intl 的 FormattedNumber,该项目具有多种不同语言的功能。 这是我制作的货币组件,以便我可以轻松地将格式化的货币插入到我的 View
目前正在使用中 babel-plugin-react-intl , 使用“id”、“description”和“defaultMessage”为每个组件创建单独的 json。我需要的是只创建一个 js
我有一个 monorepo,它公开了一个 TypeScript 模块,该模块由 React TypeScript 项目使用和使用。 当模块将任意 React 元素插入到虚拟 DOM 中时 - 一切都按
我正在尝试在我全新安装的 OS X 10.6.6 上安装 PHP 扩展 intl,使用它附带的 PHP 版本 (v5.3.3)。 我知道扩展需要 ICU,所以我用自制软件安装了它。我安装的 ICU 版
因为每个版本flutter_localizations来自 SDK 取决于 intl 0.17.0而 fstore 依赖于 intl ^0.16.1 , 禁止来自 SDK 的 flutter_loca
我想使用package:intl制作多国语言html页面。 我看过example / basic_example.dart,但找不到intl_helpers的message_lookup_by_lib
我有数据列表,我想从最早到最晚过滤它们 包含数据的列表如下所示: [{id: 73, startTime: 2022-12-13T15:30:57.244Z}, {id: 74, startTime:
我有数据列表,我想从最早到最晚过滤它们 包含数据的列表如下所示: [{id: 73, startTime: 2022-12-13T15:30:57.244Z}, {id: 74, startTime:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-2
我正在使用 PHP Intl 库来格式化日期、数字等。现在我必须在人类可读的字符串中显示时间跨度,例如: 1day, 1hour, 10 minutes, 14s 或者以紧凑的方式: 1d 1s 10
我希望 Intl.NumberFormat() 能够根据通用规则自动将单位从较小的单位转换为较大的单位。 IE。给定的数字应根据数字的大小在输出中转换为厘米、米和公里。 代码示例: const byt
我想知道是否有办法让我使用 Javascript 的 Intl.NumberFormat()用它创造一个平方米的值(value)。 比如说,我想用它来创建一个具有该功能的值,如 30 m²。页面上或任
我从 WordPress Site Health 看到这条消息。如何安装缺少的模块? The WordPress Hosting Team maintains a list of those modu
我在 Centos 7 上使用 Virtualmin 作为控制面板,我需要安装 php intl 扩展才能使用 prestashop。 我用了这个命令 yum --enablerepo=remi in
我是一名优秀的程序员,十分优秀!