JSS GraphQL Dictionary Serviceによる辞書データの取得

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

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

Sitecoreからディクショナリ データを取得するには、GraphQLとJSSのGraphQLDictionaryServiceを使用します。

メモ

この例では、アプリケーションのルートディレクトリにファイルを作成し、そのディレクトリにconfig.jsファイルがあることを前提としています。必要に応じてimportステートメントを調整し、プロジェクトの設定を反映させます。

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
    });
この記事を改善するための提案がある場合は、 お知らせください!