From 7187016eafdd6adc2131219b36da42e2f7ee99df Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Wed, 15 Feb 2023 13:12:35 +0100
Subject: [PATCH] Translations system ready

---
 README.md                                   | 25 +++++++-
 src/vips_reference_model/reference_model.py | 15 ++---
 src/vips_reference_model/translations.py    | 71 +++++++++++++++++++++
 tests/test_reference_model.py               |  2 +
 4 files changed, 102 insertions(+), 11 deletions(-)
 create mode 100644 src/vips_reference_model/translations.py

diff --git a/README.md b/README.md
index 1eec9f5..7f96178 100644
--- a/README.md
+++ b/README.md
@@ -44,4 +44,27 @@ bumpver update --major
 [(Source)](https://semver.org/#summary)
 
 ## References
-We used this excellent guide for packaging: https://realpython.com/pypi-publish-python-package/ 
\ No newline at end of file
+We used this excellent guide for packaging: https://realpython.com/pypi-publish-python-package/ 
+
+## Translations
+We're using a simple dictionary translation system, with a module translations.py, where we
+simply define some dictionaries with language codes as property, looking like this:
+
+```python
+name = {
+    "en":   "Reference Model",
+    "nb":   "Referansemodell",
+}
+```
+
+This is used in the main module like this:
+
+```python
+[...]
+from . import translations
+[...]
+def get_model_name(self, language = VIPSModel.default_language) -> str:
+        """Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
+        return translations.name.get(language, translations.name.get(VIPSModel.default_language, "NOT FOUND"))  
+[...]
+```
\ No newline at end of file
diff --git a/src/vips_reference_model/reference_model.py b/src/vips_reference_model/reference_model.py
index 9cb430f..7da1541 100644
--- a/src/vips_reference_model/reference_model.py
+++ b/src/vips_reference_model/reference_model.py
@@ -21,7 +21,8 @@ along with VIPSCore-Python-Common.  If not, see <http://www.nibio.no/licenses/>.
 from vipscore_common.vips_model import VIPSModel
 from vipscore_common.entities import Result, ModelConfiguration, WeatherObservation
 from vipscore_common.data_utils import *
-import numpy as np
+from . import translations
+
 
 class ReferenceModel(VIPSModel):
     """
@@ -125,7 +126,7 @@ class ReferenceModel(VIPSModel):
 
     def get_model_name(self, language = VIPSModel.default_language) -> str:
         """Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
-        return "Reference Model"     
+        return translations.name.get(language, translations.name.get(VIPSModel.default_language, "NOT FOUND"))    
 
     def get_model_description(self, language = VIPSModel.default_language) -> str:
         """Returns the model description in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
@@ -136,16 +137,10 @@ class ReferenceModel(VIPSModel):
 
     def get_warning_status_interpretation(self, language = VIPSModel.default_language) -> str:
         """How to interpret the warning status (red-yellow-green, what does it mean?) in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
-        return """
-        Gray   status (warning status == 0): Warning not applicable
-        Blue   status (warning status == 1): Missing data
-        Green  status (warning status == 2): No risk. Sleep well
-        Yellow status (warning status == 3): The day-degree hreshold for medium risk has been passed. Be on the alert, inspect your field
-        Red status    (warning status == 4): The day-degree threshold for high risk has been passed. When the going gets tough, the tough get going
-        """
+        return translations.wsi.get(language, translations.wsi.get(VIPSModel.default_language, "NOT FOUND"))    
 
     def get_model_usage(self, language = VIPSModel.default_language) -> str:
         """Technical manual for this model, in the specified language  (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
-        return "TODO"
+        return translations.usage.get(language, translations.usage.get(VIPSModel.default_language, "NOT FOUND"))    
 
     
\ No newline at end of file
diff --git a/src/vips_reference_model/translations.py b/src/vips_reference_model/translations.py
new file mode 100644
index 0000000..bdbac41
--- /dev/null
+++ b/src/vips_reference_model/translations.py
@@ -0,0 +1,71 @@
+"""
+Example translation system
+"""
+
+name = {
+    "en":   "Reference Model",
+    "nb":   "Referansemodell",
+}
+
+description = {
+    "en":   """
+    Well, there's egg and bacon,
+    Egg sausage and bacon
+    Egg and spam
+    Egg, bacon and spam
+    Egg, bacon, sausage and spam
+    Spam, bacon, sausage and spam
+    Spam, egg, spam, spam, bacon and spam
+    Spam, sausage, spam, spam, spam, bacon, spam tomato and spam
+    Spam, spam, spam, egg and spam
+    Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam.
+    """,
+    
+    "nb":   """
+    Vel, det er egg og bacon,
+    Eggepølse og bacon
+    Egg og spam
+    Egg, bacon og spam
+    Egg, bacon, pølse og spam
+    Spam, bacon, pølse og spam
+    Spam, egg, spam, spam, bacon og spam
+    Spam, pølse, spam, spam, spam, bacon, spam tomat og spam
+    Spam, spam, spam, egg og spam
+    Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam og spam.
+    """,
+}
+
+wsi = {
+    "en":   """
+    Gray   status (warning status == 0): Warning not applicable
+    Blue   status (warning status == 1): Missing data
+    Green  status (warning status == 2): No risk. Sleep well
+    Yellow status (warning status == 3): The day-degree hreshold for medium risk has been passed. Be on the alert, inspect your field
+    Red status    (warning status == 4): The day-degree threshold for high risk has been passed. When the going gets tough, the tough get going
+    """,
+
+    "nb": """
+    Grå status (advarselsstatus == 0): Advarsel ikke aktuelt
+    Blå status (advarselsstatus == 1): Manglende data
+    Grønn status (advarselsstatus == 2): Ingen risiko. Sov godt
+    Gul status (advarselsstatus == 3): Daggradsterskelen for middels risiko er passert. Vær på vakt, inspiser feltet ditt
+    Rød status (advarselsstatus == 4): Daggradsterskelen for høy risiko er passert. Når det blir tøft, kommer de tøffe i gang
+    """
+
+}
+
+usage = {
+    "en": """
+    Input data are:
+    sowingDate (yyyy-MM-dd) - the day you sowed your crop
+    timeZone - the timeZone you're in, e.g. "Europe/Oslo"
+    weatherData - daily mean temperatures in degrees Celcius
+    """,
+
+    "nb": """
+    Inndata er:
+     sådato (åååå-MM-dd) - dagen du sådde avlingen
+     tidssone - tidssonen du er i, f.eks. "Europe/Oslo"
+     værdata - daglig gjennomsnittstemperatur i grader Celsius
+    """
+}
\ No newline at end of file
diff --git a/tests/test_reference_model.py b/tests/test_reference_model.py
index f7cbe01..61b55ac 100644
--- a/tests/test_reference_model.py
+++ b/tests/test_reference_model.py
@@ -75,6 +75,8 @@ class TestReferenceModel(unittest.TestCase):
         """
         instance = ReferenceModel()
         self.assertEqual(instance.get_model_name(), "Reference Model")
+        # Norwegian
+        self.assertEqual(instance.get_model_name("nb"), "Referansemodell")
     
     def test_get_model_description(self):
         """
-- 
GitLab