Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to override datepicker's dateformat via locales #1830

Merged
merged 3 commits into from
Jul 28, 2021
Merged
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
2.0.1 (unreleased)
------------------


- #1830 Allow to override datepicker's dateformat via locales

2.0.0 (2021-07-26)
------------------
Expand Down
4 changes: 2 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[buildout]
index = https://pypi.org/simple/
extends = https://dist.plone.org/release/5.2.3/versions.cfg
extends = https://dist.plone.org/release/5.2.4/versions.cfg
find-links =
https://dist.plone.org/release/5.2.3/
https://dist.plone.org/release/5.2.4/
https://dist.plone.org/thirdparty/

parts =
Expand Down
5 changes: 4 additions & 1 deletion src/bika/lims/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def get_locale_format(key):
request = api.get_request()
format = translate(
key, domain="senaite.core", mapping={}, context=request)
# TODO: Is this replacement below strictly necessary?
# The variables at locales .po files (e.g. "date_format_short") take
# into consideration the translation service tool and therefore, their
# format is like "${d}/${m}/${Y}". We need to "convert" this format
# to %-like.
return format.replace(r"${", '%').replace('}', '')

# Try with prioritized formats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ document.addEventListener("DOMContentLoaded", () => {
var dt_fmt = _t(dt_fmt_string);

if (dt_fmt != dt_fmt_string) {
dt_fmt = dt_fmt.replaceAll(/[${}]/gi, "");
date_format = dt_fmt.replaceAll(/[${}]/gi, "");
}

var config = Object.assign(dt_config, tp_config);

$('[datepicker="1"]').datepicker(
Object.assign(config, {
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true,
yearRange: "-150:+150",
Expand Down