我正在用四种语言创建一个应用程序,每个网址如下所示:
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
如何在 JavaScript 中得到这个?我需要翻译一些字符串,但我需要语言环境来知道选择哪种语言
最佳答案
如果您不想在脚本标签内使用 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>
关于javascript - 如何在 JavaScript 中获取 Laravel 的语言环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52702518/