Skip to content

Commit

Permalink
feat: localize texts of frequency pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
suschneider committed Aug 19, 2024
1 parent 7aba657 commit 1d1fc88
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/app/core/pipes/frequency.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

/**
* The frequency pipe converts a string of special interval format to the corresponding display string
* example: interval 'P21D' returns '3 Week(s)'
*/
@Pipe({ name: 'ishFrequency' })
export class FrequencyPipe implements PipeTransform {
constructor(private translate: TranslateService) {}

transform(interval: string): string {
let period = interval.slice(-1).toUpperCase();
let duration = parseInt(interval.slice(1, -1), 10);

// convert days to weeks if possible since the API only returns daily, monthly or yearly intervals
if (period === 'D' && duration % 7 === 0) {
period = 'W';
Expand All @@ -17,13 +21,13 @@ export class FrequencyPipe implements PipeTransform {

switch (period) {
case 'D':
return `${duration} Day(s)`;
return this.translate.instant('order.recurrence.period.days', { 0: duration });
case 'W':
return `${duration} Week(s)`;
return this.translate.instant('order.recurrence.period.weeks', { 0: duration });
case 'M':
return `${duration} Month(s)`;
return this.translate.instant('order.recurrence.period.months', { 0: duration });
case 'Y':
return `${duration} Year(s)`;
return this.translate.instant('order.recurrence.period.years', { 0: duration });
default:
return interval;
}
Expand Down
8 changes: 4 additions & 4 deletions src/assets/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,10 @@
"order.recurrence.form.info.text": "Bestellungen",
"order.recurrence.heading": "Recurring order",
"order.recurrence.interval.label": "Recur every",
"order.recurrence.period.days": "Tag(e)",
"order.recurrence.period.months": "Monate(e)",
"order.recurrence.period.weeks": "Woche(n)",
"order.recurrence.period.years": "Jahr(e)",
"order.recurrence.period.days": "{{0, plural, one{# Tag} other{# Tage}}}",
"order.recurrence.period.months": "{{0, plural, one{# Monat} other{# Monate}}}",
"order.recurrence.period.weeks": "{{0, plural, one{# Woche} other{# Wochen}}}",
"order.recurrence.period.years": "{{0, plural, one{# Jahr} other{# Jahre}}}",
"order.recurrence.repetitions.label": "Bis",
"order.recurrence.start.label": "Beginne am",
"order.tracking.error": "Leider konnte keine Bestellung mit Ihren Daten gefunden werden.",
Expand Down
12 changes: 6 additions & 6 deletions src/assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,14 @@
"account.quotes.widget.view_all_quotes.link": "View all quotes",
"account.recurring_orders.heading": "Recurring orders",
"account.recurring_orders.navigation.link": "Recurring orders",
"account.recurring_orders.subtitle": "Your most recent recurring order appears first. Please allow up to 5 minutes for new orders to appear below.",
"account.recurring_orders.table.date_of_order": "Creation date",
"account.recurring_orders.table.id_of_order": "No.",
"account.recurring_orders.table.id_of_order.aria_label": "Navigate to order details",
"account.recurring_orders.table.date_of_order": "Creation date",
"account.recurring_orders.table.last_order_date": "Last order",
"account.recurring_orders.table.next_order_date": "Next order",
"account.recurring_orders.table.order_frequency": "Recur every",
"account.recurring_orders.table.order_total": "Total",
"account.recurring_orders.subtitle": "Your most recent recurring order appears first. Please allow up to 5 minutes for new orders to appear below.",
"account.register.address.headding": "Address",
"account.register.address.message": "To save time when placing an order, please provide your primary invoice or shipping address below. We will store this information so you won’t have to enter it again.",
"account.register.company_information.heading": "Company information",
Expand Down Expand Up @@ -946,10 +946,10 @@
"order.recurrence.form.info.text": "orders",
"order.recurrence.heading": "Recurring order",
"order.recurrence.interval.label": "Recur every",
"order.recurrence.period.days": "Day(s)",
"order.recurrence.period.months": "Month(s)",
"order.recurrence.period.weeks": "Week(s)",
"order.recurrence.period.years": "Year(s)",
"order.recurrence.period.days": "{{0, plural, one{# Day} other{# Days}}}",
"order.recurrence.period.months": "{{0, plural, one{# Month} other{# Months}}}",
"order.recurrence.period.weeks": "{{0, plural, one{# Week} other{# Weeks}}}",
"order.recurrence.period.years": "{{0, plural, one{# Year} other{# Years}}}",
"order.recurrence.repetitions.label": "Until",
"order.recurrence.start.label": "Start from",
"order.tracking.error": "Unfortunately, we could not locate an order with the information you provided.",
Expand Down
8 changes: 4 additions & 4 deletions src/assets/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,10 @@
"order.recurrence.form.info.text": "orders",
"order.recurrence.heading": "Recurring order",
"order.recurrence.interval.label": "Recur every",
"order.recurrence.period.days": "Day(s)",
"order.recurrence.period.months": "Month(s)",
"order.recurrence.period.weeks": "Week(s)",
"order.recurrence.period.years": "Year(s)",
"order.recurrence.period.days": "{{0, plural, one{# Day} other{# Days}}}",
"order.recurrence.period.months": "{{0, plural, one{# Month} other{# Months}}}",
"order.recurrence.period.weeks": "{{0, plural, one{# Week} other{# Weeks}}}",
"order.recurrence.period.years": "{{0, plural, one{# Year} other{# Years}}}",
"order.recurrence.repetitions.label": "Until",
"order.recurrence.start.label": "Start from",
"order.tracking.error": "Malheureusement, nous n’avons pas pu localiser une commande avec les informations que vous avez fournies.",
Expand Down

0 comments on commit 1d1fc88

Please sign in to comment.