我有timeago.js插件,这需要一些文件的地区。但您不能一次添加所有内容。它应该是相对当前的区域设置。所以我需要一些像switch或if条件这样的东西来添加资源。我试过了,但不起作用。
<script th:if="${#locale == 'az_AZ'}" th:src="@{/resources/jquery/js/jquery.timeago.az.js}" type="text/javascript"></script>
<script th:if="${#locale == 'ru_RU'}" th:src="@{/resources/jquery/js/jquery.timeago.ru.js}" type="text/javascript"></script>发布于 2020-10-01 22:11:32
我建议使用#locale.language只获取上下文语言环境的语言部分-特别是因为JS文件名需要匹配语言部分。
所以,就像这样:
<script th:inline="javascript"
th:if="${#locale.language == 'en'}"
th:src="@{/resources/jquery/js/jquery.timeago.en.js}"
type="text/javascript"></script>
<script th:inline="javascript"
th:if="${#locale.language == 'ru'}"
th:src="@{/resources/jquery/js/jquery.timeago.ru.js}"
type="text/javascript"></script>但是您可以更进一步,通过在您的src #locale.language中直接使用该URL值来简化此过程:
<script th:inline="javascript"
th:src="@{/resources/jquery/js/jquery.timeago.{lang}.js(lang=${#locale.language})}"
type="text/javascript"></script>现在,不需要使用任何th:if语句,并且只需要一个<script>标记,而不是可能有一长串标记。
https://stackoverflow.com/questions/64156655
复制相似问题