Tut*_*een 0 javascript translation internationalization laravel
我正在用四种语言创建一个应用程序,每个 url 都是这样的:
app.name/en/rest/of/the/url
app.name/de/rest/of/the/url
app.name/nl/rest/of/the/url
app.name/fr/rest/of/the/url
Run Code Online (Sandbox Code Playgroud)
我怎样才能在javascript中得到这个?我需要翻译一些字符串,但我需要语言环境才能知道选择哪个语言
小智 6
如果您不想在脚本标签中使用 PHP。你可以这样做
布局blade.php
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
Content of the document......
<script>
// Plain javascript
var locale = document.getElementsByTagName("html")[0].getAttribute("lang");
// jQuery
var localeJquery = $('html').attr('lang');
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 3
通过门面找到 laravel 中的位置
$locate = App::getLocale()
Run Code Online (Sandbox Code Playgroud)
通过辅助函数
config('app.locale')
Run Code Online (Sandbox Code Playgroud)
通过 JavaScript 添加
<script>
var locate = {!! config('app.locale') !!};
</script>
Run Code Online (Sandbox Code Playgroud)
有关定位的更多信息,请参阅