Signal-desktop: Support locale settings other than top-level $LANG (LC_TIME and specific locales)

Created on 22 Apr 2019  路  3Comments  路  Source: signalapp/Signal-Desktop

Signal-Desktop version 1.24.1 on Fedora 29

For some reason signal-desktop does not adhere to locale settings
on Linux. For example:

export LANG=en_US.utf8
export LC_TIME=de_DE.utf8
signal-desktop &

Expectation is to have an English UI, but message timestamps printed as "16:34".
Signal prints timestamps as "4:34 PM".

Worse, signal-desktop apparently also ignores certain settings even
for the $LANG locale:

export LANG=en_NG.utf8
signal-desktop &

Expectation is to have an English UI, but message timestamps printed as "16:34"
Signal prints timestamps as "4:34 PM".

The only way I found to switch the timestamp display is to switch to a non-English
locale like "de_DE.utf8" which is not desired.

[X] I have searched open and closed issues for duplicates
There's one related issue: https://github.com/signalapp/Signal-Desktop/issues/2938
but this one is not about the generic ability to use the host system's local settings.

Corinna

Feature Request

Most helpful comment

This patch fixes the system locale / LANG / LC_ALL element of this issue and improves the output of formatRelativeTime() in situations where there are country-specific overrides for languages.

For example, en_UK, en_IE and en_IL on macos default to using a 24h clock but en defaults to 12h due to en_US inheritance; Saudi Arabia ar_sa uses arabic numerals but other arabian locales like ar_kw use roman numerals; there are some text differences between pt_BR and pt_PT, etc, etc.

I haven't submitted as a pull request because tslint complains about statically requiring os-locale, which has no module declaration file, so it can't be directly imported and I don't have enough js clue to know what the best way to work around this problem is. But the patch is available from nickhilliard@107826c (CLA signed).

It would be great if this could be fixed in signal. If you're in a part of the world which doesn't use AM/PM, it's jarring and a bit annoying to see it.

diff --git a/ts/util/formatRelativeTime.ts b/ts/util/formatRelativeTime.ts
index 9727414b..b44dfafc 100644
--- a/ts/util/formatRelativeTime.ts
+++ b/ts/util/formatRelativeTime.ts
@@ -1,5 +1,7 @@
 import moment from 'moment';
 import { LocalizerType } from '../types/Util';
+// tslint:disable-next-line no-require-imports no-var-requires
+const osLocale = require('os-locale');

 // Only applies in the english locales, but it ensures that the format
 //   is what we want.
@@ -42,6 +44,7 @@ export function formatRelativeTime(
   const timestamp = moment(rawTimestamp);
   const now = moment();
   const diff = moment.duration(now.diff(timestamp));
+  moment.locale(osLocale.sync().replace(/_/g, '-'));

   if (diff.years() >= 1 || !isYear(timestamp)) {
     return replaceSuffix(timestamp.format(formats.y));

All 3 comments

As you've discovered, we have just one setting today - language. We don't keep track of true locales, like en_NG - we just extract the 'en' from that string and use that.

Date/time formats are usually defined by country, not by language. You can have multiple languages per country, but only one date/time format used. All supported OSes provide functions to get the date/time format of the current locale.

Corinna

This patch fixes the system locale / LANG / LC_ALL element of this issue and improves the output of formatRelativeTime() in situations where there are country-specific overrides for languages.

For example, en_UK, en_IE and en_IL on macos default to using a 24h clock but en defaults to 12h due to en_US inheritance; Saudi Arabia ar_sa uses arabic numerals but other arabian locales like ar_kw use roman numerals; there are some text differences between pt_BR and pt_PT, etc, etc.

I haven't submitted as a pull request because tslint complains about statically requiring os-locale, which has no module declaration file, so it can't be directly imported and I don't have enough js clue to know what the best way to work around this problem is. But the patch is available from nickhilliard@107826c (CLA signed).

It would be great if this could be fixed in signal. If you're in a part of the world which doesn't use AM/PM, it's jarring and a bit annoying to see it.

diff --git a/ts/util/formatRelativeTime.ts b/ts/util/formatRelativeTime.ts
index 9727414b..b44dfafc 100644
--- a/ts/util/formatRelativeTime.ts
+++ b/ts/util/formatRelativeTime.ts
@@ -1,5 +1,7 @@
 import moment from 'moment';
 import { LocalizerType } from '../types/Util';
+// tslint:disable-next-line no-require-imports no-var-requires
+const osLocale = require('os-locale');

 // Only applies in the english locales, but it ensures that the format
 //   is what we want.
@@ -42,6 +44,7 @@ export function formatRelativeTime(
   const timestamp = moment(rawTimestamp);
   const now = moment();
   const diff = moment.duration(now.diff(timestamp));
+  moment.locale(osLocale.sync().replace(/_/g, '-'));

   if (diff.years() >= 1 || !isYear(timestamp)) {
     return replaceSuffix(timestamp.format(formats.y));
Was this page helpful?
0 / 5 - 0 ratings