Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
intl(dates): use moment for timeAgo and timestamps
Browse files Browse the repository at this point in the history
This removes the internal timeAgo and uses moment's localized fromNow.  It also shows the tooltip timestamp localized as moment.format('LLLL zz') with the chosen language in the settings.  This branches off @ahdinosaurs prior art in #1206 and implements it across the codebase.  Also removes the human-time requirement.
  • Loading branch information
Andy Jacobs committed Dec 18, 2019
1 parent a9247e8 commit 8d972d2
Show file tree
Hide file tree
Showing 24 changed files with 10 additions and 337 deletions.
3 changes: 0 additions & 3 deletions lib/depject/index.js
Expand Up @@ -91,9 +91,6 @@ module.exports = {
sheet: require('./invite/sheet.js')
},
keys: require('./keys.js'),
lib: {
timeAgo: require('./lib/timeAgo.js')
},
message: {
async: {
name: require('./message/async/name.js'),
Expand Down
24 changes: 1 addition & 23 deletions lib/depject/intl/sync/i18n.js
Expand Up @@ -10,7 +10,6 @@ exports.gives = nest('intl.sync', [
'localeNames',
'i18n',
'i18n_n',
'time',
'startsWith'
])

Expand All @@ -33,8 +32,7 @@ exports.create = (api) => {
startsWith,
localeNames,
i18n,
i18n_n: i18nN,
time
i18n_n: i18nN
})

function startsWith (text, startsWith) {
Expand Down Expand Up @@ -71,26 +69,6 @@ exports.create = (api) => {
return i18nL.__n(value, ...opts)
}

function time (date) {
return date
.replace(/from now/, i18n('from now'))
.replace(/ago/, i18n('ago'))
.replace(/years/, i18n('years'))
.replace(/months/, i18n('months'))
.replace(/weeks/, i18n('weeks'))
.replace(/days/, i18n('days'))
.replace(/hours/, i18n('hours'))
.replace(/minutes/, i18n('minutes'))
.replace(/seconds/, i18n('seconds'))
.replace(/year/, i18n('year'))
.replace(/month/, i18n('month'))
.replace(/week/, i18n('week'))
.replace(/day/, i18n('day'))
.replace(/hour/, i18n('hour'))
.replace(/minute/, i18n('minute'))
.replace(/second/, i18n('second'))
}

// Init an subscribe to settings changes.
function _init () {
if (_locale) return
Expand Down
42 changes: 0 additions & 42 deletions lib/depject/lib/timeAgo.js

This file was deleted.

5 changes: 1 addition & 4 deletions lib/depject/message/html/render/gathering.js
Expand Up @@ -3,9 +3,6 @@ const nest = require('depnest')
const extend = require('xtend')
const moment = require('moment-timezone')

const localTimezone = moment.tz.guess()
moment.locale(navigator.languages)

exports.needs = nest({
'message.html.markdown': 'first',
'message.html.layout': 'first',
Expand Down Expand Up @@ -179,7 +176,7 @@ exports.create = function (api) {

function formatTime (time) {
if (time && time.epoch) {
return moment(time.epoch).tz(localTimezone).format('LLLL zz')
return moment(time.epoch).format('LLLL zz')
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/depject/message/html/timestamp.js
@@ -1,9 +1,9 @@
const h = require('mutant/h')
const nest = require('depnest')
const moment = require('moment-timezone')

exports.gives = nest('message.html.timestamp')
exports.needs = nest({
'lib.obs.timeAgo': 'first',
'message.sync.timestamp': 'first',
'message.sync.root': 'first'
})
Expand All @@ -15,7 +15,7 @@ exports.create = function (api) {
return h('a.Timestamp', {
href: api.message.sync.root(msg) || msg.key,
anchor: msg.key,
title: new Date(api.message.sync.timestamp(msg))
}, api.lib.obs.timeAgo(api.message.sync.timestamp(msg)))
title: moment(api.message.sync.timestamp(msg)).format('LLLL zz')
}, moment(api.message.sync.timestamp(msg)).fromNow())
}
}
5 changes: 5 additions & 0 deletions lib/main-window.js
Expand Up @@ -15,6 +15,10 @@ const watch = require('mutant/watch')
const requireStyle = require('require-style')
const ssbUri = require('ssb-uri')
const pull = require('pull-stream')
const moment = require('moment-timezone')

const localTimezone = moment.tz.guess()
moment.tz.setDefault(localTimezone)

module.exports = function (config) {
const sockets = combine(
Expand Down Expand Up @@ -50,6 +54,7 @@ module.exports = function (config) {

const i18n = api.intl.sync.i18n
const language = api.settings.obs.get('patchwork.lang', '')()
moment.locale(language)
setupContextMenuAndSpellCheck(api.config.sync.load(), { navigate, getMessageText, language })

const id = api.keys.sync.id()
Expand Down
16 changes: 0 additions & 16 deletions locales/de.json
Expand Up @@ -92,22 +92,6 @@
"Edit": "Bearbeiten",
"identified ": "bezeichnet ",
"self identifies as ": "bezeichnet sich selbst als ",
"from now": "von jetzt",
"ago": "her",
"years": "Jahre",
"months": "Monate",
"weeks": "Wochen",
"days": "Tage",
"hours": "Stunden",
"minutes": "Minuten",
"seconds": "Sekunden",
"year": "Jahr",
"month": "Monat",
"week": "Woche",
"day": "Tag",
"hour": "Stunde",
"minute": "Minute",
"second": "Sekunde",
"assigned a display image to ": "hat ein Bild zugewiesen ",
"Theme": "Theme",
"Language": "Sprache",
Expand Down
16 changes: 0 additions & 16 deletions locales/el.json
Expand Up @@ -66,22 +66,6 @@
"Self Assigned": "Self Assigned",
"Assigned By": "Εκχωρήθηκε από",
"followed ": "ακολουθείται από ",
"from now": "από τώρα",
"ago": "πριν",
"years": "χρόνια",
"months": "μήνες",
"weeks": "εβδομάδες",
"days": "ημέρες",
"hours": "ώρες",
"minutes": "λεπτά",
"seconds": "δευτερόλεπτα",
"year": "έτος",
"month": "μήνας",
"week": "εβδομάδα",
"day": "ημέρα",
"hour": "ώρα",
"minute": "λεπτό",
"second": "δευτερόλεπτο",
"Reply": "Απάντηση",
"View full thread": "Δείτε την πλήρη ανάρτηση",
"Unsubscribe": "Απεγγραφή",
Expand Down
16 changes: 0 additions & 16 deletions locales/en.json
Expand Up @@ -66,22 +66,6 @@
"Self Assigned": "Self Assigned",
"Assigned By": "Assigned By",
"followed ": "followed ",
"from now": "from now",
"ago": "ago",
"years": "years",
"months": "months",
"weeks": "weeks",
"days": "days",
"hours": "hours",
"minutes": "mins",
"seconds": "secs",
"year": "year",
"month": "month",
"week": "week",
"day": "day",
"hour": "hour",
"minute": "min",
"second": "sec",
"Reply": "Reply",
"View full thread": "View full thread",
"Unsubscribe": "Unsubscribe",
Expand Down
16 changes: 0 additions & 16 deletions locales/eo.json
Expand Up @@ -118,22 +118,6 @@
"Close": "Fermi",
"New Message": "Nova mesaĝo",
"Language": "Lingvo",
"from now": "de nun",
"ago": "antaŭ",
"years": "jaroj",
"months": "monatoj",
"weeks": "semajnoj",
"days": "tagoj",
"hours": "horoj",
"minutes": "minutoj",
"seconds": "sekundoj",
"year": "jaro",
"month": "monato",
"week": "semajno",
"day": "tago",
"hour": "horo",
"minute": "minuto",
"second": "sekundo",
"unsubscribed from ": "malabonis de ",
"en": "en",
"es": "es",
Expand Down
16 changes: 0 additions & 16 deletions locales/es.json
Expand Up @@ -105,22 +105,6 @@
"Close": "Cerrar",
"New Message": "Nuevo mensaje",
"Language": "Idioma",
"from now": "en el futuro",
"ago": "atras",
"years": "años",
"months": "meses",
"weeks": "semanas",
"days": "días",
"hours": "horas",
"minutes": "minutos",
"seconds": "segundos",
"year": "año",
"month": "mes",
"week": "semana",
"day": "día",
"hour": "hora",
"minute": "minutos",
"second": "segundos",
"unsubscribed from ": "desuscrito de ",
"en": "en",
"es": "es",
Expand Down
16 changes: 0 additions & 16 deletions locales/fr.json
Expand Up @@ -67,22 +67,6 @@
"Self Assigned": "Auto-assigné",
"Assigned By": "Assigné par",
"followed ": "suit ",
"from now": "from now",
"ago": "ago",
"years": "années",
"months": "mois",
"weeks": "semaines",
"days": "jours",
"hours": "heures",
"minutes": "minutes",
"seconds": "secondes",
"year": "année",
"month": "mois",
"week": "semaine",
"day": "jour",
"hour": "heure",
"minute": "min",
"second": "seconde",
"Reply": "Répondre",
"View full thread": "Afficher le fil complet",
"Unsubscribe": "Se désabonner",
Expand Down
16 changes: 0 additions & 16 deletions locales/pl.json
Expand Up @@ -60,22 +60,6 @@
"Self Assigned": "Samoprzypisane",
"Assigned By": "Przypisane przez",
"followed ": "zaobserwowała ",
"from now": "od teraz",
"ago": "temu",
"years": "lata",
"months": "miesiące",
"weeks": "tygodnie",
"days": "dni",
"hours": "godziny",
"minutes": "minuty",
"seconds": "sekundy",
"year": "rok",
"month": "miesiąc",
"week": "tydzień",
"day": "dzień",
"hour": "godzina",
"minute": "min",
"second": "sek",
"Reply": "Odpowiedz",
"View full thread": "Pokaż całą konwersację",
"Unsubscribe": "Odsubskrybuj",
Expand Down
16 changes: 0 additions & 16 deletions locales/pt-BR.json
Expand Up @@ -93,22 +93,6 @@
"Edit": "Editar",
"identified ": "identificou ",
"self identifies as ": "se identifica como ",
"from now": "a partir de agora",
"ago": "atrás",
"years": "anos",
"months": "meses",
"weeks": "semanas",
"days": "dias",
"hours": "horas",
"minutes": "minutos",
"seconds": "segundos",
"year": "ano",
"month": "mês",
"week": "semana",
"day": "dia",
"hour": "hora",
"minute": "minuto",
"second": "segundo",
"assigned a display image to ": "atribuiu uma imagem para ",
"Theme": "Tema",
"Language": "Língua",
Expand Down
16 changes: 0 additions & 16 deletions locales/pt.json
Expand Up @@ -94,22 +94,6 @@
"Edit": "Editar",
"identified ": "identificou ",
"self identifies as ": "auto identifica-se como ",
"from now": "no futuro",
"ago": "atrás",
"years": "anos",
"months": "meses",
"weeks": "semanas",
"days": "dias",
"hours": "horas",
"minutes": "minutos",
"seconds": "segundos",
"year": "ano",
"month": "mês",
"week": "semana",
"day": "dia",
"hour": "hora",
"minute": "minutos",
"second": "segundos",
"assigned a display image to ": "atribuíu uma imagem a ",
"Theme": "Tema",
"Language": "Idioma",
Expand Down
16 changes: 0 additions & 16 deletions locales/ru.json
Expand Up @@ -66,22 +66,6 @@
"Self Assigned": "Самоназначено",
"Assigned By": "Назначено",
"followed ": "следует ",
"from now": "отныне",
"ago": "назад",
"years": "годы",
"months": "месяцы",
"weeks": "недели",
"days": "дни",
"hours": "часы",
"minutes": "мин",
"seconds": "сек",
"year": "год",
"month": "месяц",
"week": "неделя",
"day": "день",
"hour": "час",
"minute": "мин",
"second": "сек",
"Reply": "Ответить",
"View full thread": "Просмотр полной темы",
"Unsubscribe": "Отписаться",
Expand Down

0 comments on commit 8d972d2

Please sign in to comment.