Repository: crsmithdev/arrow
Pull request #571 (2019-02-22 18:40:09)

Add additional timeframes translations for german language
When using the `humanize` method of arrow lib with the "only_distance" option set to true, in german language there are some special cases which have to be translated different than if not using the option.
For example "in one hour" in german is "in einer Stunde", with "only_distance" set to true, it is "one hour" which is translated to "einer Stunde" at the moment. But it would be better to translate it like "eine Stunde".
This PR adds these special cases to the german localisation.

codecov-io: # [Codecov](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=h1) Report
> Merging [#571](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=desc) into [master](https://codecov.io/gh/crsmithdev/arrow/commit/5b175882be0cd8e9faba3ed0f3c27a5bb5ba756f?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/crsmithdev/arrow/pull/571/graphs/tree.svg?width=650&token=4EkGnFsIGn&height=150&src=pr)](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #571   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          13     13           
  Lines        3376   3399   +23     
  Branches      237    238    +1     
=====================================
+ Hits         3376   3399   +23
```


| [Impacted Files](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [arrow/locales.py](https://codecov.io/gh/crsmithdev/arrow/pull/571/diff?src=pr&el=tree#diff-YXJyb3cvbG9jYWxlcy5weQ==) | `100% <100%> (ø)` | :arrow_up: |
| [tests/locales\_tests.py](https://codecov.io/gh/crsmithdev/arrow/pull/571/diff?src=pr&el=tree#diff-dGVzdHMvbG9jYWxlc190ZXN0cy5weQ==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=footer). Last update [5b17588...28eb36e](https://codecov.io/gh/crsmithdev/arrow/pull/571?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

systemcatch: Hey @niklasdoerfler thanks for the contribution! I'll merge this in shortly.

Patch:
diff --git a/HISTORY.md b/HISTORY.md
index 931578e..250e4d9 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,5 +1,11 @@
 ## History
 
+### 0.13.1
+
+- [NEW] Add support for Python 3.7.
+- [CHANGE] Remove deprecation decorators for Arrow.range(), Arrow.span_range() and Arrow.interval(), all now return generators, wrap with list() to get old behavior.
+- [FIX] Documentation and docstring updates.
+
 ### 0.13.0
 
 - [NEW] Added support for Python 3.6.
diff --git a/arrow/locales.py b/arrow/locales.py
index 09e7b21..2efc859 100644
--- a/arrow/locales.py
+++ b/arrow/locales.py
@@ -812,6 +812,13 @@ class _DeutschLocaleCommonMixin(object):
         'years': '{0} Jahren',
     }
 
+    timeframes_only_distance = timeframes.copy()
+    timeframes_only_distance['minute'] = 'eine Minute'
+    timeframes_only_distance['hour'] = 'eine Stunde'
+    timeframes_only_distance['day'] = 'ein Tag'
+    timeframes_only_distance['month'] = 'ein Monat'
+    timeframes_only_distance['year'] = 'ein Jahr'
+
     month_names = [
         '', 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli',
         'August', 'September', 'Oktober', 'November', 'Dezember'
@@ -834,6 +841,21 @@ class _DeutschLocaleCommonMixin(object):
     def _ordinal_number(self, n):
         return '{}.'.format(n)
 
+    def describe(self, timeframe, delta=0, only_distance=False):
+        ''' Describes a delta within a timeframe in plain language.
+        :param timeframe: a string representing a timeframe.
+        :param delta: a quantity representing a delta in a timeframe.
+        :param only_distance: return only distance eg: "11 seconds" without "in" or "ago" keywords
+        '''
+
+        humanized = self.timeframes_only_distance[timeframe].format(trunc(abs(delta)))
+
+        if not only_distance:
+            humanized = self._format_timeframe(timeframe, delta)
+            humanized = self._format_relative(humanized, timeframe, delta)
+
+        return humanized
+
 
 class GermanLocale(_DeutschLocaleCommonMixin, Locale):
 


Test patch:
diff --git a/tests/locales_tests.py b/tests/locales_tests.py
index 9afe6bc..82b31ef 100644
--- a/tests/locales_tests.py
+++ b/tests/locales_tests.py
@@ -417,6 +417,18 @@ class GermanLocaleTests(Chai):
 
     def test_ordinal_number(self):
         assertEqual(self.locale.ordinal_number(1), '1.')
+    
+    def test_define(self):
+        assertEqual(self.locale.describe("minute", only_distance=True), 'eine Minute')
+        assertEqual(self.locale.describe("minute", only_distance=False), 'in einer Minute')
+        assertEqual(self.locale.describe("hour", only_distance=True), 'eine Stunde')
+        assertEqual(self.locale.describe("hour", only_distance=False), 'in einer Stunde')
+        assertEqual(self.locale.describe("day", only_distance=True), 'ein Tag')
+        assertEqual(self.locale.describe("day", only_distance=False), 'in einem Tag')
+        assertEqual(self.locale.describe("month", only_distance=True), 'ein Monat')
+        assertEqual(self.locale.describe("month", only_distance=False), 'in einem Monat')
+        assertEqual(self.locale.describe("year", only_distance=True), 'ein Jahr')
+        assertEqual(self.locale.describe("year", only_distance=False), 'in einem Jahr')
 
 
 class HungarianLocaleTests(Chai):