2017 © Pedro Peláez
 

propel-behavior i18n-helper-behavior

Helpful additions to default i18n propel behavior

image

c33s/i18n-helper-behavior

Helpful additions to default i18n propel behavior

  • Monday, February 27, 2017
  • by vworldat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 616 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

I18nHelperBehavior

Helpful additions to default i18n propel behavior, (*1)

Installation

Require c33s/i18n-helper-behavior in your composer.json file:, (*2)

{
    "require": {
        "c33s/i18n-helper-behavior": "@stable",
    }
}

Add propel behaviors to your propel config:, (*3)

# When using symfony:
# app/config/config.yml

propel:
    # ...

    behaviors:
        c33s_i18n_helper:   vendor.c33s.i18n-helper-behavior.src.C33sPropelBehaviorI18nHelper

Usage

Add behavior to your propel models - either globally (automatically for all models containing i18n behavior) or to a specific model:, (*4)



    <!-- use globally for all i18n models -->
    <behavior name="c33s_i18n_helper">
        <parameter name="default_locales" value="de, en" />
    </behavior>

    <table name="book">
        <behavior name="i18n">
            <!-- configure i18n as needed -->
            <parameter name="i18n_columns" value="title" />
            <parameter name="default_locale" value="de" />
        </behavior>

        <!-- use model-specific -->
        <behavior name="c33s_i18n_helper">
            <parameter name="default_locales" value="de, en" />
        </behavior>

        <column name="title" type="varchar" size="255" />

        <...>
    </table>

The behavior will add some convenience functions to your model. In the above example, the following methods will be generated for the i18n column title:, (*5)

<?php

use C33s\Behavior\I18nHelper\I18nModelInterface;

class BaseBook extends BaseObject implements Persistent, I18nModelInterface
{
    // ...

    // c33s_i18n_helper behavior

    /**
     * Get all available translations of the "Title" column.
     * This returns an associative array with locale => value pairs.
     *
     * @return array
     */
    public function getI18nTitle()
    {
        // ...
    }

    /**
     * Set translations of the "Title" column.
     * Accepts an associative array with locale => value pairs.
     *
     * @return Book
     */
    public function setI18nTitle($allTitles)
    {
        // ...
    }

    /**
     * Get i18n value of the "Title" column, using locale fallback (reverse default locales)
     * if the value is empty.
     * Starts with either the given locale or the current/default locale, set previously using getTranslation().
     *
     * @param string $locale
     *
     * @return mixed
     */
    public function getTitleWithFallback($locale = null)
    {
        // ...
    }

    /**
     * Set an array of default locales to use for the c33s_i18n_helper behavior (getI18n*(), get*WithFallback()).
     *
     * @param array $locales
     *
     * @return Book
     */
    public function setI18nDefaultLocales(array $locales)
    {
        // ...
    }

    /**
     * Get an array of default locales used by the c33s_i18n_helper behavior (getI18n*(), get*WithFallback()).
     *
     * @return array
     */
    public function getI18nDefaultLocales()
    {
        // ...
    }
}


In addition, all your i18n models will implement I18nModelInterface which is very helpful to recognize translatable objects whereever you have to., (*6)

The getI18n*() methods can be used with Symfony2 collection FormTypes (e.g. collection of text inputs), allowing you to edit all translations of a given field at once without any further code or configuration., (*7)

TODO:

  • forms example.
  • implement FormType guesser.

The Versions

27/02 2017

dev-master

9999999-dev https://github.com/vworldat/I18nHelperBehavior

Helpful additions to default i18n propel behavior

  Sources   Download

MIT

The Requires

 

27/02 2017

v0.2.0

0.2.0.0 https://github.com/vworldat/I18nHelperBehavior

Helpful additions to default i18n propel behavior

  Sources   Download

MIT

The Requires

 

11/02 2015

v0.1.0

0.1.0.0 https://github.com/vworldat/I18nHelperBehavior

Helpful additions to default i18n propel behavior

  Sources   Download

MIT

The Requires