bestit/contentful-translation-bundle

用于从contentful加载信息的翻译包

0.1.0 2017-11-16 19:47 UTC

This package is auto-updated.

Last update: 2024-08-29 04:41:30 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

用于从contentful加载信息的翻译包

步骤 1: 下载包

打开命令控制台,进入您的项目目录并执行以下命令以下载此包的最新稳定版本

$ composer require bestit/contentful-translation-bundle

此命令需要您全局安装了Composer,请参考Composer文档中的安装章节

步骤 2: 启用包

然后,将包添加到项目app/AppKernel.php文件中注册的包列表中,以启用该包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new BestIt\ContentfulTranslationBundle\BestItContentfulTranslationBundle(),
        );

        // ...
    }

    // ...
}

步骤 3: 配置包

简单配置。以下是一个yaml示例

# config.yml

best_it_contentful_translation:

    # Contentful client service ... expect an Client from offical contentful sdk
    contentful_client_id: 'contentful.delivery.translation_client'                      # Required
    
    # Contentful mapping (all optional)
    contentful_mapping:
    
            # Contentful content type id (default: translation)
            content_type: 'translation'
            
            # Contentful field id for the message key (default: translation_key)
            translation_key: 'translation_key'
            
            # Contentful field id for the message value (default: translation_value)
            translation_value: 'translation_value'
            
            # Contentful field id for the message domain (default: translation_domain)
            translation_domain: 'translation_domain'

步骤 4: 配置contentful

您需要在contentful空间中有一个翻译内容类型。只需创建一个,并在您的配置映射中设置字段id(见上方)。内容类型需要三个字段:key、value和domain。您可以使用本地化字段作为value。

以下是一个json示例配置

{
  "name": "Übersetzung",
  "description": "",
  "displayField": "translation_key",
  "fields": [
    {
      "id": "translation_key",
      "name": "Schlüssel",
      "type": "Symbol",
      "localized": false,
      "required": true,
      "validations": [
        {
          "unique": true
        }
      ],
      "disabled": false,
      "omitted": false
    },
    {
      "id": "translation_value",
      "name": "Text",
      "type": "Symbol",
      "localized": true,
      "required": false,
      "validations": [],
      "disabled": false,
      "omitted": false
    },
    {
      "id": "translation_domain",
      "name": "Domain",
      "type": "Symbol",
      "localized": false,
      "required": false,
      "validations": [],
      "disabled": false,
      "omitted": false
    }
  ],
  "sys": {
    //...
  }
}

步骤 5: 使用翻译

symfony翻译器期望一个翻译文件。因此,您必须创建一个'contentful'翻译文件 - 就像您已经通过yml、xml或xliff所知道的那样:/Resources/translations/messages.de.contentful

文件名定义了域名和区域设置,就像在Symfony中一样。文件内容可以保持为空 - 翻译通过contentful获取。

请注意,symfony缓存翻译。因此,在Contentful中进行更改后,您必须清除缓存。