]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: include number placeholder in relative date strings
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 24 Apr 2024 07:22:08 +0000 (00:22 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 24 Apr 2024 07:22:08 +0000 (00:22 -0700)
src-ui/messages.xlf
src-ui/src/app/pipes/custom-date.pipe.spec.ts
src-ui/src/app/pipes/custom-date.pipe.ts

index eaa2d7bfef9a90f77ba266807cc19f4bb1cdb925..13490548553578464f074ffb124c75fcc08c1056 100644 (file)
           <context context-type="linenumber">36</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="4272436583644511364" datatype="html">
-        <source>Just now</source>
+      <trans-unit id="7811681478769461161" datatype="html">
+        <source>%s year ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">39</context>
+          <context context-type="linenumber">14</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="8456127468852940807" datatype="html">
-        <source>year ago</source>
+      <trans-unit id="3393387677918927062" datatype="html">
+        <source>%s years ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">42</context>
+          <context context-type="linenumber">15</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="963494111451627204" datatype="html">
-        <source>years ago</source>
+      <trans-unit id="3053246523831285824" datatype="html">
+        <source>%s month ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">43</context>
+          <context context-type="linenumber">19</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="1919405338795657780" datatype="html">
-        <source>month ago</source>
+      <trans-unit id="1158628882375251480" datatype="html">
+        <source>%s months ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">47</context>
+          <context context-type="linenumber">20</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="6041340836190906216" datatype="html">
-        <source>months ago</source>
+      <trans-unit id="7039133412826927309" datatype="html">
+        <source>%s week ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">48</context>
+          <context context-type="linenumber">24</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="4072659649620334828" datatype="html">
-        <source>week ago</source>
+      <trans-unit id="2896962543647781653" datatype="html">
+        <source>%s weeks ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">52</context>
+          <context context-type="linenumber">25</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="2871318661796659216" datatype="html">
-        <source>weeks ago</source>
+      <trans-unit id="91416192007234700" datatype="html">
+        <source>%s day ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">53</context>
+          <context context-type="linenumber">29</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="1328378419272652134" datatype="html">
-        <source>day ago</source>
+      <trans-unit id="5601594741748068208" datatype="html">
+        <source>%s days ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">57</context>
+          <context context-type="linenumber">30</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="5620397708418210833" datatype="html">
-        <source>days ago</source>
+      <trans-unit id="8387405724402999437" datatype="html">
+        <source>%s hour ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">58</context>
+          <context context-type="linenumber">34</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="4259498317457105735" datatype="html">
-        <source>hour ago</source>
+      <trans-unit id="2008395012733474465" datatype="html">
+        <source>%s hours ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">62</context>
+          <context context-type="linenumber">35</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="7576594819545407052" datatype="html">
-        <source>hours ago</source>
+      <trans-unit id="5782387980670840884" datatype="html">
+        <source>%s minute ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">63</context>
+          <context context-type="linenumber">39</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="4063456036422970205" datatype="html">
-        <source>minute ago</source>
+      <trans-unit id="7573942914011074807" datatype="html">
+        <source>%s minutes ago</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">67</context>
+          <context context-type="linenumber">40</context>
         </context-group>
       </trans-unit>
-      <trans-unit id="6906829094715901970" datatype="html">
-        <source>minutes ago</source>
+      <trans-unit id="4272436583644511364" datatype="html">
+        <source>Just now</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/pipes/custom-date.pipe.ts</context>
-          <context context-type="linenumber">68</context>
+          <context context-type="linenumber">72</context>
         </context-group>
       </trans-unit>
       <trans-unit id="7536524521722799066" datatype="html">
index 87e99212b03470ba173e1674e7c6509bef1cc2f4..ddc03c773e6672f679aa953b4aa15431a6b82e08 100644 (file)
@@ -1,10 +1,7 @@
 import { TestBed } from '@angular/core/testing'
 import { CustomDatePipe } from './custom-date.pipe'
 import { SettingsService } from '../services/settings.service'
-import {
-  HttpClientTestingModule,
-  HttpTestingController,
-} from '@angular/common/http/testing'
+import { HttpClientTestingModule } from '@angular/common/http/testing'
 import { DatePipe } from '@angular/common'
 
 describe('CustomDatePipe', () => {
index e6034c59bc5bdf3a2274d65c49781280d994fc0f..a7a31a2ed8210a0599ea1bee4ade0adbceceb37c 100644 (file)
@@ -9,6 +9,39 @@ const FORMAT_TO_ISO_FORMAT = {
   shortDate: 'y-MM-dd',
 }
 
+const INTERVALS = {
+  year: {
+    label: $localize`%s year ago`,
+    labelPlural: $localize`%s years ago`,
+    interval: 31536000,
+  },
+  month: {
+    label: $localize`%s month ago`,
+    labelPlural: $localize`%s months ago`,
+    interval: 2592000,
+  },
+  week: {
+    label: $localize`%s week ago`,
+    labelPlural: $localize`%s weeks ago`,
+    interval: 604800,
+  },
+  day: {
+    label: $localize`%s day ago`,
+    labelPlural: $localize`%s days ago`,
+    interval: 86400,
+  },
+  hour: {
+    label: $localize`%s hour ago`,
+    labelPlural: $localize`%s hours ago`,
+    interval: 3600,
+  },
+  minute: {
+    label: $localize`%s minute ago`,
+    labelPlural: $localize`%s minutes ago`,
+    interval: 60,
+  },
+}
+
 @Pipe({
   name: 'customDate',
 })
@@ -37,45 +70,13 @@ export class CustomDatePipe implements PipeTransform {
     if (format === 'relative') {
       const seconds = Math.floor((+new Date() - +new Date(value)) / 1000)
       if (seconds < 60) return $localize`Just now`
-      const intervals = {
-        year: {
-          label: $localize`year ago`,
-          labelPlural: $localize`years ago`,
-          interval: 31536000,
-        },
-        month: {
-          label: $localize`month ago`,
-          labelPlural: $localize`months ago`,
-          interval: 2592000,
-        },
-        week: {
-          label: $localize`week ago`,
-          labelPlural: $localize`weeks ago`,
-          interval: 604800,
-        },
-        day: {
-          label: $localize`day ago`,
-          labelPlural: $localize`days ago`,
-          interval: 86400,
-        },
-        hour: {
-          label: $localize`hour ago`,
-          labelPlural: $localize`hours ago`,
-          interval: 3600,
-        },
-        minute: {
-          label: $localize`minute ago`,
-          labelPlural: $localize`minutes ago`,
-          interval: 60,
-        },
-      }
       let counter
-      for (const i in intervals) {
-        counter = Math.floor(seconds / intervals[i].interval)
+      for (const i in INTERVALS) {
+        counter = Math.floor(seconds / INTERVALS[i].interval)
         if (counter > 0) {
           const label =
-            counter > 1 ? intervals[i].labelPlural : intervals[i].label
-          return `${counter} ${label}`
+            counter > 1 ? INTERVALS[i].labelPlural : INTERVALS[i].label
+          return label.replace('%s', counter.toString())
         }
       }
     }