Skip to content

Commit

Permalink
use gettext for date to date (#130)
Browse files Browse the repository at this point in the history
and tweak fr_CA ordinals

CPNHUB-79
  • Loading branch information
petrjasek committed Apr 28, 2022
1 parent bd33944 commit a894c7a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 40 deletions.
20 changes: 13 additions & 7 deletions assets/agenda/components/AgendaMetaTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import classNames from 'classnames';

import AgendaItemTimeUpdater from './AgendaItemTimeUpdater';
import {bem} from 'ui/utils';
import {formatTime, formatDate, DATE_FORMAT, gettext, getScheduleType} from 'utils';
import {formatTime, formatDate, DATE_FORMAT, gettext, getScheduleType, formatDatetime} from 'utils';
import {hasCoverages, isCoverageForExtraDay, SCHEDULE_TYPE, isItemTBC, TO_BE_CONFIRMED_TEXT} from '../utils';

function format(item, group, onlyDates) {
Expand Down Expand Up @@ -62,14 +62,20 @@ function format(item, group, onlyDates) {
switch(scheduleType) {
case SCHEDULE_TYPE.MULTI_DAY:
return isTBCItem ? ([
<span key="start">{dateElement(start)}{tbcStr}</span>,
<span key="dash" className='ml-2 mr-2'>{(gettext('to'))}</span>,
<span key="end">{dateElement(end)}{tbcStr}</span>
<span key="date">
{gettext('{{startDate}} to {{endDate}}', {
startDate: formatDate(start) + tbcStr,
endDate: formatDate(end) + tbcStr,
})}
</span>,
]) :
([
<span key="start">{timeElement(start)}{dateElement(start)}</span>,
<span key="dash" className='ml-2 mr-2'>{(gettext('to'))}</span>,
<span key="end">{timeElement(end)}{dateElement(end)}</span>
<span key="date">
{gettext('{{startDate}} to {{endDate}}', {
startDate: formatDatetime(start),
endDate: formatDatetime(end),
})}
</span>,
]);

case SCHEDULE_TYPE.ALL_DAY:
Expand Down
27 changes: 21 additions & 6 deletions assets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import 'moment/locale/fi';
import 'moment/locale/cs';

moment.locale(getLocale());
window.moment = moment;

// CP don't want 2e 3e etc., only 1er
moment.updateLocale('fr-ca', {ordinal: (number) => number + (number === 1 ? 'er' : '')});

export const now = moment(); // to enable mocking in tests
const NEWSROOM = 'newsroom';
Expand Down Expand Up @@ -287,6 +291,16 @@ export function formatDate(dateString) {
return parseDate(dateString).format(DATE_FORMAT);
}

/**
* Format date with time
*
* @param {String} dateString
* @return {String}
*/
export function formatDatetime(dateString) {
return fullDate(dateString);
}

/**
* Parse the given date string, setting the time to 23:59:59 (i.e. end of the day).
* Ensures that the datetime is for the end of the day in the provided timezone
Expand Down Expand Up @@ -384,7 +398,10 @@ export function formatAgendaDate(item, group, localTimeZone = true) {
}

const scheduleType = getScheduleType(item);
let regulartTimeStr = `${formatTime(start)} - ${formatTime(end)} `;
let regulartTimeStr = gettext('{{startTime}} - {{endTime}}', {
startTime: formatTime(start),
endTime: formatTime(end),
});
if (isTBCItem) {
regulartTimeStr = localTimeZone ? `${TO_BE_CONFIRMED_TEXT} ` : '';
}
Expand All @@ -399,11 +416,9 @@ export function formatAgendaDate(item, group, localTimeZone = true) {
endDate: formatDate(end),
}));
} else {
dateTimeString.push(gettext('{{startTime}} {{startDate}} to {{endTime}} {{endDate}}', {
startTime: formatTime(start),
startDate: formatDate(start),
endTime: formatTime(end),
endDate: formatDate(end),
dateTimeString.push(gettext('{{startDate}} to {{endDate}}', {
startDate: formatDatetime(start),
endDate: formatDatetime(end),
}));
}
break;
Expand Down
36 changes: 20 additions & 16 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Newsroom-Core 2.1.0.dev0\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-04-27 08:27+0200\n"
"POT-Creation-Date: 2022-04-27 16:27+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -639,7 +639,7 @@ msgstr ""
#: assets/agenda/components/AgendaAttachments.jsx:42
#: assets/company-reports/components/ContentActivity.jsx:62
#: assets/company-reports/components/ContentActivity.jsx:117
#: assets/item-actions.js:49 assets/ui/components/ArticleVideo.jsx:16
#: assets/item-actions.js:49 assets/ui/components/ArticleMedia.jsx:28
#: assets/wire/components/DownloadItemsModal.jsx:53
#: newsroom/reports/content_activity.py:237
msgid "Download"
Expand Down Expand Up @@ -1266,15 +1266,17 @@ msgstr ""
msgid "New card"
msgstr ""

#: assets/utils.js:400
msgid "{{startDate}} to {{endDate}}"
#: assets/utils.js:404
msgid "{{startTime}} - {{endTime}}"
msgstr ""

#: assets/utils.js:407
msgid "{{startTime}} {{startDate}} to {{endTime}} {{endDate}}"
#: assets/agenda/components/AgendaMetaTime.jsx:68
#: assets/agenda/components/AgendaMetaTime.jsx:76 assets/utils.js:417
#: assets/utils.js:422
msgid "{{startDate}} to {{endDate}}"
msgstr ""

#: assets/utils.js:633
#: assets/utils.js:648
msgid "Failed to process request!"
msgstr ""

Expand Down Expand Up @@ -1669,12 +1671,6 @@ msgstr ""
msgid "event completed"
msgstr ""

#: assets/agenda/components/AgendaMetaTime.jsx:66
#: assets/agenda/components/AgendaMetaTime.jsx:71
#: assets/components/cards/render/EventsTwoByTwoCard.jsx:33
msgid "to"
msgstr ""

#: assets/agenda/components/AgendaPreviewCoverages.jsx:27
msgid "Previous Coverages"
msgstr ""
Expand Down Expand Up @@ -2380,6 +2376,10 @@ msgstr ""
msgid "all"
msgstr ""

#: assets/components/cards/render/EventsTwoByTwoCard.jsx:33
msgid "to"
msgstr ""

#: assets/components/cards/render/MoreNewsButton.jsx:12
msgid "More news"
msgstr ""
Expand Down Expand Up @@ -3123,8 +3123,12 @@ msgstr ""
msgid "Embargo: {{ date }}"
msgstr ""

#: assets/ui/components/ArticleVideo.jsx:12
msgid "Your browser does not support HTML5 video"
#: assets/ui/components/ArticleMedia.jsx:17
msgid "Your browser does not support playing video"
msgstr ""

#: assets/ui/components/ArticleMedia.jsx:23
msgid "Your browser does not support playing audio"
msgstr ""

#: assets/ui/components/Content.jsx:7 assets/ui/components/Content.jsx:8
Expand All @@ -3140,7 +3144,7 @@ msgid "Article preview"
msgstr ""

#: assets/ui/components/Preview.jsx:13
#: assets/wire/components/ItemDetails.jsx:83
#: assets/wire/components/ItemDetails.jsx:82
msgid "Published on {{ date }} at {{ time }}"
msgstr ""

Expand Down
Binary file modified newsroom/translations/fr_CA/LC_MESSAGES/messages.mo
Binary file not shown.
30 changes: 19 additions & 11 deletions newsroom/translations/fr_CA/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
# Gideon Lehmann <gideon.lehmann@sourcefabric.org>, 2022
# Evzen Deulin <evgeny.deulin@sourcefabric.org>, 2022
# Simon Peacock <simon.peacock@gmail.com>, 2022
# Petr Jašek <petr.jasek@sourcefabric.org>, 2022
# Marie-Eve Ouellette <marie-eve.ouellette@lapressecanadienne.com>, 2022
# Charles-Philippe Giroux <charles-philippe.giroux@lapressecanadienne.com>, 2022
# Petr Jašek <petr.jasek@sourcefabric.org>, 2022
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Newsroom-Core 2.1.0.dev0\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-04-25 14:10+0200\n"
"POT-Creation-Date: 2022-04-27 08:27+0200\n"
"PO-Revision-Date: 2019-11-27 15:02+0000\n"
"Last-Translator: Charles-Philippe Giroux <charles-philippe.giroux@lapressecanadienne.com>, 2022\n"
"Last-Translator: Petr Jašek <petr.jasek@sourcefabric.org>, 2022\n"
"Language-Team: French (Canada) (https://www.transifex.com/sourcefabric/teams/6584/fr_CA/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -1315,7 +1315,15 @@ msgstr "Nouveau filtre de section"
msgid "New card"
msgstr "Nouvelle fiche"

#: assets/utils.js:625
#: assets/utils.js:400
msgid "{{startDate}} to {{endDate}}"
msgstr "de {{startDate}} à {{endDate}}"

#: assets/utils.js:407
msgid "{{startTime}} {{startDate}} to {{endTime}} {{endDate}}"
msgstr "{{startTime}} {{startDate}} à {{endTime}} {{endDate}}"

#: assets/utils.js:633
msgid "Failed to process request!"
msgstr "La requête n'a pas pu être traitée!"

Expand Down Expand Up @@ -1936,7 +1944,7 @@ msgstr "Finlande"

#: assets/companies/components/Companies.jsx:37
msgid "Please provide company name"
msgstr ""
msgstr "Veuillez fournir le nom de l'entreprise"

#: assets/companies/components/Companies.jsx:60
msgid "Would you like to delete company: {{name}}"
Expand Down Expand Up @@ -2678,7 +2686,7 @@ msgstr "Images de la tuile"

#: assets/navigations/components/Navigations.jsx:41
msgid "Please provide navigation name"
msgstr ""
msgstr "Veuillez fournir le nom de la navigation"

#: assets/navigations/components/Navigations.jsx:62
msgid "Would you like to delete navigation: {{name}}"
Expand Down Expand Up @@ -2853,7 +2861,7 @@ msgid ""
"again."
msgstr ""
"Assurez-vous de copier votre nouveau client secret maintenant, car vous ne "
"serez plus en mesure de le voir."
"serez plus en mesure de le voir une autre fois."

#: assets/products/actions.js:92 assets/products/actions.js:147
#: assets/products/actions.js:177
Expand Down Expand Up @@ -2903,7 +2911,7 @@ msgstr "Tester la requête d'élément de couverture"

#: assets/products/components/Products.jsx:45
msgid "Please provide product name"
msgstr ""
msgstr "Veuillez fournir le nom du produit"

#: assets/products/components/Products.jsx:66
msgid "Would you like to delete product: {{name}}"
Expand Down Expand Up @@ -3050,7 +3058,7 @@ msgstr "Notifications par courriel:"

#: assets/search/components/TopicForm.jsx:30
msgid "Toggle email notifications"
msgstr ""
msgstr "Activer/désactiver les notifications par courriel"

#: assets/search/components/TopicForm.jsx:51
msgid "Send me notifications"
Expand Down Expand Up @@ -3141,7 +3149,7 @@ msgstr "Tester l'identifiant du produit Superdesk"

#: assets/section-filters/components/SectionFilters.jsx:40
msgid "Please provide Section Filter name"
msgstr ""
msgstr "Veuillez fournir le nom du filtre de section"

#: assets/section-filters/components/SectionFilters.jsx:61
msgid "Would you like to delete Section Filter: {{name}}"
Expand Down Expand Up @@ -3277,7 +3285,7 @@ msgstr "Requiert une approbation"

#: assets/users/components/Users.jsx:39
msgid "Please provide email"
msgstr ""
msgstr "Veuillez fournir l'adresse de courriel"

#: assets/users/components/Users.jsx:60
msgid "Would you like to delete user: {{name}}?"
Expand Down

0 comments on commit a894c7a

Please sign in to comment.