首页 > 解决方案 > 如何使用 jed 翻译 yoast?

问题描述

我正在使用这个 Yoastnpm 包,按照自述文件,我能够使用该代码使其工作:

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());

有人可以帮助我对这个问题有所了解吗?谢谢

标签: javascriptlaravelnpmyoast

解决方案


推荐阅读