javascript - 如何在 JavaScript 中获取 Laravel 的语言环境?

标签 javascript laravel internationalization translation

我正在用四种语言创建一个应用程序,每个网址如下所示:

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/

相关文章:

javascript - 有什么方法可以设置 HighCharts 热图数据的最小值和最大值吗?

javascript - 正则表达式删除 URL 中的所有特殊字符

php - Laravel 5.2 数据库 [xxx] 未配置,但在 database.php 中定义

java - 如何动态加载 GWT 主题

java - 如何在 spring 中加载 javascript i18n 属性文件?

javascript - 循环遍历包含对象的数组的数组,并在 JavaScript/Angular 中更新数组

javascript - jsonp 回调未从带有 PhoneGap 的 iPhone 模拟器触发

mysql - 数据库设计建议

laravel - curl 错误 60 : SSL certificate problem: unable to get local issuer certificate (see https://curl. haxx.se/libcurl/c/libcurl-errors.html)

gwt - 是否可以在 UIBinder XML 布局中使用参数化的 GWT 消息?