diff --git a/README.md b/README.md index 1eec9f5f4882947b2b5e46aa7000d68cde0c5df4..7f9617834edc9ec1803f41f1be3e6bab80dbb84f 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 9cb430fe02ac7870763421d20982f43852c21cfd..7da154142a490d7f120864aa70d1e829e6bccca3 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 0000000000000000000000000000000000000000..bdbac41ff9dfeae9c5bd898d5e670dba75c6960d --- /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 f7cbe016e80e9fb94cc2e161fd7a6e73ba4ff7c2..61b55ac302eb84f6328c1bba18dc7620f58f1ad5 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): """