Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/js/bolt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Axios.defaults.headers.common = {
accept: 'application/vnd.api+json',
};

import './locale';
import './jquery';
import './codemirror';
import './filters';
Expand Down
16 changes: 16 additions & 0 deletions assets/js/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Settings } from 'luxon';

/*
** Make Luxon format dates (incl. relative ones like "7 days ago") in the locale of the Bolt admin UI,
** instead of the browser's locale. Bolt uses locale codes like 'pt_BR', while Intl expects 'pt-BR'.
** An invalid locale would make Luxon throw on every date it formats, so those keep the browser's locale.
*/
const locale = document.documentElement.lang.replace(/_/g, '-');

if (locale) {
try {
Settings.defaultLocale = Intl.getCanonicalLocales(locale)[0];
} catch {
// Keep the browser's locale
}
}
2 changes: 1 addition & 1 deletion templates/_base/layout.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{# Check if aside has value and set hasAside variable #}
{% set hasAside = block('aside')|trim is not empty ? true : false %}
<!DOCTYPE html>
<html lang="{{ app.user.locale|default() }}" {% if block('html_id') %}id="{% block html_id %}{% endblock %}"{% endif %}>
<html lang="{{ app.request.locale|default('')|replace({'_': '-'}) }}" {% if block('html_id') %}id="{% block html_id %}{% endblock %}"{% endif %}>

<head>
<meta charset="utf-8">
Expand Down
2 changes: 1 addition & 1 deletion templates/_macro/_macro.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@


{% macro relative_datetime(datetime) %}{% apply spaceless %}
<abbr class="datetime-relative" title="{{ datetime|localdate }}">
<abbr class="datetime-relative" title="{{ datetime|localdate(null, app.request.locale|default(null)) }}">
{{- datetime|date('c') -}}
</abbr>
{% endapply %}{% endmacro %}
Expand Down
2 changes: 1 addition & 1 deletion templates/_partials/fields/date.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
:errormessage='{{ errormessage|json_encode }}'
></editor-date>
{% else %}
{{ value|localdate(format|default(null), locale|default(null)) }}
{{ value|localdate(format|default(null), locale|default(app.request.locale|default(null))) }}
<small>({{ macro.relative_datetime(value) }})</small>
{% endif %}

Expand Down
Loading