JSS GraphQL辞書サービスで辞書データを取得

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

GraphQLとJSSGraphQLDictionaryServiceを使ってSitecoreから辞書データを取得できます。 

!注この例は、アプリケーションのルートディレクトリにファイルを作成し、同じディレクトリにconfig.jsファイルがあることを前提としています。プロジェクトのセットアップに合わせてインポート文を調整してください。

JSS GraphQL辞書サービスで辞書データを取得するには:

  1. dictionary-service.tsファイルで、GraphQLDictionaryServiceのインスタンスを作成・設定します:

    import {GraphQLDictionaryService} from '@sitecore-jss/sitecore-jss'; import config from './config';

    export const dictionaryService = new GraphQLDictionaryService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, siteName: config.jssAppName, /* The Dictionary Service needs a root item ID to fetch dictionary phrases for the current app. If your Sitecore instance only has 1 JSS App, you can specify the root item ID here; otherwise, the service will attempt to figure out the root item for the current JSS App using GraphQL and app name. rootItemId: '{GUID}' */ });

  2. データを取得したいファイルで、新しい辞書サービスインスタンスをインポートして使用してください:

    import { dictionaryService } from './dictionary-service'; const language = 'en'; dictionaryService.fetchDictionaryData(language).then(data => { // do something with the data });

この記事を改善するための提案がある場合は、 お知らせください!