Why is the token in my custom module not replaced? I want to use the token [user:name] in my module. This module contains a sample  ControllerBase class 

In my class I test this:

class Page_test_Controller extends ControllerBase {

    /**
     * {@inheritdoc}
     */
    public function token() {
        $build = array(
            '#type' =&gt; 'markup',
            '#markup' =&gt; t('[user:name] hello'),
        );
        return $build;
    }

}


When I load my page the token isn't replaced as shown here:



What am I missing or doing wrong?
Translatable strings don't use tokens, but placeholders, see for example https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Render%21FormattableMarkup.php/function/FormattableMarkup%3A%3AplaceholderFormat/8 for some documentation, or https://www.drupal.org/node/322729 (more 7.x, but conceptually still mostly OK).

Tokens are when you have user configurable text like the user register/confirmation mails. It doesn't make sense to have token in a text that is hardcoded since tokens are only useful if that text can be customized by the user. For documentation on how to use the token API, see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Utility%21Token.php/class/Token/8