dev-master
9999999-devAn interface to allow simple translation of controller url segments and actions.
BSD-3-Clause
The Requires
- php >=5.5
- silverstripe/framework ^3.1
silverstripe translatable translatable controller
Wallogit.com
2017 © Pedro Peláez
An interface to allow simple translation of controller url segments and actions.
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)
"require": {
"php": "^5.4",
"silverstripe/framework": "^3.1"
}
composer install jjjjjjjjjjjjjjjjjjjj/silverstripe-translatable-controllers, (*2)
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: '関数の例'
An interface to allow simple translation of controller url segments and actions.
BSD-3-Clause
silverstripe translatable translatable controller