2017 © Pedro Peláez
 

silverstripe-module silverstripe-translatable-controllers

An interface to allow simple translation of controller url segments and actions.

image

janneklouman/silverstripe-translatable-controllers

An interface to allow simple translation of controller url segments and actions.

  • Tuesday, May 8, 2018
  • by janneklouman
  • Repository
  • 1 Watchers
  • 2 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SilverStripe Translatable Controllers

This module provides a simple interface that allows you to set up multiple routes to your controllers and their actions. The most common use case would probably be translating these routes., (*1)

Requirements

"require": {
    "php": "^5.4",
    "silverstripe/framework": "^3.1"
}

Installation

composer install jjjjjjjjjjjjjjjjjjjj/silverstripe-translatable-controllers, (*2)

Basic usage example

The following example provides a simple controller (ExampleController) with one function (example_function), available from: * example.com/ExampleController/example_function * example.com/example_example/function_function * example.com/exempelcontroller/exempelfunktion (when the locale is Swedish) * example.com/コントローラーの例/関数の例 (when the locale is Japanese), (*3)

Make your controller implement the TranslatableController interface:, (*4)

# ExampleController.php
class ExampleController extends Controller implements TranslatableController
{

    private static $allowed_actions = [
        'example_function'
    ];

    public function getValidUrlSegments()
    {
        return [
            'example_example',
            _t('ExampleController.CONTROLLER_URL_SEGMENT')
        ];
    }

    public function getValidUrlHandlers()
    {
        return [
            'function_function' => 'example_function',
            _t('ExampleController.CONTROLLER_ACTION_EXAMPLE') => 'example_function'
        ]
    }

    /**
     * Returns the number 42
     */
    public function example_function
    {
        return 42;
    }

}

Define your routes in the translation file for the target language(s):, (*5)

# sv_SE.yml
sv:
  ExampleController:
    CONTROLLER_URL_SEGMENT: 'exempelcontroller'
    CONTROLLER_ACTION_EXAMPLE: 'exempelfunktion'
# ja_JP.yml
ja:
  ExampleController:
    CONTROLLER_URL_SEGMENT: 'コントローラーの例'
    CONTROLLER_ACTION_EXAMPLE: '関数の例'

The Versions

08/05 2018

dev-master

9999999-dev

An interface to allow simple translation of controller url segments and actions.

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe translatable translatable controller