This snippet shows you how to show a title depending on your language.
mymodule.routing.yml:
mymodule.custom_page:
path: '/my-custom-page'
defaults:
_title_callback: '\Drupal\mymodule\Controller\customPageController::getTitle'
_controller: '\Drupal\mymodule\Controller\customPageController::render'
customPageController.php:
namespace Drupal\mymodule\Controller;
use Drupal\Core\Controller\ControllerBase;
class customPageController extends ControllerBase {
public static function render() {
}
/**
* Returns a page title.
*/
public function getTitle() {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
switch($language) {
case 'en':
$title = 'hello';
break;
case 'fr':
$title = 'salut';
break;
}
return $title;
}
}