javascript - 如何使用 jed 翻译 yoast?
问题描述
我正在使用这个 Yoast
npm 包,按照自述文件,我能够使用该代码使其工作:
import { AnalysisWebWorker } from "yoastseo";
const worker = new AnalysisWebWorker( self );
worker.register();
这用于生成有关内容的分数:
import { AnalysisWorkerWrapper, createWorker, Paper } from "yoastseo";
// `url` needs to be the full URL to the script for the browser to know where to load the worker script from.
// This should be the script created by the previous code-snippet.
const url = "https://my-site-url.com/path-to-webworker-script.js"
const worker = new AnalysisWorkerWrapper( createWorker( url ) );
worker.initialize( {
locale: "en_US",
contentAnalysisActive: true,
keywordAnalysisActive: true,
logLevel: "ERROR",
} ).then( () => {
// The worker has been configured, we can now analyze a Paper.
const paper = new Paper( "Text to analyze", {
keyword: "analyze",
} );
return worker.analyze( paper );
} ).then( ( results ) => {
console.log( 'Analysis results:' );
console.log( results );
} ).catch( ( error ) => {
console.error( 'An error occured while analyzing the text:' );
console.error( error );
} );
但我不明白如何更改语言环境italian
,我尝试将其更改locale
为:
locale: "it_IT",
或者:
locale: "it"
但生成的文本仍然是英文的。然后,我按照这个实现,看到有如下函数:
i18n() {
return new Jed({
domain: `js-text-analysis`,
locale_data: {
"js-text-analysis": { "": {} }
}
})
}
它被传递给以下对象:
const contentAssessor = new ContentAssessor(this.i18n());
const seoAssessor = new SEOAssessor(this.i18n());
有人可以帮助我对这个问题有所了解吗?谢谢
解决方案
推荐阅读
- google-bigquery - Dataproc 上 Spark 的 BigQuery 连接器 - 无法使用服务帐户密钥文件进行身份验证
- c# - 从列表中添加和删除时出现“索引超出范围”错误
- c++ - vcpkg 致命错误:即使文件存在,也找不到“muParser.h”文件
- django - Django: forms.ChoiceField, overriding forms __init__
- c++ - C++ how to wait for a method that gets executed on another thread then the main thread to finish (VS2010)
- node.js - 如何在猫鼬模式中使用唯一属性和加密?
- python - Use pandas pivot_table() to convert attribute-value pairs to table
- google-analytics - 谷歌标签管理器在同一个网站上触发了多个谷歌分析事件
- python - Extract classes from MNIST dataset
- javascript - 将 JSON 读取到 HTML 表中