2017 © Pedro Peláez
 

library translatable

Translatable module for zend framework 3

image

vim/translatable

Translatable module for zend framework 3

  • Saturday, January 20, 2018
  • by vanvas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 1 Dependents
  • 3 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

translatable

Module for Zend Framework 3., (*1)

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org., (*2)

composer require vim/translatable

Register Vim\Translatable in config/modules.config.php:, (*3)

<?php
return [
    'Vim\Translatable',
];

Current Language

Get current language:

<?php
/** @var \Vim\Translatable\Service\CurrentLanguageService $currentLanguageService */
$currentLanguageService = $container->get(\Vim\Translatable\Service\CurrentLanguageService::class);
$currentLanguageService->get();

Language alias is taken from the locale (\Locale::getDefault())., (*4)

Set current language:

<?php
/** @var \Vim\Translatable\Service\CurrentLanguageService $currentLanguageService */
$currentLanguageService = $container->get(\Vim\Translatable\Service\CurrentLanguageService::class);
$currentLanguageService->set('en');

It is not recommended to use this method., (*5)

You can use initializer for \Vim\Translatable\Service\CurrentLanguageService.

To do this, register initializer in service manager config., (*6)

<?php
return [
    'service_manager' => [
        'initializers' => [
            \Vim\Translatable\ServiceManager\Initializer\Service\CurrentLanguageServiceInitializer::class,
        ],
    ],
];

Examples

Translatable Entity:

<?php
namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Selectable;
use Vim\Translatable\Entity\TranslatableEntityAbstract;

/**
 * @ORM\Table(name="article")
 * @ORM\Entity
 * @Vim\Translatable\Annotation\TranslatableEntityAnnotation(
 *     className="Application\Entity\ArticleTranslationEntity",
 * )
 * @param string $title
 */
class ArticleEntity extends TranslatableEntityAbstract
{
    /**
     * @var string
     * @ORM\Column(name="alias", type="string", nullable=false)
     */
    public $alias;

    /**
     * @var Collection|Selectable
     *
     * @ORM\OneToMany(
     *   targetEntity="ArticleTranslationEntity",
     *   mappedBy="object",
     *   cascade={"persist", "remove"}
     * )
     */
    public $translation;
}

Translation Entity:

<?php
namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;
use Vim\Translatable\Entity\TranslationEntityAbstract;

/**
 * @ORM\Entity
 * @ORM\Table(name="article_translation",
 *     uniqueConstraints={@ORM\UniqueConstraint(name="ux_article_translation_unique", columns={
 *         "language", "object_id"
 *     })}
 * )
 */
class ArticleTranslationEntity extends TranslationEntityAbstract
{
    /**
     * @var string
     * @ORM\Column(name="title", type="string", nullable=false)
     */
    public $title;

    /**
     * @var ArticleEntity
     * @ORM\ManyToOne(targetEntity="ArticleEntity", inversedBy="translation")
     * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
     */
    public $object;
}

The Versions

20/01 2018

dev-master

9999999-dev https://github.com/vanvas/translatable.git

Translatable module for zend framework 3

  Sources   Download

The Requires

 

language php zend framework translatable multilanguage zf2 module zf3 module

19/01 2018

1.0.0

1.0.0.0 https://github.com/vanvas/translatable.git

Translatable module for zend framework 3

  Sources   Download

The Requires

 

language php zend framework translatable multilanguage zf2 module zf3 module