PHP,Wordpress - get_locale; require_once():需要打开失败

I would appreciate some help with an error I cannot get my head wrapped around...

I migrated a website from my localhost to a server, but now I have one problem with the language translation part.

The code:

<?php
    $locale =get_locale();
    echo $locale;
    $lang = require $_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/template  /lang/$locale.php';
?>

So I echoed the locale to find out if get_locale actually word and it does. it returns "en_US". In the path of require_once this file exists, but if I want to save the file it returns:

Error: require(): Failed opening required '/usr/home/removedusername/htdocs/wp-content /themes/template/lang/$locale.php' (include_path='.:/var/www/php55/lib/php')

While I thought, man the file path must have some problem, I exchanged the "$locale.php" to "en_US.php" and it doesn't show an error and the website actually works also fine just now of course I cannot switch the language anymore as I don't use a variable. Why the path with an included variable ($locale.php) does not work?

Probably a stupid mistake, but I would love some help.

Thank you in advance.

You're using single quotes around your string, so the variable isn't being substituted. Just replace the single quotes with double quotes.

"$_SERVER[DOCUMENT_ROOT]/wp-content/themes/template/lang/$locale.php"

Note for wordpress, get_template_directory, get_stylesheet_directory, get_theme_root, and plugin_dir_path are available for accessing the configured asset directories.